-
Notifications
You must be signed in to change notification settings - Fork 13
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 #182 from LLNL/feature/cmake
Support CMake FetchContent
- Loading branch information
Showing
11 changed files
with
145 additions
and
75 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(myproject) | ||
|
||
# Metall requires C++ 17 | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Boost header files are required | ||
find_package(Boost 1.64) | ||
|
||
# Download and setup Metall. | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
metall | ||
GIT_REPOSITORY https://github.com/LLNL/metall.git | ||
GIT_TAG master | ||
) | ||
FetchContent_MakeAvailable(metall) | ||
|
||
|
||
# ---------------------------------------- # | ||
# For using Metall CXX API | ||
# ---------------------------------------- # | ||
if (Boost_FOUND) | ||
find_package(Threads) | ||
|
||
add_executable(cpp_example ../src/cpp_example.cpp) | ||
|
||
# Need Boost header files | ||
target_include_directories(cpp_example PRIVATE ${Boost_INCLUDE_DIRS}) | ||
|
||
# Link Metall | ||
# Although target_link_libraries() is used, no library file (e.g., *.a file) is linked. | ||
# Only include path will be set here. | ||
target_link_libraries(cpp_example PRIVATE Metall) | ||
|
||
# This is required if one uses GCC | ||
target_link_libraries(cpp_example PRIVATE stdc++fs) | ||
|
||
target_link_libraries(cpp_example PRIVATE Threads::Threads) | ||
endif () | ||
|
||
|
||
# ---------------------------------------- # | ||
# For using Metall C API | ||
# ---------------------------------------- # | ||
if (Boost_FOUND) | ||
add_executable(c_example ../src/c_example.c) | ||
|
||
# Link Metall C library (libmetall_c) | ||
target_link_libraries(c_example PRIVATE metall_c) | ||
endif () |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
On this page, we describe how to download, install, and link Metall from a CMake project. | ||
|
||
To just find/link an already installed Metall package from a CMake project, see another example [here](../find_package). | ||
|
||
Here is an example CMake file that downloads, installs, and links Metall package [CMakeLists.txt](CMakeLists.txt). | ||
|
||
## Build | ||
|
||
Here is how to use the CMake file in this directory. | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
|
||
cmake ../ -DBOOST_ROOT=/path/to/boost \ | ||
-DBUILD_C=ON # Required to use Metall C API | ||
make | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
To just **find/link an already installed** Metall package from a CMake project, see [find_package](../find_package). | ||
|
||
To **have CMake download, install, and link** Metall, see [FetchContent](../FetchContent). |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Find Metall from CMake Project | ||
|
||
On this page, we describe how to **find/link an already installed** Metall package from a CMake project. | ||
|
||
To have CMake download, install, and link Metall, see another example [here](../FetchContent). | ||
|
||
Here is an example CMake file that finds an already installed Metall package [CMakeLists.txt](CMakeLists.txt). | ||
|
||
## 0. (pre-step) Install Metall | ||
|
||
Here is how to build example programs. | ||
|
||
### 0-1. Install Metall Manually | ||
|
||
To install Metall at `"/path/to/install"`, for example: | ||
```bash | ||
cd metall | ||
mkdir build | ||
cd build | ||
|
||
cmake ../ -DCMAKE_INSTALL_PREFIX="/path/to/install" | ||
# (option) add the following options to build the Metall C API library | ||
-DBOOST_ROOT=/path/to/boost -DBUILD_C=ON | ||
|
||
make && make install | ||
``` | ||
|
||
|
||
### 0-2. Install Metall using Spack | ||
|
||
Alternatively, one can install Metall using Spack. | ||
|
||
```bash | ||
# Install Metall using Spack | ||
# Boost is also install | ||
spack install metall | ||
``` | ||
|
||
|
||
## 1. Build | ||
|
||
Here is how to use the CMake file in this directory. | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
|
||
export CMAKE_PREFIX_PATH="/path/to/install" | ||
# Or | ||
spack load metall # Spack exports CMAKE_PREFIX_PATH | ||
|
||
cmake ../ \ | ||
-DBOOST_ROOT=/path/to/boost # Required to build programs that uses Metall C++ API. | ||
make | ||
``` |
File renamed without changes.
File renamed without changes.
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