From 6fb5337b611297c011415f447de5aaa58f0056fb Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Thu, 29 Mar 2018 23:40:07 +0200 Subject: [PATCH] Better structure --- SUMMARY.md | 46 +++++++++----------- chapters/{options.md => basics/variables.md} | 0 chapters/builtin.md | 3 ++ chapters/external.md | 3 ++ specifics/MPI.md | 18 -------- specifics/OpenMP.md | 17 -------- 6 files changed, 26 insertions(+), 61 deletions(-) rename chapters/{options.md => basics/variables.md} (100%) create mode 100644 chapters/builtin.md create mode 100644 chapters/external.md diff --git a/SUMMARY.md b/SUMMARY.md index c53f8a7..ad549fe 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -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) diff --git a/chapters/options.md b/chapters/basics/variables.md similarity index 100% rename from chapters/options.md rename to chapters/basics/variables.md diff --git a/chapters/builtin.md b/chapters/builtin.md new file mode 100644 index 0000000..91ebb05 --- /dev/null +++ b/chapters/builtin.md @@ -0,0 +1,3 @@ +# Finding Package + +There are two ways to find packages in CMake. diff --git a/chapters/external.md b/chapters/external.md new file mode 100644 index 0000000..91ebb05 --- /dev/null +++ b/chapters/external.md @@ -0,0 +1,3 @@ +# Finding Package + +There are two ways to find packages in CMake. diff --git a/specifics/MPI.md b/specifics/MPI.md index 94e8310..0fec3ae 100644 --- a/specifics/MPI.md +++ b/specifics/MPI.md @@ -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) diff --git a/specifics/OpenMP.md b/specifics/OpenMP.md index eab32ca..99fe49e 100644 --- a/specifics/OpenMP.md +++ b/specifics/OpenMP.md @@ -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