mirror of
1
0
Fork 0

Better structure

This commit is contained in:
Henry Fredrick Schreiner 2018-03-29 23:40:07 +02:00
parent 8fc1144b51
commit 6fb5337b61
6 changed files with 26 additions and 61 deletions

View File

@ -1,40 +1,34 @@
# Summary
* [An Introduction to Modern CMake](README.md)
* [Installing CMake](chapters/installing.md)
* [Running CMake](chapters/running.md)
* [What's new in CMake](chapters/newcmake.md)
---
## Making a CMakeLists
* [Installing CMake](chapters/installing.md)
* [Running CMake](chapters/running.md)
* [What's new in CMake](chapters/newcmake.md)
* [Introduction to the Basics](chapters/basics.md)
* [Variables and the Cache](chapters/options.md)
* [C++11 and Beyond](chapters/cpp11.md)
* [Variables and the Cache](chapters/basics/variables.md)
* [How to Structure Your Project](chapters/structure.md)
* [Running Other Programs (X)](chapters/programs.md)
* [Adding Features](chapters/features.md)
* [How to Structure Your Project](chapters/structure.md)
* [C++11 and Beyond](chapters/cpp11.md)
* [Tidy and Format (X)](chapters/tidy.md)
* [IDEs (X)](chapters/IDEs.md)
* [Debugging (X)](chapters/debug.md)
* [Including Projects](chapters/projects.md)
* [Submodule](chapters/projects/submodule.md)
* [DownloadProject](chapters/projects/download.md)
* [Fetch (3.11)](chapters/projects/fetch.md)
* [Running Other Programs (X)](chapters/programs.md)
* [Testing](chapters/testing.md)
* [GoogleTest](chapters/testing/googletest.md)
* [Catch](chapters/testing/catch.md)
* [Tidy and Format (X)](chapters/tidy.md)
* [IDEs (X)](chapters/IDEs.md)
* [Debugging (X)](chapters/debug.md)
* [Exporting and Installing](chapters/exporting.md)
* [Built-in package discovery](chapters/builtin.md)
* [CUDA](specifics/CUDA.md)
* [OpenMP](specifics/OpenMP.md)
* [Boost (X)](specifics/Boost.md)
* [MPI](specifics/MPI.md)
* [Other common packages](chapters/external.md)
* [ROOT](specifics/ROOT.md)
* [Simple Example](examples/root-simple/README.md)
* [Simple Example CMake 3.11+](examples/root-simple-3.11/README.md)
* [Dictionary Example](examples/root-dict/README.md)
---
## Specific packages
* [CUDA](specifics/CUDA.md)
* [OpenMP](specifics/OpenMP.md)
* [Boost (X)](specifics/Boost.md)
* [MPI](specifics/MPI.md)
* [ROOT](specifics/ROOT.md)
* [Simple Example](examples/root-simple/README.md)
* [Simple Example CMake 3.11+](examples/root-simple-3.11/README.md)
* [Dictionary Example](examples/root-dict/README.md)

3
chapters/builtin.md Normal file
View File

@ -0,0 +1,3 @@
# Finding Package
There are two ways to find packages in CMake.

3
chapters/external.md Normal file
View File

@ -0,0 +1,3 @@
# Finding Package
There are two ways to find packages in CMake.

View File

@ -14,24 +14,6 @@ target_link_libraries(MyTarget PUBLIC MPI::MPI_CXX)
However, you can imitate this on CMake 3.1+ with:
```cmake
find_package(MPI REQUIRED)
# For supporting CMake < 3.9:
if(NOT TARGET MPI::MPI_CXX)
add_library(MPI_LIB_TARGET INTERFACE)
add_library(MPI::MPI_CXX ALIAS MPI_LIB_TARGET)
target_compile_options(MPI_LIB_TARGET INTERFACE "${MPI_CXX_COMPILE_FLAGS}")
target_include_directories(MPI_LIB_TARGET INTERFACE "${MPI_CXX_INCLUDE_PATH}")
target_link_libraries(MPI_LIB_TARGET INTERFACE ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES})
endif()
message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
target_link_libraries(MyTarget PUBLIC MPI::MPI_CXX)
```
Or,
```cmake
find_package(MPI REQUIRED)

View File

@ -12,23 +12,6 @@ endif()
This not only is cleaner than the old method, it will also correctly set the library link line differently from the compile line if needed. However, if you need to support older CMake, the following works on CMake 3.1+:
```cmake
# For CMake < 3.9, we need to make the target ourselves
if(NOT TARGET OpenMP::OpenMP_CXX)
add_library(OpenMP_TARGET INTERFACE)
add_library(OpenMP::OpenMP_CXX ALIAS OpenMP_TARGET)
target_compile_options(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
target_link_libraries(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS})
find_package(Threads REQUIRED)
target_link_libraries(OpenMP_TARGET INTERFACE Threads::Threads)
endif()
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
```
or,
```cmake
# For CMake < 3.9, we need to make the target ourselves