Skip to content

Commit

Permalink
Merge pull request #243 from eseiler/infra/lto
Browse files Browse the repository at this point in the history
[INFRA] CMake
  • Loading branch information
eseiler authored Oct 28, 2024
2 parents 326b948 + b958084 commit 7f601c1
Show file tree
Hide file tree
Showing 30 changed files with 67 additions and 95 deletions.
96 changes: 34 additions & 62 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.5...3.12)
cmake_minimum_required (VERSION 3.5...3.30)

# ----------------------------------------------------------------------------
# Greeter
Expand All @@ -22,6 +22,8 @@ include (CheckIncludeFileCXX)
include (CheckCXXSourceCompiles)
include (CheckCXXSourceRuns)
include (CheckCXXCompilerFlag)
include (CMakeDependentOption)
include (CheckIPOSupported)

# ----------------------------------------------------------------------------
# Find or add dependencies
Expand Down Expand Up @@ -83,6 +85,7 @@ hibf_require_ccache ()
# ----------------------------------------------------------------------------

set (CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set (HIBF_CXX_FLAGS "")

set (CXXSTD_TEST_SOURCE
"#if !defined (__cplusplus) || (__cplusplus < 202100)
Expand Down Expand Up @@ -111,7 +114,7 @@ set (CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
if (HIBF_CPP23_FLAG STREQUAL "BUILTIN")
hibf_config_print ("C++ Standard-23 support: builtin")
elseif (HIBF_CPP23_FLAG)
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} ${HIBF_FEATURE_CPP23_FLAG_${HIBF_CPP23_FLAG}}")
list (APPEND HIBF_CXX_FLAGS "${HIBF_FEATURE_CPP23_FLAG_${HIBF_CPP23_FLAG}}")
hibf_config_print ("C++ Standard-23 support: via ${HIBF_FEATURE_CPP23_FLAG_${HIBF_CPP23_FLAG}}")
else ()
hibf_config_error ("HIBF requires C++23, but your compiler does not support it.")
Expand Down Expand Up @@ -150,7 +153,7 @@ endif ()

check_cxx_compiler_flag ("-Wno-psabi" HIBF_SUPPRESS_GCC4_ABI)
if (HIBF_SUPPRESS_GCC4_ABI)
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} -Wno-psabi")
list (APPEND HIBF_CXX_FLAGS "-Wno-psabi")
hibf_config_print ("Suppressing GCC 4 warnings: via -Wno-psabi")
endif ()

Expand Down Expand Up @@ -227,68 +230,38 @@ else ()
set (HIBF_IS_DEBUG FALSE)
endif ()

# Apple M1 with GCC sets `-march=apple-m1` when using `-march=native`. This option is only available with GCC >= 13.
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm64"
AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
set (HIBF_M1_NO_NATIVE TRUE)
else ()
set (HIBF_M1_NO_NATIVE FALSE)
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)

option (HIBF_NATIVE_BUILD "Optimize build for current architecture." ON)
if (HIBF_M1_NO_NATIVE)
hibf_config_print ("Optimize build: disabled (Apple M1 with GCC < 13)")
elseif (HIBF_IS_DEBUG)
hibf_config_print ("Optimize build: disabled")
elseif (HIBF_NATIVE_BUILD)
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} -march=native")
if (HIBF_NATIVE_BUILD)
list (APPEND HIBF_CXX_FLAGS "-march=native")
hibf_config_print ("Optimize build: via -march=native")
else ()
check_cxx_compiler_flag ("-mpopcnt" HIBF_HAS_POPCNT)
if (HIBF_HAS_POPCNT)
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} -mpopcnt")
list (APPEND HIBF_CXX_FLAGS "-mpopcnt")
hibf_config_print ("Optimize build: via -mpopcnt")
else ()
hibf_config_print ("Optimize build: disabled")
endif ()
endif ()

option (HIBF_LTO_BUILD "Use Link Time Optimisation." ON)
if (HIBF_IS_DEBUG OR NOT HIBF_LTO_BUILD)
hibf_config_print ("Link Time Optimisation: disabled")
else ()
# CMake's check_ipo_supported uses hardcoded lto flags
# macOS GCC supports -flto-auto, but not the hardcoded flag "-fno-fat-lto-objects"
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set (HIBF_LTO_FLAGS "-flto=auto -ffat-lto-objects")
else ()
set (HIBF_LTO_FLAGS "-flto=auto")
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)

set (LTO_CMAKE_SOURCE
"cmake_minimum_required(VERSION ${CMAKE_VERSION})\nproject(lto-test LANGUAGES CXX)
cmake_policy(SET CMP0069 NEW)\nadd_library(foo foo.cpp)\nadd_executable(boo main.cpp)
target_link_libraries(boo PUBLIC foo)")
set (LTO_FOO_CPP "int foo(){return 0x42;}")
set (LTO_MAIN_CPP "int foo();int main(){return foo();}")
set (testdir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/lto-test")
set (bindir "${testdir}/bin")
set (srcdir "${testdir}/src")
file (MAKE_DIRECTORY "${bindir}")
file (MAKE_DIRECTORY "${srcdir}")
file (WRITE "${srcdir}/foo.cpp" "${LTO_FOO_CPP}")
file (WRITE "${srcdir}/main.cpp" "${LTO_MAIN_CPP}")
file (WRITE "${srcdir}/CMakeLists.txt" "${LTO_CMAKE_SOURCE}")
try_compile (HIBF_HAS_LTO "${bindir}"
"${srcdir}" "lto-test"
CMAKE_FLAGS "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DCMAKE_CXX_FLAGS:STRING=${HIBF_LTO_FLAGS}"
OUTPUT_VARIABLE output)
if (HIBF_HAS_LTO)
hibf_config_print ("Link Time Optimisation: enabled")
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} ${HIBF_LTO_FLAGS}")
if (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 ()
hibf_config_print ("Link Time Optimisation: not available")
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 ()
endif ()

Expand Down Expand Up @@ -357,21 +330,20 @@ set (CXXSTD_TEST_SOURCE "#include <hibf/platform.hpp>
int main() {}")

# using try_compile instead of check_cxx_source_compiles to capture output in case of failure
file (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" "${CXXSTD_TEST_SOURCE}\n")

try_compile (HIBF_PLATFORM_TEST #
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_CXX_FLAGS} ${HIBF_CXX_FLAGS}"
list (JOIN HIBF_CXX_FLAGS " " HIBF_TRY_COMPILE_CXX_FLAGS)
# cmake-format: off
try_compile (HIBF_PLATFORM_TEST
SOURCE_FROM_CONTENT src.cxx "#include <hibf/platform.hpp>\nint main() {}"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_CXX_FLAGS} ${HIBF_TRY_COMPILE_CXX_FLAGS}"
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_INCLUDE_PATH};${HIBF_HEADER_PATH}"
COMPILE_DEFINITIONS ${HIBF_DEFINITIONS}
LINK_LIBRARIES ${HIBF_LIBRARIES}
OUTPUT_VARIABLE HIBF_PLATFORM_TEST_OUTPUT)

# cmake-format: on
if (HIBF_PLATFORM_TEST)
hibf_config_print ("HIBF platform.hpp build: passed")
else ()
hibf_config_error ("HIBF platform.hpp build: failed\n${HIBF_PLATFORM_TEST_OUTPUT}")
set (HIBF_PLATFORM_TEST_LOG "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hibf.platform.compile.log")
file (WRITE "${HIBF_PLATFORM_TEST_LOG}" "${HIBF_PLATFORM_TEST_OUTPUT}")
hibf_config_error ("HIBF platform.hpp build: failed\n See ${HIBF_PLATFORM_TEST_LOG}")
endif ()

separate_arguments (HIBF_CXX_FLAGS UNIX_COMMAND "${HIBF_CXX_FLAGS}")
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10...3.30)

set (HIBF_SOURCE_FILES
hierarchical_interleaved_bloom_filter.cpp
interleaved_bloom_filter.cpp
Expand Down
2 changes: 1 addition & 1 deletion test/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10...3.22)
cmake_minimum_required (VERSION 3.10...3.30)
project (hibf_test)

option (INSTALL_HIBF "" OFF)
Expand Down
2 changes: 1 addition & 1 deletion test/clang_tidy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

project (hibf_tidy NONE)

Expand Down
2 changes: 1 addition & 1 deletion test/cmake/diagnostics/list_missing_unit_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

set (hibf_test_include_targets
""
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/diagnostics/list_unused_snippets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

set (hibf_test_snippets
""
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/diagnostics/list_unused_unit_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

set (hibf_test_targets
""
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_add_subdirectories.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# Calls add_subdirectory on all (direct) subdirectories of the given directory if they contain a `CMakeLists.txt`
#
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_generate_snippet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# Generate snippets from a source_snippet
#
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_macro_benchmark.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# Adds a macro benchmark target and a test which executes that macro benchmark
#
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_path_longest_stem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# A compatible function for cmake < 3.20 that basically returns `cmake_path (GET <filename> STEM LAST_ONLY <out_var>)`
function (hibf_path_longest_stem out_var filename)
Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_require_ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.15)
cmake_minimum_required (VERSION 3.15...3.30)

include (FindPackageMessage)

Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_test_component.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

include (hibf_path_longest_stem)

Expand Down
2 changes: 1 addition & 1 deletion test/cmake/hibf_test_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# Finds all files relative to the `test_base_path_` which satisfy the given file pattern.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

include (diagnostics/list_missing_unit_tests)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.12)
cmake_minimum_required (VERSION 3.12...3.30)

function (generate_include_dependencies_impl)
cmake_parse_arguments (
Expand Down
2 changes: 1 addition & 1 deletion test/coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10...3.22)
cmake_minimum_required (VERSION 3.10...3.30)
project (hibf_test_coverage CXX)

# Add a custom build type: Coverage
Expand Down
2 changes: 1 addition & 1 deletion test/documentation/hibf-doxygen-layout.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

include (${HIBF_HEADER_PATH}/../test/cmake/hibf_test_files.cmake)

Expand Down
2 changes: 1 addition & 1 deletion test/documentation/hibf-doxygen-package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

set (CPACK_GENERATOR "TXZ")

Expand Down
2 changes: 1 addition & 1 deletion test/documentation/hibf-doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

### Find doxygen and dependency to DOT tool
find_package (Doxygen REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion test/header/generate_header_source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

option (HEADER_FILE_ABSOLUTE "")
option (HEADER_FILE_INCLUDE "")
Expand Down
2 changes: 1 addition & 1 deletion test/hibf-test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# HIBF. To build tests, run cmake on one of the sub-folders in this directory
# which contain a CMakeLists.txt.

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# Force alignment of benchmarked loops so that numbers are reliable.
# For large loops and erratic seeming bench results the value might
Expand Down
2 changes: 1 addition & 1 deletion test/iwyu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

# cmake ../test/iwyu/ -DCMAKE_CXX_COMPILER="clang++-17" -DHIBF_IWYU_DIR=...
# make -j2 2> out.txt
Expand Down
2 changes: 1 addition & 1 deletion test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10...3.22)
cmake_minimum_required (VERSION 3.10...3.30)
project (hibf_test_performance CXX)

include (../hibf-test.cmake)
Expand Down
2 changes: 1 addition & 1 deletion test/snippet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10...3.22)
cmake_minimum_required (VERSION 3.10...3.30)
project (hibf_test_snippet CXX)

include (../hibf-test.cmake)
Expand Down
2 changes: 1 addition & 1 deletion test/snippet/compare_snippet_output.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.10...3.30)

include ("${CMAKE_CURRENT_LIST_DIR}/../cmake/hibf_path_longest_stem.cmake")

Expand Down
Loading

0 comments on commit 7f601c1

Please sign in to comment.