Skip to content

Commit ebb754e

Browse files
committed
Add CMake presets
They currently relect the content of do-configure.
1 parent 2e5b25f commit ebb754e

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

CMakeLists.txt

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
# Project name
3+
# try to prevent modification of source directory
4+
# note: some files may still be written before CMake can abort and need to be removed manually
5+
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
6+
message(
7+
FATAL_ERROR
8+
"In-source build not allowed. "
9+
"Please create a new directory, preferably next to the source directory, and run CMake from there. "
10+
"You may want to remove CMakeCache.txt and CMakeFiles/ which were created in the source directory."
11+
)
12+
endif()
13+
414
project(mirco VERSION 0.1.0)
515

6-
# Check for out-of-source build
7-
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
8-
message(FATAL_ERROR "\nIn-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n\nTo clean-up, you may need to remove CMakeCache.txt and CMakeFiles from your source directory.")
9-
endif()
16+
# Print CMake version to screen
17+
message(STATUS "Using CMake ${CMAKE_VERSION}")
1018

19+
# Enforce the C++ standard we are using and turn off compiler-specific extensions
1120
set(CMAKE_CXX_STANDARD 17)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_CXX_EXTENSIONS OFF)
23+
24+
# We do not use C++ modules (yet). Turn off scanning to avoid issues with clang-tidy.
25+
# If you want to add module support, this problem needs to be revisited. Our hope
26+
# is that CMake and/or clang-tidy will be updated to handle modules better.
27+
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
28+
29+
# Ensure cmake setup the correct runtime path when installing
30+
# see here for more information: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
31+
include(GNUInstallDirs)
32+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
33+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
34+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
35+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1236

1337
# Add libraries
1438
if(GTEST_IN_MIRCO)
@@ -145,7 +169,7 @@ configure_package_config_file(cmake/mirco_libConfig.cmake.in
145169

146170
install(FILES
147171
${CMAKE_CURRENT_BINARY_DIR}/mirco_libConfig.cmake
148-
DESTINATION lib/cmake/mirco
172+
DESTINATION lib/cmake/mirco
149173
)
150174

151175
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION include/mirco FILES_MATCHING PATTERN "*.h")

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -22,62 +22,83 @@ cd <someBaseDir>
2222
mkdir <sourceDir>
2323
git clone --recursive https://github.com/imcs-compsim/MIRCO.git <sourceDir>
2424
```
25+
2526
where `<someBaseDir>` is some directory in your machine and `<sourceDir>` will contain the `MIRCO` source code.
2627

2728
If you have already cloned the repository using:
29+
2830
```bash
2931
git clone https://github.com/imcs-compsim/MIRCO.git <sourceDir>
3032
```
33+
3134
you can pull the submodules using:
35+
3236
```bash
3337
cd <sourceDir>
3438
git submodule update --init --recursive
3539
```
40+
3641
To update the submodules, you can use the following command from your source directory:
42+
3743
```bash
3844
git submodule update --recursive --remote
3945
```
4046

4147
### Configure and build the code
4248

4349
To create an out-of-source build, first create a build directory using:
50+
4451
```bash
4552
cd <someBaseDir>
4653
mkdir <buildDir>
4754
```
55+
4856
where `<buildDir>` is the build directory.
4957

5058
> Note: The exact location of `<buildDir>` is arbitrary, as long as it is _not_ a subdirectory of `<sourceDir>`.
5159
5260
Now, you have to navigate to the build directory and call the `do-configure` script in order to invoke `cmake`:
61+
5362
```bash
5463
cd <buildDir>
5564
<sourceDir>/do-configure
5665
```
5766

67+
Alternatively, you can use CMake presets:
68+
69+
```bash
70+
cd <buildDir>
71+
cmake --preset=<name_of_your_preset> <sourceDir>
72+
```
73+
5874
> **IMPORTANT** Make sure to set `Trilinos_DIR` to point to you Trilinos installation.
5975
6076
Build the `mirco` executable in the build directory using:
77+
6178
```bash
6279
cd <buildDir>
6380
make -j <numProc>
6481
```
82+
6583
with `<numProc>` specifying the number of processes used for compilation.
6684
The `mirco` executable will be created in the build directory.
6785

6886
### Run all tests
6987

7088
You can run the tests from the build directory using:
89+
7190
```bash
7291
ctest
7392
```
7493

7594
### Run the code
7695

7796
To run the code with an input file, use the following command in your build directory:
97+
7898
```bash
7999
./mirco <sourceDir>/Input/<someInputFile.xml>
80100
```
101+
81102
where `<someInputFile.xml>` is any input file in the prescribed format.
82103

83104
## How to cite MIRCO?

0 commit comments

Comments
 (0)