Skip to content

Commit

Permalink
Merge pull request #275 from chillenzer/update-cmake
Browse files Browse the repository at this point in the history
Update cmake
  • Loading branch information
psychocoderHPC authored Jan 23, 2025
2 parents 8624e97 + 8a80fb1 commit cd4e065
Show file tree
Hide file tree
Showing 1,218 changed files with 1,858 additions and 288,922 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Continuous Integration
on: [push, pull_request]
env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules
CTEST_OUTPUT_ON_FAILURE: 1
jobs:
pre-commit:
runs-on: ubuntu-latest
Expand All @@ -18,26 +21,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: "**/cpm_modules"
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
- run: sudo apt update && sudo apt install libboost-all-dev
- run: mkdir build_dir
- working-directory: build_dir
run: |
git submodule init && git submodule update
- working-directory: build_dir
run: |
cmake .. \
-DCMAKE_CXX_FLAGS="-std=c++20 -g" \
-Dalpaka_CXX_STANDARD=20 \
-DmallocMC_CATCH2_PROVIDER=intern \
- run: |
cmake -S. -Bbuild \
-Dalpaka_ACC_CPU_B_OMP2_T_SEQ_ENABLE:BOOL=ON \
-Dalpaka_ACC_CPU_B_SEQ_T_OMP2_ENABLE:BOOL=ON \
-Dalpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE:BOOL=ON \
-Dalpaka_ACC_CPU_B_SEQ_T_THREADS_ENABLE:BOOL=ON
- working-directory: build_dir
run: make -j tests examples
- working-directory: build_dir
run: ./tests
- working-directory: build_dir
run: ./mallocMC_Example01
- working-directory: build_dir
run: ./mallocMC_Example03
-Dalpaka_ACC_CPU_B_SEQ_T_THREADS_ENABLE:BOOL=ON \
-DmallocMC_BUILD_TESTING:BOOL=ON \
-DmallocMC_BUILD_EXAMPLES:BOOL=ON
- working-directory: build
run: cmake --build . -j
- working-directory: build
run: ctest
- working-directory: build
run: |
for example in examples/[^C]*/mallocMCExample*; do
./${example}
done
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
minimum_pre_commit_version: 3.2.0 # necessitated by Lucas-C's hooks
default_install_hook_types: [pre-commit, pre-push]
exclude: |
(?x)^(
alpaka/.*|
thirdParty/.*
)$
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
Expand Down
136 changes: 60 additions & 76 deletions CMakeLists.txt
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
)
170 changes: 0 additions & 170 deletions alpaka/.clang-format

This file was deleted.

3 changes: 0 additions & 3 deletions alpaka/.dockerignore

This file was deleted.

Loading

0 comments on commit cd4e065

Please sign in to comment.