Skip to content

Commit 0411562

Browse files
authored
Merge pull request #42 from scivision/feature-cmake
CMake: improve install
2 parents 483bae9 + 2a2950d commit 0411562

File tree

5 files changed

+56
-47
lines changed

5 files changed

+56
-47
lines changed

.github/workflows/ci_cmake.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
jobs:
1919

2020
linux:
21-
runs-on: ubuntu-20.04
21+
runs-on: ubuntu-latest
2222
name: CMake build on Linux
2323
timeout-minutes: 15
2424

@@ -33,7 +33,7 @@ jobs:
3333
ninja-build libopenmpi-dev openmpi-bin
3434
3535
- name: CMake configure
36-
run: cmake --preset=ninja -DCMAKE_INSTALL_PREFIX=~/libsc
36+
run: cmake --preset default -DCMAKE_INSTALL_PREFIX=~
3737

3838
- name: CMake build
3939
run: cmake --build build
@@ -42,11 +42,10 @@ jobs:
4242
run: cmake --install build
4343

4444
- name: CMake self-tests
45-
run: ctest --parallel 2 --output-on-failure
46-
working-directory: build
45+
run: ctest --preset default
4746

4847
- name: CMake configure examples
49-
run: cmake -B example/build -S example -Dmpi=yes -Dopenmp=yes -DSC_ROOT=~/libsc
48+
run: cmake -B example/build -S example -Dmpi=yes -Dopenmp=yes -DSC_ROOT=~
5049

5150
- name: CMake build examples
5251
run: cmake --build example/build
@@ -82,7 +81,7 @@ jobs:
8281
run: brew install open-mpi ninja
8382

8483
- name: CMake configure
85-
run: cmake --preset=mac -DCMAKE_INSTALL_PREFIX=~/libsc
84+
run: cmake --preset mac -DCMAKE_INSTALL_PREFIX=~
8685

8786
- name: CMake build
8887
run: cmake --build build
@@ -91,11 +90,10 @@ jobs:
9190
run: cmake --install build
9291

9392
- name: CMake self-tests
94-
run: ctest -E sort --parallel 2 --output-on-failure
95-
working-directory: build
93+
run: ctest -E sort --preset default
9694

9795
- name: CMake configure examples
98-
run: cmake -B example/build -S example -Dmpi=yes -DSC_ROOT=~/libsc
96+
run: cmake -B example/build -S example -Dmpi=yes -DSC_ROOT=~
9997

10098
- name: CMake build examples
10199
run: cmake --build example/build
@@ -157,11 +155,11 @@ jobs:
157155

158156
- name: CMake configure with MPI
159157
if: steps.check_files.outputs.files_exists == 'true'
160-
run: cmake --preset=ninja -DCMAKE_INSTALL_PREFIX=~/libsc
158+
run: cmake --preset default -DCMAKE_INSTALL_PREFIX=~
161159

162160
- name: CMake configure without MPI
163161
if: steps.check_files.outputs.files_exists == 'false'
164-
run: cmake --preset=ninja -Dmpi=no -DCMAKE_INSTALL_PREFIX=~/libsc
162+
run: cmake --preset default -Dmpi=no -DCMAKE_INSTALL_PREFIX=~
165163

166164
- name: CMake build
167165
run: cmake --build build
@@ -170,16 +168,15 @@ jobs:
170168
run: cmake --install build
171169

172170
- name: CMake self-tests
173-
run: ctest --parallel 2 --output-on-failure
174-
working-directory: build
171+
run: ctest --preset default
175172

176173
- name: CMake configure examples with MPI
177174
if: steps.check_files.outputs.files_exists == 'true'
178-
run: cmake -B example/build -S example -Dmpi=yes -Dopenmp=yes -DSC_ROOT=~/libsc
175+
run: cmake -B example/build -S example -Dmpi=yes -Dopenmp=yes -DSC_ROOT=~
179176

180177
- name: CMake configure examples without MPI
181178
if: steps.check_files.outputs.files_exists == 'false'
182-
run: cmake -B example/build -S example -Dopenmp=yes -DSC_ROOT=~/libsc
179+
run: cmake -B example/build -S example -Dopenmp=yes -DSC_ROOT=~
183180

184181
- name: CMake build examples
185182
run: cmake --build example/build

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ endif(BUILD_TESTING)
7474

7575
# --- packaging
7676

77+
install(FILES
78+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/FindSC.cmake
79+
DESTINATION lib/cmake/Modules)
80+
7781
include(cmake/pkgconf.cmake)
7882
include(cmake/install.cmake)
7983

CMakePresets.json

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
{
2-
"version": 1,
3-
"cmakeMinimumRequired": {
4-
"major": 3,
5-
"minor": 19,
6-
"patch": 0
2+
"version": 2,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
77
},
88

99
"configurePresets": [
1010
{
11-
"name": "_default", "hidden": true,
11+
"name": "default",
1212
"binaryDir": "${sourceDir}/build",
13+
"generator": "Ninja",
1314
"cacheVariables": {"CMAKE_BUILD_TYPE": "Release",
1415
"mpi": true,
1516
"openmp": true}
1617
},
1718
{
18-
"name": "ninja", "inherits": "_default",
19-
"displayName": "build with Ninja",
20-
"description": "Ninja is a faster alternative to Make",
21-
"generator": "Ninja"
22-
},
23-
{
24-
"name": "mac", "inherits": "ninja",
19+
"name": "mac", "inherits": "default",
2520
"displayName": "MacOS",
2621
"description": "MacOS: OpenMP not used",
2722
"cacheVariables": {"openmp": false}
@@ -32,19 +27,18 @@
3227
"description": "MacOS: OpenMP not used, using Make"
3328
},
3429
{
35-
"name": "make", "inherits": "_default",
30+
"name": "make", "inherits": "default",
3631
"displayName": "build with GNU Make",
3732
"generator": "Unix Makefiles"
3833
},
3934
{
40-
"name": "makewin", "inherits": "_default",
35+
"name": "makewin", "inherits": "default",
4136
"displayName": "build with GNU Make: Windows",
4237
"generator": "MinGW Makefiles"
4338
},
4439
{
45-
"name": "intel", "inherits": "ninja",
40+
"name": "intel", "inherits": "default",
4641
"displayName": "Intel Classic compiler: Linux/MacOS",
47-
"description": "build with Intel Classic on Linux/MacOS",
4842
"environment": {
4943
"CC": "icc",
5044
"CXX": "icpc",
@@ -55,7 +49,6 @@
5549
{
5650
"name": "intelwin", "inherits": "intel",
5751
"displayName": "Intel Classic compiler: Windows",
58-
"description": "build with Intel Classic on Windows",
5952
"environment": {
6053
"CC": "icl",
6154
"CXX": "icl"
@@ -64,12 +57,30 @@
6457
{
6558
"name": "intelnext", "inherits": "intel",
6659
"displayName": "Intel oneAPI LLVM",
67-
"description": "build with Intel oneAPI NextGen LLVM",
6860
"environment": {
6961
"CC": "icx",
7062
"CXX": "icx",
7163
"FC": "ifx"
7264
}
7365
}
66+
],
67+
"buildPresets": [
68+
{
69+
"name": "default",
70+
"configurePreset": "default"
71+
}
72+
],
73+
"testPresets": [
74+
{
75+
"name": "default",
76+
"configurePreset": "default",
77+
"output": {
78+
"outputOnFailure": true,
79+
"verbosity": "default"
80+
},
81+
"execution": {
82+
"noTestsAction": "error",
83+
"stopOnFailure": false}
84+
}
7485
]
7586
}

cmake/install.cmake

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,20 @@ configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in
88

99
write_basic_package_version_file(
1010
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
11-
VERSION ${${PROJECT_NAME}_VERSION}
12-
COMPATIBILITY SameMinorVersion
13-
)
11+
COMPATIBILITY SameMinorVersion)
1412

1513
install(EXPORT ${PROJECT_NAME}Targets
16-
FILE ${PROJECT_NAME}Targets.cmake
1714
NAMESPACE ${PROJECT_NAME}::
18-
DESTINATION lib/cmake/${PROJECT_NAME}
19-
)
15+
DESTINATION lib/cmake/${PROJECT_NAME})
2016

2117
install(FILES
2218
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
2319
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake
2420
DESTINATION lib/cmake/${PROJECT_NAME})
2521

2622
export(EXPORT ${PROJECT_NAME}Targets
27-
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
28-
NAMESPACE ${PROJECT_NAME}::
29-
)
23+
FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake
24+
NAMESPACE ${PROJECT_NAME}::)
3025

3126
# --- CPack
3227

example/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ include(CTest)
55
include(CheckSymbolExists)
66
include(CheckIncludeFile)
77

8-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/Modules)
9-
108
option(mpi "use MPI" off)
119

1210
# --- find external libraries
@@ -21,14 +19,18 @@ find_package(ZLIB REQUIRED)
2119
find_package(Threads)
2220

2321
# --- find our library
24-
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG true)
2522

26-
find_package(SC REQUIRED PATHS ${PROJECT_SOURCE_DIR}/../build)
23+
if(NOT SC_ROOT AND NOT DEFINED ENV{SC_ROOT})
24+
set(SC_ROOT ${PROJECT_SOURCE_DIR}/../build)
25+
endif()
26+
27+
find_package(SC REQUIRED)
2728

2829
# --- get system capabilities
2930

3031
check_symbol_exists(sqrt math.h SC_NONEED_M)
3132
if(NOT SC_NONEED_M)
33+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
3234
check_symbol_exists(sqrt math.h SC_NEED_M)
3335
endif()
3436

0 commit comments

Comments
 (0)