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 1 commit
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_SHARED_LIBS "Build sleef as static library" ON) | ||||||||||||||||||||||||||||||||||||||||||
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 SLEEF_BUILD_SHARED_LIBS) | ||||||||||||||||||||||||||||||||||||||||||
message(FATAL_ERROR "SLEEF_ENABLE_LTO and SLEEF_BUILD_SHARED_LIBS cannot be specified at the same time") | ||||||||||||||||||||||||||||||||||||||||||
endif(SLEEF_ENABLE_LTO AND SLEEF_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 : " ${SLEEF_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(SLEEF_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 SLEEF_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() | ||||||
|
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: