-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add static build config. #510
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# Options | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
option(SLEEF_BUILD_STATIC_TEST_BINS "Build statically linked test executables" OFF) | ||||||||||||||||||||||||||||||||||||||||||
option(SLEEF_ENABLE_LTO "Enable LTO on GCC or ThinLTO on clang" OFF) | ||||||||||||||||||||||||||||||||||||||||||
option(SLEEF_BUILD_LIBM "libsleef will be built." ON) | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -29,6 +28,13 @@ option(SLEEF_DISABLE_SSL "Disable testing with the SSL library" OFF) | |||||||||||||||||||||||||||||||||||||||||
option(SLEEF_ENABLE_CUDA "Enable CUDA" OFF) | ||||||||||||||||||||||||||||||||||||||||||
option(SLEEF_ENABLE_CXX "Enable C++" OFF) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
set(_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
if(NOT DEFINED ${SLEEF_BUILD_SHARED_LIBS}) | ||||||||||||||||||||||||||||||||||||||||||
set(_INTERNAL_SLEEF_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) | ||||||||||||||||||||||||||||||||||||||||||
else() | ||||||||||||||||||||||||||||||||||||||||||
set(_INTERNAL_SLEEF_BUILD_SHARED_LIBS ${SLEEF_BUILD_SHARED_LIBS}) | ||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be done with options instead? For instance,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blapie -- These are not equivalent because this defines My blog post suggests the following:
Suggested change
Then you can just look at the truthiness of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
# Function used to generate safe command arguments for add_custom_command | ||||||||||||||||||||||||||||||||||||||||||
function(command_arguments PROPNAME) | ||||||||||||||||||||||||||||||||||||||||||
set(quoted_args "") | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -157,9 +163,9 @@ separate build directory. Note: Please remove autogenerated file \ | |||||||||||||||||||||||||||||||||||||||||
`CMakeCache.txt` and directory `CMakeFiles` in the current directory.") | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everywhere you should just use https://cmake.org/cmake/help/v3.18/command/project.html#project |
||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if(SLEEF_ENABLE_LTO AND BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
message(FATAL_ERROR "SLEEF_ENABLE_LTO and BUILD_SHARED_LIBS cannot be specified at the same time") | ||||||||||||||||||||||||||||||||||||||||||
endif(SLEEF_ENABLE_LTO AND BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
if(SLEEF_ENABLE_LTO AND _INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
message(FATAL_ERROR "SLEEF_ENABLE_LTO and _INTERNAL_SLEEF_BUILD_SHARED_LIBS cannot be specified at the same time") | ||||||||||||||||||||||||||||||||||||||||||
endif(SLEEF_ENABLE_LTO AND _INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+166
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With my other suggestions:
Suggested change
Note that duplicating the condition in the |
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if(SLEEF_ENABLE_LTO) | ||||||||||||||||||||||||||||||||||||||||||
cmake_policy(SET CMP0069 NEW) | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
That policy is already enabled by |
||||||||||||||||||||||||||||||||||||||||||
|
@@ -305,7 +311,7 @@ if(SLEEF_SHOW_CONFIG) | |||||||||||||||||||||||||||||||||||||||||
message(" Native build dir: ${NATIVE_BUILD_DIR}") | ||||||||||||||||||||||||||||||||||||||||||
endif(CMAKE_CROSSCOMPILING) | ||||||||||||||||||||||||||||||||||||||||||
message(STATUS "Using option `${SLEEF_C_FLAGS}` to compile libsleef") | ||||||||||||||||||||||||||||||||||||||||||
message(STATUS "Building shared libs : " ${BUILD_SHARED_LIBS}) | ||||||||||||||||||||||||||||||||||||||||||
message(STATUS "Building shared libs : " ${_INTERNAL_SLEEF_BUILD_SHARED_LIBS}) | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
message(STATUS "Building static test bins: " ${SLEEF_BUILD_STATIC_TEST_BINS}) | ||||||||||||||||||||||||||||||||||||||||||
message(STATUS "MPFR : " ${LIB_MPFR}) | ||||||||||||||||||||||||||||||||||||||||||
if (MPFR_INCLUDE_DIR) | ||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ include(CheckLanguage) | |||||
|
||||||
if (SLEEF_BUILD_STATIC_TEST_BINS) | ||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") | ||||||
set(BUILD_SHARED_LIBS OFF) | ||||||
set(_INTERNAL_SLEEF_BUILD_SHARED_LIBS OFF) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "-static") | ||||||
endif() | ||||||
|
||||||
|
@@ -834,7 +834,7 @@ endif() | |||||
|
||||||
# Set common definitions | ||||||
|
||||||
if (NOT BUILD_SHARED_LIBS) | ||||||
if (NOT _INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
set(COMMON_TARGET_DEFINITIONS SLEEF_STATIC_LIBS=1) | ||||||
set(SLEEF_STATIC_LIBS 1) | ||||||
endif() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -133,7 +133,7 @@ optimized, or any other special set of flags. | |||||
- `SLEEF_SHOW_CONFIG` : Show relevant CMake variables upon configuring a build | ||||||
- `SLEEF_SHOW_ERROR_LOG` : Show the content of CMakeError.log | ||||||
|
||||||
- `BUILD_SHARED_LIBS` : Static libs are built if set to FALSE | ||||||
- `SLEEF_BUILD_SHARED_LIBS` : Static libs are built if set to FALSE | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `SLEEF_BUILD_GNUABI_LIBS` : Avoid building libraries with GNU ABI if set to FALSE | ||||||
- `SLEEF_BUILD_INLINE_HEADERS` : Generate header files for inlining whole SLEEF functions | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -224,7 +224,7 @@ set(COMMON_TARGET_PROPERTIES | |||||||||||||
C_STANDARD 99 # -std=gnu99 | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
if (BUILD_SHARED_LIBS) | ||||||||||||||
if (_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
|
@@ -373,8 +373,11 @@ foreach(T ${LIST_SUPPORTED_FPTYPE}) | |||||||||||||
endforeach() | ||||||||||||||
|
||||||||||||||
# Target libdft | ||||||||||||||
|
||||||||||||||
add_library(${TARGET_LIBDFT} $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>) | ||||||||||||||
if(_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
add_library(${TARGET_LIBDFT} SHARED $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>) | ||||||||||||||
else() | ||||||||||||||
add_library(${TARGET_LIBDFT} STATIC $<TARGET_OBJECTS:dftcommon_obj> $<TARGET_OBJECTS:${TARGET_LIBARRAYMAP_OBJ}>) | ||||||||||||||
endif() | ||||||||||||||
Comment on lines
+376
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
target_link_libraries(${TARGET_LIBDFT} ${TARGET_LIBSLEEF} ${LIBM}) | ||||||||||||||
|
||||||||||||||
foreach(T ${LIST_SUPPORTED_FPTYPE}) | ||||||||||||||
|
@@ -422,13 +425,4 @@ install( | |||||||||||||
COMPONENT sleef_Runtime | ||||||||||||||
INCLUDES # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
install( | ||||||||||||||
TARGETS ${TARGET_LIBDFT} | ||||||||||||||
DESTINATION dummy # provided above already | ||||||||||||||
LIBRARY # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||||||||||||||
COMPONENT sleef_Development | ||||||||||||||
NAMELINK_ONLY | ||||||||||||||
) | ||||||||||||||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -348,7 +348,7 @@ set(COMMON_TARGET_PROPERTIES | |||||||||||||
C_STANDARD 99 # -std=gnu99 | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
if (BUILD_SHARED_LIBS) | ||||||||||||||
if (_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
|
@@ -359,7 +359,12 @@ endif() | |||||||||||||
# Original sleef sources | ||||||||||||||
set(STANDARD_SOURCES rempitab.c) | ||||||||||||||
|
||||||||||||||
add_library(${TARGET_LIBSLEEF} ${STANDARD_SOURCES}) | ||||||||||||||
if(_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
add_library(${TARGET_LIBSLEEF} SHARED ${STANDARD_SOURCES}) | ||||||||||||||
else() | ||||||||||||||
add_library(${TARGET_LIBSLEEF} STATIC ${STANDARD_SOURCES}) | ||||||||||||||
endif() | ||||||||||||||
Comment on lines
+362
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm going to stop highlighting all the places this needs to be reverted. |
||||||||||||||
|
||||||||||||||
add_dependencies(${TARGET_LIBSLEEF} ${TARGET_HEADERS}) | ||||||||||||||
set_target_properties(${TARGET_LIBSLEEF} PROPERTIES | ||||||||||||||
VERSION ${SLEEF_VERSION} | ||||||||||||||
|
@@ -884,7 +889,11 @@ if(ENABLE_GNUABI) | |||||||||||||
endforeach() | ||||||||||||||
|
||||||||||||||
# Create library | ||||||||||||||
add_library(${TARGET_LIBSLEEFGNUABI} ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c) | ||||||||||||||
if(_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
add_library(${TARGET_LIBSLEEFGNUABI} SHARED ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c) | ||||||||||||||
else() | ||||||||||||||
add_library(${TARGET_LIBSLEEFGNUABI} STATIC ${TARGET_LIBSLEEFGNUABI_OBJECTS} rempitab.c) | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
# Library properties | ||||||||||||||
set_target_properties(${TARGET_LIBSLEEFGNUABI} PROPERTIES | ||||||||||||||
|
@@ -973,7 +982,11 @@ endif() | |||||||||||||
# -------------------------------------------------------------------- | ||||||||||||||
# Build scalar-only library from sleefdp.c and sleefsp.c | ||||||||||||||
if(SLEEF_BUILD_SCALAR_LIB) | ||||||||||||||
add_library(sleefscalar sleefdp.c sleefsp.c rempitab.c) | ||||||||||||||
if(_INTERNAL_SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||
add_library(sleefscalar SHARED sleefdp.c sleefsp.c rempitab.c) | ||||||||||||||
else() | ||||||||||||||
add_library(sleefscalar STATIC sleefdp.c sleefsp.c rempitab.c) | ||||||||||||||
endif() | ||||||||||||||
add_dependencies(sleefscalar ${TARGET_HEADERS}) | ||||||||||||||
set_target_properties(sleefscalar PROPERTIES | ||||||||||||||
VERSION ${SLEEF_VERSION} | ||||||||||||||
|
@@ -1004,15 +1017,6 @@ if(SLEEF_BUILD_SCALAR_LIB) | |||||||||||||
DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||||||||||||||
COMPONENT sleef_Runtime | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
install( | ||||||||||||||
TARGETS sleefscalar | ||||||||||||||
DESTINATION dummy # provided above already | ||||||||||||||
LIBRARY # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||||||||||||||
COMPONENT sleef_Development | ||||||||||||||
NAMELINK_ONLY | ||||||||||||||
) | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
# -------------------------------------------------------------------- | ||||||||||||||
|
@@ -1038,14 +1042,6 @@ install( | |||||||||||||
INCLUDES # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||||||||||||||
) | ||||||||||||||
install( | ||||||||||||||
TARGETS ${TARGET_LIBSLEEF} | ||||||||||||||
DESTINATION dummy # provided above already | ||||||||||||||
LIBRARY # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||||||||||||||
COMPONENT sleef_Development | ||||||||||||||
NAMELINK_ONLY | ||||||||||||||
) | ||||||||||||||
configure_file("sleef.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sleef.pc" @ONLY) | ||||||||||||||
install( | ||||||||||||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/sleef.pc" | ||||||||||||||
|
@@ -1068,13 +1064,4 @@ if(ENABLE_GNUABI) | |||||||||||||
DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||||||||||||||
COMPONENT sleef_Runtime | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
install( | ||||||||||||||
TARGETS ${TARGET_LIBSLEEF} | ||||||||||||||
DESTINATION dummy # provided above already | ||||||||||||||
LIBRARY # | ||||||||||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||||||||||||||
COMPONENT sleef_Development | ||||||||||||||
NAMELINK_ONLY | ||||||||||||||
) | ||||||||||||||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of
option
andset
are controlled by policies. You must setcmake_minimum_required
as the first line of your top-level program to have any backwards compatibility guarantees at all.Ideally
project()
would be the second line since so many other commands depend on the internal state it configures.Then, after your options, add the following lines:
No need to maintain that
LANGLIST
anymore. Just enable the requested languages.Then, below, delete these lines:
CMP0091
is enabled in CMake 3.15+ so thecmake_policy
line is a noop and so the wholeif ()
block can be removed.Also delete these lines: