-
Notifications
You must be signed in to change notification settings - Fork 8
fix: Allow for environment override of CMAKE_CXX_FLAGS #29
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
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,4 +1,4 @@ | ||
| cmake_minimum_required (VERSION 3.0.2) | ||
| cmake_minimum_required(VERSION 3.12...3.31) | ||
|
|
||
| # Disable the use of RPATHS - we probably are not | ||
| # that interested in relocatable binaries and it | ||
|
|
@@ -20,37 +20,37 @@ set(CMAKE_CXX_STANDARD 11) | |
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_CXX_EXTENSIONS OFF) | ||
| set(VERSION 2.0.10) | ||
| include(CheckCXXCompilerFlag) | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") | ||
| set(CXX_FLAGS_TO_CHECK "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fstack-protector-strong -O2 -pipe -fext-numeric-literals") | ||
| set(CXX_FLAGS_DEBUG_TO_CHECK "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address ${CMAKE_CXX_FLAGS_TO_CHECK}") | ||
| set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address") | ||
| else() | ||
| set(CXX_FLAGS_TO_CHECK "-Wall -Wextra") | ||
| set(CXX_FLAGS_DEBUG_TO_CHECK "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address ${CMAKE_CXX_FLAGS_TO_CHECK}") | ||
| endif() | ||
| set(CXX_FLAGS_PASSED ) | ||
| set(CXX_FLAGS_DEBUG_PASSED ) | ||
| foreach(fl ${CXX_FLAGS_TO_CHECK}) | ||
| CHECK_CXX_COMPILER_FLAG(${fl} COMPILER_SUPPORTS_${fl}) | ||
| if(COMPILER_SUPPORTS_${fl}) | ||
| set(CXX_FLAGS_PASSED "${CXX_FLAGS_PASSED} ${fl}" ) | ||
|
|
||
| # Set default CXXFLAGS but allow for environment override | ||
| # c.f. https://cmake.org/cmake/help/v3.31/envvar/CXXFLAGS.html | ||
|
Comment on lines
+24
to
+25
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. First determine the values of |
||
| if (NOT CMAKE_CXX_FLAGS) | ||
| # c.f. https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") | ||
| set(CMAKE_CXX_FLAGS "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fstack-protector-strong -O2 -pipe -fext-numeric-literals") | ||
| else() | ||
| set(CMAKE_CXX_FLAGS "-Wall -Wextra") | ||
| endif() | ||
| endforeach() | ||
| foreach(fl ${CXX_FLAGS_DEBUG_TO_CHECK}) | ||
| CHECK_CXX_COMPILER_FLAG(${fl} COMPILER_SUPPORTS_${fl}) | ||
| if(COMPILER_SUPPORTS_${fl}) | ||
| set(CXX_FLAGS_DEBUG_PASSED "${CXX_FLAGS_DEBUG_PASSED} ${fl}" ) | ||
| else() | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") | ||
| # Ensure -fext-numeric-literals is in CMAKE_CXX_FLAGS | ||
| string(FIND "${CMAKE_CXX_FLAGS}" "-fext-numeric-literals" _found_ext_numeric_literals) | ||
| if (_found_ext_numeric_literals EQUAL -1) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fext-numeric-literals" CACHE STRING "Update environment CXXFLAGS" FORCE) | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
| set(CMAKE_CXX_FLAGS ${CXX_FLAGS_PASSED}) | ||
| set(CMAKE_CXX_FLAGS_DEBUG ${CXX_FLAGS_DEBUG_PASSED}) | ||
| message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}") | ||
| message(STATUS "CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}") | ||
| endif() | ||
|
|
||
| # TODO: QCDLoop is currently only well tested on GNU, so other compiler | ||
| # and linker defaults should be added as they become known | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") | ||
| set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address ${CMAKE_CXX_FLAGS}" CACHE STRING "debug CXXFLAGS" FORCE) | ||
| set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING "debug linker flags" FORCE) | ||
|
Comment on lines
+46
to
+47
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. Once |
||
| endif() | ||
|
|
||
| set(prefix ${CMAKE_INSTALL_PREFIX}) | ||
| set(exec_prefix ${CMAKE_INSTALL_PREFIX}) | ||
| set(includedir "${CMAKE_INSTALL_INCLUDE_DIR}") | ||
| set(libdir "${CMAKE_INSTALL_LIBDIR}") | ||
| set(includedir ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| set(libdir ${CMAKE_INSTALL_LIBDIR}) | ||
|
|
||
| configure_file( | ||
| "${PROJECT_SOURCE_DIR}/src/qcdloop/config.h.in" | ||
|
|
@@ -75,6 +75,7 @@ find_library(QUADMATH_LIBRARY | |
| /usr/local/lib /usr/x86_64-linux-gnu/* | ||
| /usr/lib/gcc/x86_64-linux-gnu/* | ||
| /usr/lib/gcc/x86_64-redhat-linux/* | ||
| "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" | ||
| ) | ||
|
|
||
| if(QUADMATH_LIBRARY) | ||
|
|
||
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.
Use range of compatible CMake versions (https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html) which was introduced in v3.12. This will take the newest available CMake version between
v3.12andv3.31that can be found a build time.