diff --git a/cmake/configuration.cmake b/cmake/configuration.cmake index d1739634..deba6f9b 100644 --- a/cmake/configuration.cmake +++ b/cmake/configuration.cmake @@ -231,8 +231,7 @@ else () endif () check_cxx_compiler_flag ("-march=native" HIBF_HAS_MARCH_NATIVE) -cmake_dependent_option (HIBF_NATIVE_BUILD "Optimize build for current architecture." ON - "HIBF_HAS_MARCH_NATIVE;NOT HIBF_IS_DEBUG" OFF) +cmake_dependent_option (HIBF_NATIVE_BUILD "Optimize build for current architecture." ON "HIBF_HAS_MARCH_NATIVE" OFF) if (HIBF_NATIVE_BUILD) list (APPEND HIBF_CXX_FLAGS "-march=native") @@ -248,21 +247,31 @@ else () endif () check_ipo_supported (RESULT HIBF_HAS_LTO OUTPUT HIBF_HAS_LTO_OUTPUT) -cmake_dependent_option (HIBF_LTO_BUILD "Use Link Time Optimisation." ON "HIBF_HAS_LTO;NOT HIBF_IS_DEBUG" OFF) - -if (HIBF_LTO_BUILD) +cmake_dependent_option (HIBF_LTO_BUILD "Use Link Time Optimisation." ON "HIBF_HAS_LTO" OFF) +cmake_dependent_option (HIBF_DEV_CHECK_LTO "LTO check." ON + "HIBF_LTO_BUILD;NOT HIBF_IS_TOP_LEVEL;NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION" OFF) + +if (HIBF_DEV_CHECK_LTO) + message (FATAL_ERROR " HIBF heavily benefits from Link Time Optimisation (LTO).\n" + " Your compiler supports LTO, but is has not been enabled for your project.\n \n" + " Add the following at the beginning of your CMakeLists.txt:\n" + " ```\n" + " include (CheckIPOSupported)\n" + " check_ipo_supported (RESULT result OUTPUT output)\n" + " if (result)\n" + " set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)\n" + " endif ()\n" + " ```" + " \n \n" + " For development purposes, this error can be disabled via `HIBF_DEV_CHECK_LTO=OFF`.") +elseif (HIBF_LTO_BUILD) set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - list (APPEND HIBF_CXX_FLAGS ${CMAKE_CXX_COMPILE_OPTIONS_IPO}) hibf_config_print ("Link Time Optimisation: enabled") else () - if (HIBF_IS_DEBUG) - hibf_config_print ("Link Time Optimisation: disabled") - else () - set (HIBF_LTO_LOG "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hibf.lto.log") - file (WRITE "${HIBF_LTO_LOG}" "${HIBF_HAS_LTO_OUTPUT}") - hibf_config_print ("Link Time Optimisation: not supported") - hibf_config_print (" See ${HIBF_LTO_LOG}") - endif () + set (HIBF_LTO_LOG "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hibf.lto.log") + file (WRITE "${HIBF_LTO_LOG}" "${HIBF_HAS_LTO_OUTPUT}") + hibf_config_print ("Link Time Optimisation: not supported") + hibf_config_print (" See ${HIBF_LTO_LOG}") endif () # ---------------------------------------------------------------------------- diff --git a/cmake/hibf-config.cmake.in b/cmake/hibf-config.cmake.in index 84c04343..fcda8b83 100644 --- a/cmake/hibf-config.cmake.in +++ b/cmake/hibf-config.cmake.in @@ -4,6 +4,8 @@ @PACKAGE_INIT@ +include (CheckIPOSupported) +include (CMakeDependentOption) include (CMakeFindDependencyMacro) find_dependency (cereal @HIBF_CEREAL_VERSION@ REQUIRED) @@ -26,4 +28,22 @@ else () find_dependency (simde @HIBF_SIMDE_VERSION@ REQUIRED) endif () +check_ipo_supported (RESULT HIBF_HAS_LTO OUTPUT HIBF_HAS_LTO_OUTPUT) +cmake_dependent_option (HIBF_DEV_CHECK_LTO "LTO check." ON "HIBF_HAS_LTO;NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION" OFF) + +if (HIBF_DEV_CHECK_LTO) + message (FATAL_ERROR " HIBF heavily benefits from Link Time Optimisation (LTO).\n" + " Your compiler supports LTO, but is has not been enabled for your project.\n \n" + " Add the following at the beginning of your CMakeLists.txt:\n" + " ```\n" + " include (CheckIPOSupported)\n" + " check_ipo_supported (RESULT result OUTPUT output)\n" + " if (result)\n" + " set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)\n" + " endif ()\n" + " ```" + " \n \n" + " For development purposes, this error can be disabled via `HIBF_DEV_CHECK_LTO=OFF`.") +endif () + include ("${CMAKE_CURRENT_LIST_DIR}/hibf-targets.cmake") diff --git a/cmake/package-lock.cmake b/cmake/package-lock.cmake index 3628c7a3..984031fa 100644 --- a/cmake/package-lock.cmake +++ b/cmake/package-lock.cmake @@ -19,7 +19,7 @@ CPMDeclarePackage (simde NAME simde VERSION ${HIBF_SIMDE_VERSION} GITHUB_REPOSITORY simd-everywhere/simde - DOWNLOAD_ONLY YES) + DOWNLOAD_ONLY YES QUIET YES) # benchmark set (HIBF_BENCHMARK_VERSION 1.9.0) CPMDeclarePackage (benchmark diff --git a/test/hibf-test.cmake b/test/hibf-test.cmake index a43fa6a9..540b6c6b 100644 --- a/test/hibf-test.cmake +++ b/test/hibf-test.cmake @@ -13,6 +13,12 @@ cmake_minimum_required (VERSION 3.10...3.30) # have to be adapted or the option deactivated. option (HIBF_BENCHMARK_ALIGN_LOOPS "Pass -falign-loops=32 to the benchmark builds." ON) +include (CheckIPOSupported) +check_ipo_supported (RESULT HIBF_TEST_HAS_LTO OUTPUT HIBF_TEST_HAS_LTO_OUTPUT) +if (HIBF_TEST_HAS_LTO) + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +endif () + get_filename_component (HIBF_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) add_subdirectory ("${HIBF_ROOT_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/hibf_lib") target_compile_options (hibf PUBLIC "-pedantic" "-Wall" "-Wextra" "-Werror") diff --git a/test/tutorial/CMakeLists.txt b/test/tutorial/CMakeLists.txt index 46aab3d2..a2a8f6f8 100644 --- a/test/tutorial/CMakeLists.txt +++ b/test/tutorial/CMakeLists.txt @@ -5,6 +5,12 @@ cmake_minimum_required (VERSION 3.16...3.30) project (hibf_test_tutorial CXX) +include (CheckIPOSupported) +check_ipo_supported (RESULT HIBF_TEST_HAS_LTO OUTPUT HIBF_TEST_HAS_LTO_OUTPUT) +if (HIBF_TEST_HAS_LTO) + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +endif () + set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 37727852..bffd2e8c 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -5,9 +5,10 @@ cmake_minimum_required (VERSION 3.10...3.30) project (hibf_util CXX) -# https://cmake.org/cmake/help/latest/policy/CMP0135.html -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) - cmake_policy (SET CMP0135 NEW) +include (CheckIPOSupported) +check_ipo_supported (RESULT HIBF_TEST_HAS_LTO OUTPUT HIBF_TEST_HAS_LTO_OUTPUT) +if (HIBF_TEST_HAS_LTO) + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif () # Dependency: seqan::hibf