Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ src/qcdloop/config.h
src/qcdloop/stamp-h1
examples/cache_test
examples/cmass_test
examples/trigger_test
examples/trigger_test
# pixi environments
.pixi
*.egg-info
57 changes: 29 additions & 28 deletions CMakeLists.txt
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)
Copy link
Contributor Author

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.12 and v3.31 that can be found a build time.


# Disable the use of RPATHS - we probably are not
# that interested in relocatable binaries and it
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First determine the values of CMAKE_CXX_FLAGS: Either taken from the environment CXXFLAGS like normal, or if they are absent, set defaults manually.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once CMAKE_CXX_FLAGS has been set, then all other compiler or linker flags can be set accordingly in an additive fashion to their existing environmental defaults based on the CMAKE_CXX_COMPILER_ID.

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"
Expand All @@ -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)
Expand Down
Loading