diff --git a/CMakeLists.txt b/CMakeLists.txt index 380051c..ff7c9be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ include(thrust) include(spdlog) include(tetgen) include(xsimd) +include(clang_format) ############################### # Thrust Parallelization Set-Up diff --git a/cmake/clang_format.cmake b/cmake/clang_format.cmake new file mode 100644 index 0000000..87d9bcb --- /dev/null +++ b/cmake/clang_format.cmake @@ -0,0 +1,27 @@ +file(GLOB_RECURSE CLANG_FORMAT_SRC + "${PROJECT_SOURCE_DIR}/src/*.cpp" + "${PROJECT_SOURCE_DIR}/src/*.h" + "${PROJECT_SOURCE_DIR}/test/*.cpp" + "${PROJECT_SOURCE_DIR}/test/*.h" +) + +# Define a variable for clang-format command +find_program(CLANG_FORMAT clang-format) + +# Ensure clang-format was found +if(NOT CLANG_FORMAT) + message(STATUS "HPCLab: clang-format not found. Please install it to use clang-format via CMake") +else() + message(STATUS "HPCLab: clang-format found. You can format all source files via `cmake --build . --target format`") + add_custom_command( + OUTPUT format_all_files + COMMAND ${CLANG_FORMAT} -i ${CLANG_FORMAT_SRC} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Formatting all source and test files with clang-format" + VERBATIM + ) + + add_custom_target(format + DEPENDS format_all_files + ) +endif() diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake index c968cce..9350769 100644 --- a/cmake/gtest.cmake +++ b/cmake/gtest.cmake @@ -1,18 +1,23 @@ include(FetchContent) -message(STATUS "Setting up gtest") +message(STATUS "Setting up Google Test") +set(GOOGLE_TEST_VERSION 1.15.2) + +find_package(GTest ${GOOGLE_TEST_VERSION} QUIET) -#Adapted from https://cliutils.gitlab.io/modern-cmake/chapters/testing/googletest.html -#Fetches the version 1.13.0 from the official github for googletest -FetchContent_Declare(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.13.0 - ) -FetchContent_MakeAvailable(googletest) +if(${GTest_FOUND}) + message(STATUS "Found existing Google Test: ${GTest_DIR}") +else() + message(STATUS "Using Google Test from GitHub Release ${GOOGLE_TEST_VERSION}") + + FetchContent_Declare(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v${GOOGLE_TEST_VERSION} + ) + FetchContent_MakeAvailable(googletest) -# Disable warnings from the library target -target_compile_options(gtest_main PRIVATE -w) -# Disable warnings from included headers -get_target_property(propval gtest_main INTERFACE_INCLUDE_DIRECTORIES) -target_include_directories(gtest_main SYSTEM PUBLIC "${propval}") \ No newline at end of file + target_compile_options(gtest_main PRIVATE -w) + get_target_property(propval gtest_main INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(gtest_main SYSTEM PUBLIC "${propval}") +endif() diff --git a/cmake/pybind11.cmake b/cmake/pybind11.cmake index be320d9..8c85ae2 100644 --- a/cmake/pybind11.cmake +++ b/cmake/pybind11.cmake @@ -1,22 +1,18 @@ include(FetchContent) -message(STATUS "Setting up pybind11") +message(STATUS "Setting up Pybind11 Library") +set(PYBIND11_VERSION 2.12.0) -find_package(pybind11 2.12.0 QUIET) - -if (${pybind11_FOUND}) - - message(STATUS "Using local pybind11 installation") +find_package(pybind11 ${PYBIND11_VERSION} QUIET) +if(${pybind11_FOUND}) + message(STATUS "Found existing Pybind11 Library: ${pybind11_DIR}") else() - - message(STATUS "Using pybind11 from git repository") + message(STATUS "Using Pybind11 Library from GitHub Release ${PYBIND11_VERSION}") FetchContent_Declare(pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.12.0 + GIT_TAG v${PYBIND11_VERSION} ) - FetchContent_MakeAvailable(pybind11) - -endif() +endif() \ No newline at end of file diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake index d5a8d0f..cbb0e49 100644 --- a/cmake/spdlog.cmake +++ b/cmake/spdlog.cmake @@ -1,33 +1,24 @@ include(FetchContent) message(STATUS "Setting up spdlog") +set(SPDLOG_VERSION 1.14.1) -find_package(spdlog 1.13.0 QUIET) - -if (${spdlog_FOUND}) - - message(STATUS "Using existing spdlog installation") +# Known Issue: +# If you install spdlog@1.14.1 via homebrew on ARM macOS, CMake will find spdlog +# However, there is a version mismatch between the `fmt` library installed as dependency, and the one actually +# being required leading to a linking error (i.e. missing symbols) while compiling! +find_package(spdlog ${SPDLOG_VERSION} QUIET) +if(${spdlog_FOUND}) + message(STATUS "Found existing spdlog Library: ${spdlog_DIR}") else() - - message(STATUS "Using spdlog from git repository") - + message(STATUS "Using Spdlog Library from GitHub Release ${SPDLOG_VERSION}") FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git - GIT_TAG v1.13.0 + GIT_TAG v${SPDLOG_VERSION} ) - - # Disable stuff we don't need - option(SPDLOG_BUILD_EXAMPLE "" OFF) - option(SPDLOG_BUILD_TESTS "" OFF) - option(SPDLOG_INSTALL "" OFF) - + set(SPDLOG_BUILD_EXAMPLE OFF CACHE BOOL "" FORCE) + set(SPDLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(SPDLOG_INSTALL OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(spdlog) - - # Disable warnings from the library target - target_compile_options(spdlog PRIVATE -w) - # Disable warnings from included headers - get_target_property(propval spdlog INTERFACE_INCLUDE_DIRECTORIES) - target_include_directories(spdlog SYSTEM PUBLIC "${propval}") - endif() \ No newline at end of file diff --git a/cmake/tbb.cmake b/cmake/tbb.cmake index 3f6136d..2be02c6 100644 --- a/cmake/tbb.cmake +++ b/cmake/tbb.cmake @@ -1,15 +1,24 @@ include(FetchContent) -message(STATUS "Setting up tbb via CMake") +message(STATUS "Setting up tbb") +set(TBB_VERSION 2021.12.0) -#Fetches the version v2021.12.0 from the official github of tbb -FetchContent_Declare(tbb - GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git - GIT_TAG v2021.12.0 -) +find_package(TBB QUIET HINTS /opt/homebrew/Cellar/tbb) -# Disable tests & and do not treat tbb-compile errors as warnings -option(TBB_TEST "Enable testing" OFF) -option(TBB_STRICT "Treat compiler warnings as errors" OFF) +if(${TBB_FOUND}) + message(STATUS "Found existing TBB library: ${TBB_DIR}") +else() + message(STATUS "Using TBB from GitHub Release ${TBB_VERSION}") -FetchContent_MakeAvailable(tbb) + #Fetches the version v2021.12.0 from the official github of tbb + FetchContent_Declare(tbb + GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git + GIT_TAG v${TBB_VERSION} + ) + + # Disable tests & and do not treat tbb-compile errors as warnings + set(TBB_TEST OFF CACHE BOOL "" FORCE) + set(TBB_STRICT OFF CACHE BOOl "" FORCE) + + FetchContent_MakeAvailable(tbb) +endif() diff --git a/cmake/thrust.cmake b/cmake/thrust.cmake index a7ef8bf..0511df7 100644 --- a/cmake/thrust.cmake +++ b/cmake/thrust.cmake @@ -1,28 +1,26 @@ include(FetchContent) message(STATUS "Setting up thrust") +set(THRUST_VERSION 1.16.0) # Set custom variables, policies, etc. # Disable stuff not needed set(THRUST_ENABLE_HEADER_TESTING "OFF") set(THRUST_ENABLE_TESTING "OFF") set(THRUST_ENABLE_EXAMPLES "OFF") - # Set standard CPP Dialect to 17 (default of thrust would be 14) set(THRUST_CPP_DIALECT 17) -find_package(Thrust 1.16.0 QUIET) - -if (${Thrust_FOUND}) +find_package(Thrust ${THRUST_VERSION} QUIET) - message(STATUS "Using existing thrust installation") +if (${Thrust_FOUND}) + message(STATUS "Found existing thrust installation: ${Thrust_DIR}") else() - message(STATUS "Using thrust from git repository") - # Fetches the version 1.16.0 of the official NVIDIA Thrust repository + message(STATUS "Using thrust from GitHub Release ${THRUST_VERSION}") FetchContent_Declare(thrust GIT_REPOSITORY https://github.com/NVIDIA/thrust.git - GIT_TAG 1.16.0 + GIT_TAG ${THRUST_VERSION} ) FetchContent_MakeAvailable(thrust) endif() diff --git a/cmake/xsimd.cmake b/cmake/xsimd.cmake index 7fa01a1..a0d4c9e 100644 --- a/cmake/xsimd.cmake +++ b/cmake/xsimd.cmake @@ -1,24 +1,18 @@ include(FetchContent) -message(STATUS "Setting up xsimd via CMake") +message(STATUS "Setting up xsimd Library") +set(XSIMD_VERSION 11.1.0) - -find_package(xsimd 11.1 QUIET) +find_package(xsimd ${XSIMD_VERSION} QUIET) if (${xsimd_FOUND}) - - message(STATUS "Using existing xsimd installation") - + message(STATUS "Found existing xsimd Library: ${xsimd_DIR}") else() - - message(STATUS "Using xsimd from git repository") - - #Fetches the version 11.1.0 from the official github of tbb + message(STATUS "Using xsimd Library from GitHub Release ${XSIMD_VERSION}") FetchContent_Declare(xsimd GIT_REPOSITORY https://github.com/xtensor-stack/xsimd.git - GIT_TAG 11.1.0 + GIT_TAG ${XSIMD_VERSION} ) FetchContent_MakeAvailable(xsimd) - endif() diff --git a/cmake/yaml.cmake b/cmake/yaml.cmake index 8896a98..aeece0a 100644 --- a/cmake/yaml.cmake +++ b/cmake/yaml.cmake @@ -1,32 +1,27 @@ include(FetchContent) message(STATUS "Setting up yaml-cpp") +set(YAML_CPP_VERSION 0.8.0) -find_package(yaml-cpp 0.8.0 QUIET) +find_package(yaml-cpp ${YAML_CPP_VERSION} QUIET) if (${yaml-cpp_FOUND}) - - message(STATUS "Using existing yaml-cpp installation") - + message(STATUS "Found existing yaml-cpp library: ${yaml-cpp_DIR}") else() - - #Fetches the version 0.8.0 for yaml-cpp + message(STATUS "Using yaml-cpp from GitHub Release ${YAML_CPP_VERSION}") FetchContent_Declare(yaml-cpp GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git - GIT_TAG 0.8.0 + GIT_TAG ${YAML_CPP_VERSION} ) - # Disable everything we don't need set(YAML_CPP_BUILD_TESTS OFF CACHE INTERNAL "") set(YAML_CPP_BUILD_CONTRIB OFF CACHE INTERNAL "") set(YAML_CPP_BUILD_TOOLS OFF CACHE INTERNAL "") - + set(YAML_CPP_FORMAT_SOURCE OFF CACHE INTERNAL "") FetchContent_MakeAvailable(yaml-cpp) - # Disable warnings from the library target target_compile_options(yaml-cpp PRIVATE -w) # Disable warnings from included headers get_target_property(propval yaml-cpp INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(yaml-cpp SYSTEM PUBLIC "${propval}") - endif()