-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from chillenzer/update-cmake
Update cmake
- Loading branch information
Showing
1,218 changed files
with
1,858 additions
and
288,922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,73 @@ | ||
project(mallocMC LANGUAGES CXX) | ||
cmake_minimum_required(VERSION 3.18) | ||
cmake_minimum_required(VERSION 3.14...3.22) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
# ---- Project ---- | ||
|
||
if(POLICY CMP0074) | ||
cmake_policy(SET CMP0074 NEW) | ||
endif() | ||
project( | ||
mallocMC | ||
VERSION 3.0.0 | ||
LANGUAGES CXX | ||
) | ||
|
||
# find alpaka | ||
set(mallocMC_ALPAKA_PROVIDER "intern" CACHE STRING "Select which alpaka is used") | ||
set_property(CACHE mallocMC_ALPAKA_PROVIDER PROPERTY STRINGS "intern;extern") | ||
mark_as_advanced(mallocMC_ALPAKA_PROVIDER) | ||
if(${mallocMC_ALPAKA_PROVIDER} STREQUAL "intern") | ||
set(alpaka_BUILD_EXAMPLES OFF) | ||
set(BUILD_TESTING OFF) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/alpaka ${CMAKE_BINARY_DIR}/alpaka) | ||
else() | ||
find_package(alpaka HINTS $ENV{ALPAKA_ROOT}) | ||
endif() | ||
# ---- Include guards ---- | ||
|
||
if(NOT TARGET alpaka::alpaka) | ||
message(FATAL "Required mallocMC dependency alpaka could not be found!") | ||
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) | ||
message( | ||
FATAL_ERROR | ||
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there." | ||
) | ||
endif() | ||
|
||
# Catch2 | ||
set(mallocMC_CATCH2_PROVIDER "intern" CACHE STRING "Select which Catch2 is used") | ||
set_property(CACHE mallocMC_CATCH2_PROVIDER PROPERTY STRINGS "intern;extern") | ||
mark_as_advanced(mallocMC_CATCH2_PROVIDER) | ||
# ---- Add dependencies via CPM ---- | ||
# see https://github.com/TheLartians/CPM.cmake for more info | ||
|
||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/CPM_0.40.2.cmake) | ||
CPMUsePackageLock(${CMAKE_CURRENT_LIST_DIR}/cmake/package-lock.cmake) | ||
|
||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/add_controlled.cmake) | ||
|
||
# PackageProject.cmake will be used to make our target installable | ||
add_controlled("PackageProject.cmake" REQUIRED) | ||
add_controlled("alpaka" REQUIRED) | ||
|
||
# for installation, just copy include folder to install folder | ||
install( | ||
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/include/." | ||
DESTINATION include | ||
# ---- Create library ---- | ||
|
||
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20) | ||
|
||
# being a cross-platform target, we enforce standards conformance on MSVC | ||
target_compile_options(${PROJECT_NAME} INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->") | ||
|
||
target_include_directories( | ||
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}> | ||
) | ||
|
||
# warnings | ||
add_library(warnings INTERFACE) | ||
if(CMAKE_COMPILER_IS_GNUCXX) | ||
target_compile_options(warnings INTERFACE -Wall -Wshadow -Wno-unknown-pragmas -Wextra -Wno-unused-parameter -Wno-unused-local-typedefs) | ||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") | ||
target_compile_options(warnings INTERFACE -Wall -Wshadow) | ||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI") | ||
target_compile_options(warnings INTERFACE -Minform=inform) | ||
if(mallocMC_BUILD_TESTING) | ||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/tools.cmake) | ||
enable_testing() | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test ${CMAKE_BINARY_DIR}/test) | ||
endif() | ||
|
||
# Executables | ||
file(GLOB_RECURSE headers src/include/**) | ||
add_custom_target(mallocMCIde SOURCES ${headers}) # create a target with the header files for IDE projects | ||
source_group(TREE ${CMAKE_CURRENT_LIST_DIR}/src/include FILES ${headers}) | ||
|
||
alpaka_add_executable(mallocMC_Example01 EXCLUDE_FROM_ALL examples/mallocMC_example01.cpp) | ||
target_include_directories(mallocMC_Example01 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/include) | ||
target_link_libraries(mallocMC_Example01 PUBLIC alpaka::alpaka warnings) | ||
|
||
alpaka_add_executable(mallocMC_Example03 EXCLUDE_FROM_ALL examples/mallocMC_example03.cpp) | ||
target_include_directories(mallocMC_Example03 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/include) | ||
target_link_libraries(mallocMC_Example03 PUBLIC alpaka::alpaka warnings) | ||
|
||
add_custom_target(examples DEPENDS mallocMC_Example01 mallocMC_Example03) | ||
|
||
if(${mallocMC_CATCH2_PROVIDER} STREQUAL "intern") | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/catch2 ${CMAKE_BINARY_DIR}/catch2) | ||
include(Catch) | ||
else() | ||
# get Catch2 v3 and build it from source with the same C++ standard as the tests | ||
Include(FetchContent) | ||
FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.7.1) | ||
FetchContent_MakeAvailable(Catch2) | ||
target_compile_features(Catch2 PUBLIC cxx_std_20) | ||
include(Catch) | ||
|
||
# hide Catch2 cmake variables by default in cmake gui | ||
get_cmake_property(variables VARIABLES) | ||
foreach (var ${variables}) | ||
if (var MATCHES "^CATCH_") | ||
mark_as_advanced(${var}) | ||
endif() | ||
endforeach() | ||
if(mallocMC_BUILD_EXAMPLES) | ||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/tools.cmake) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples ${CMAKE_BINARY_DIR}/examples) | ||
endif() | ||
|
||
file(GLOB_RECURSE testSources "${CMAKE_CURRENT_SOURCE_DIR}/tests/*/*.cpp") | ||
alpaka_add_executable(tests EXCLUDE_FROM_ALL ${testSources}) | ||
catch_discover_tests(tests) | ||
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}/tests" FILES ${testSources}) | ||
target_compile_features(tests PRIVATE cxx_std_20) | ||
target_include_directories(tests PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/include) | ||
target_link_libraries(tests PRIVATE alpaka::alpaka Catch2::Catch2WithMain) | ||
# ---- Create an installable target ---- | ||
# this allows users to install and find the library via `find_package()`. | ||
|
||
# the location where the project's version header will be placed should match the project's regular | ||
# header paths | ||
string(TOLOWER ${PROJECT_NAME}/version.hpp VERSION_HEADER_LOCATION) | ||
|
||
packageProject( | ||
NAME ${PROJECT_NAME} | ||
VERSION ${PROJECT_VERSION} | ||
NAMESPACE ${PROJECT_NAME} | ||
BINARY_DIR ${PROJECT_BINARY_DIR} | ||
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include | ||
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} | ||
VERSION_HEADER "${VERSION_HEADER_LOCATION}" | ||
COMPATIBILITY SameMajorVersion | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.