Skip to content

Commit

Permalink
update cmake setup
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed Oct 15, 2024
1 parent 5d7a307 commit 2a2a6ee
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 88 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ include(thrust)
include(spdlog)
include(tetgen)
include(xsimd)
include(clang_format)

###############################
# Thrust Parallelization Set-Up
Expand Down
27 changes: 27 additions & 0 deletions cmake/clang_format.cmake
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 18 additions & 13 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -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}")
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()
20 changes: 8 additions & 12 deletions cmake/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -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()
35 changes: 13 additions & 22 deletions cmake/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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()
29 changes: 19 additions & 10 deletions cmake/tbb.cmake
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 6 additions & 8 deletions cmake/thrust.cmake
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 6 additions & 12 deletions cmake/xsimd.cmake
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 6 additions & 11 deletions cmake/yaml.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2a2a6ee

Please sign in to comment.