diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05fd0af..d76da5e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,4 +34,3 @@ pages: paths: - public expire_in: 1 week - diff --git a/LICENSE b/LICENSE index b5b3635..61ab961 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +1 @@ -This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. \ No newline at end of file +This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. diff --git a/README.md b/README.md index 8496841..c189322 100644 --- a/README.md +++ b/README.md @@ -94,4 +94,3 @@ There are some other places to find good information on the web. Here are some o Modern CMake was originally written by [Henry Schreiner](https://iscinumpy.gitlab.io). Other contributors can be found [listed on GitLab](https://gitlab.com/CLIUtils/modern-cmake/-/network/master). [^1]: CMake 3.0 also removed several long deprecated features from very old versions of CMake and make one very tiny backwards incompatible change to syntax related to square brackets, so this is not entirely fair; there might be some very, very old CMake files that would stop working with 3. I've never seen one, though. - diff --git a/SUMMARY.md b/SUMMARY.md index 2f289ed..503d7d0 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -20,9 +20,9 @@ * [IDEs](chapters/features/ides.md) * [Debugging](chapters/features/debug.md) * [Including Projects](chapters/projects.md) - * [Submodule](chapters/projects/submodule.md) - * [DownloadProject](chapters/projects/download.md) - * [Fetch (CMake 3.11)](chapters/projects/fetch.md) + * [Submodule](chapters/projects/submodule.md) + * [DownloadProject](chapters/projects/download.md) + * [Fetch (CMake 3.11)](chapters/projects/fetch.md) * [Testing](chapters/testing.md) * [GoogleTest](chapters/testing/googletest.md) * [Catch](chapters/testing/catch.md) diff --git a/chapters/basics.md b/chapters/basics.md index 5c68cbb..ab6e7bf 100644 --- a/chapters/basics.md +++ b/chapters/basics.md @@ -157,7 +157,7 @@ See if you can follow the following file. It makes a simple C++11 library and a cmake_minimum_required(VERSION 3.8) project(Calculator LANGUAGES CXX) - + add_library(calclib STATIC src/calclib.cpp include/calc/lib.hpp) target_include_directories(calclib PUBLIC include) target_compile_features(calclib PUBLIC cxx_std_11) @@ -173,4 +173,3 @@ target_link_libraries(calc PUBLIC calclib) [^2]: You will sometimes see `FATAL_ERROR` here, that was needed to support nice failures when running this in CMake <2.6, which should not be a problem anymore. [^3]: The `::` syntax was originally intended for `INTERFACE IMPORTED` libraries, which were explicitly supposed to be libraries defined outside the current project. But, because of this, most of the `target_*` commands don't work on `IMPORTED` libraries, making them hard to set up yourself. So don't use the `IMPORTED` keyword for now, and use an `ALIAS` target instead; it will be fine until you start exporting targets. This limitation was fixed in CMake 3.11. - diff --git a/chapters/basics/comms.md b/chapters/basics/comms.md index f2ece7b..d79ec47 100644 --- a/chapters/basics/comms.md +++ b/chapters/basics/comms.md @@ -51,4 +51,3 @@ project(My LANGUAGES CXX VERSION ${VERSION_STRING}) ``` Above, `file(STRINGS file_name variable_name REGEX regex)` picks lines that match a regex; and the same regex is used to then pick out the parentheses capture group with the version part. Replace is used with back substitution to output only that one group. - diff --git a/chapters/basics/example.md b/chapters/basics/example.md index 98dc4fa..dc65308 100644 --- a/chapters/basics/example.md +++ b/chapters/basics/example.md @@ -1,10 +1,10 @@ # A simple example This is a simple yet complete example of a proper CMakeLists. For this program, we have one library (MyLibExample) with a header file and a source file, -and one application, MyExample, with one source file. +and one application, MyExample, with one source file. [import:'main', lang:'cmake'](../../examples/simple-project/CMakeLists.txt) The complete example is available in [examples folder](https://gitlab.com/CLIUtils/modern-cmake/tree/master/examples/simple-project). -A larger, multi-file example is [also available](https://gitlab.com/CLIUtils/modern-cmake/tree/master/examples/extended-project). \ No newline at end of file +A larger, multi-file example is [also available](https://gitlab.com/CLIUtils/modern-cmake/tree/master/examples/extended-project). diff --git a/chapters/basics/functions.md b/chapters/basics/functions.md index bcd3765..1d7643c 100644 --- a/chapters/basics/functions.md +++ b/chapters/basics/functions.md @@ -114,4 +114,4 @@ If you look at the official page, you'll see a slightly different method using s [^1]: They act as if they are evaluated at build/install time, though actually they are evaluated for each build configuration. -[^2]: The CMake docs splits expressions into Informational, Logical, and Output. +[^2]: The CMake docs splits expressions into Informational, Logical, and Output. diff --git a/chapters/basics/programs.md b/chapters/basics/programs.md index a033e66..fa08628 100644 --- a/chapters/basics/programs.md +++ b/chapters/basics/programs.md @@ -42,4 +42,3 @@ Here, the generation happens after `some_target` is complete, and happens when y A useful tool in writing CMake builds that work cross-platform is `cmake -E ` (seen in CMake files as `${CMAKE_COMMAND} -E`). This mode allows CMake to do a variety of things without calling system tools explicitly, like `copy`, `make_directory`, and `remove`. It is mostly used for the build time commands. Note that the very useful `create_symlink` mode used to be Unix only, but was added for Windows in CMake 3.13. [See the docs](https://cmake.org/cmake/help/latest/manual/cmake.1.html#command-line-tool-mode). [execute_process]: https://cmake.org/cmake/help/latest/command/execute_process.html - diff --git a/chapters/basics/structure.md b/chapters/basics/structure.md index f4b5f8e..4054170 100644 --- a/chapters/basics/structure.md +++ b/chapters/basics/structure.md @@ -62,4 +62,3 @@ endif() ``` See the [extended code example here](https://gitlab.com/CLIUtils/modern-cmake/tree/master/examples/extended-project). - diff --git a/chapters/basics/variables.md b/chapters/basics/variables.md index 0e8c497..515ed1d 100644 --- a/chapters/basics/variables.md +++ b/chapters/basics/variables.md @@ -51,8 +51,8 @@ Since `BOOL` is such a common variable type, you can set it more succinctly with ```cmake option(MY_OPTION "This is settable from the command line" OFF) - ``` - + ``` + For the `BOOL` datatype, there are several different wordings for `ON` and `OFF`. See [cmake-variables] for a listing of known variables in CMake. @@ -62,8 +62,8 @@ See [cmake-variables] for a listing of known variables in CMake. You can also `set(ENV{variable_name} value)` and get `$ENV{variable_name}` environment variables, though it is generally a very good idea to avoid them. ## The Cache - -The cache is actually just a text file, `CMakeCache.txt`, that gets created in the build directory when you run CMake. This is how CMake remembers anything you set, so you don't have to re-list your options every time you rerun CMake. + +The cache is actually just a text file, `CMakeCache.txt`, that gets created in the build directory when you run CMake. This is how CMake remembers anything you set, so you don't have to re-list your options every time you rerun CMake. ## Properties diff --git a/chapters/features/debug.md b/chapters/features/debug.md index 42dd4b2..2cefba6 100644 --- a/chapters/features/debug.md +++ b/chapters/features/debug.md @@ -49,4 +49,3 @@ If you add `--trace-expand`, the variables will be expanded into their values. For single-configuration generators, you can build your code with `-DCMAKE_BUILD_TYPE=Debug` to get debugging flags. In multi-configuration generators, like many IDEs, you can pick the configuration in the IDE. There are distinct flags for this mode (variables ending in `_DEBUG` as opposed to `_RELEASE`), as well as a generator expression value `CONFIG:Debug` or `CONFIG:Release`. Once you make a debug build, you can run a debugger, such as gdb or lldb on it. - diff --git a/chapters/features/ides.md b/chapters/features/ides.md index b52ca6e..a60455d 100644 --- a/chapters/features/ides.md +++ b/chapters/features/ides.md @@ -24,7 +24,7 @@ You can control how files show up in each folder with regular expressions or exp ## Folders for files -You can also control how the folders inside targets appear. There are two ways, both using the «command:source_group» command. The traditional way is +You can also control how the folders inside targets appear. There are two ways, both using the «command:source_group» command. The traditional way is ```cmake source_group("Source Files\\New Directory" REGULAR_EXPRESSION ".*\\.c[ucp]p?") diff --git a/chapters/features/modules.md b/chapters/features/modules.md index ab5fd32..561b802 100644 --- a/chapters/features/modules.md +++ b/chapters/features/modules.md @@ -84,7 +84,7 @@ try_compile( bindir SOURCES source.cpp -) +) ``` There are lots of options you can add, like `COMPILE_DEFINITIONS`. In CMake 3.8+, this will honor the CMake C/C++/CUDA standard settings. If you use `try_run` instead, it will run the resulting program and give you the output in `RUN_OUTPUT_VARIABLE`. diff --git a/chapters/install/exporting.md b/chapters/install/exporting.md index 7419e6a..594783a 100644 --- a/chapters/install/exporting.md +++ b/chapters/install/exporting.md @@ -22,4 +22,3 @@ export(PACKAGE MyLib) Now, if you `find_package(MyLib)`, CMake can find the build folder. Look at the generated `MyLibTargets.cmake` file to help you understand exactly what is created; it's just a normal CMake file, with the exported targets. Note that there's a downside: if you have imported dependencies, they will need to be imported before you `find_package`. That will be fixed in the next method. - diff --git a/chapters/install/installing.md b/chapters/install/installing.md index 2e3746f..72093be 100644 --- a/chapters/install/installing.md +++ b/chapters/install/installing.md @@ -55,7 +55,7 @@ find_dependency(MYDEP REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/MyLibTargets.cmake") ``` -Now, you can use configure file (if you used a `.in` file) and then install the resulting file. +Now, you can use configure file (if you used a `.in` file) and then install the resulting file. Since we've made a `ConfigVersion` file, this is a good place to install it too. ```cmake diff --git a/chapters/install/packaging.md b/chapters/install/packaging.md index b5e5d9e..9e3005a 100644 --- a/chapters/install/packaging.md +++ b/chapters/install/packaging.md @@ -34,4 +34,3 @@ Finally, you need to include the CPack module: ```cmake include(CPack) ``` - diff --git a/chapters/intro/dodonot.md b/chapters/intro/dodonot.md index 246ee3f..eddf621 100644 --- a/chapters/intro/dodonot.md +++ b/chapters/intro/dodonot.md @@ -8,7 +8,7 @@ The next two lists are heavily based on the excellent gist [Effective Modern CMa * **Don't add unneeded PUBLIC requirements**: You should avoid forcing something on users that is not required (`-Wall`). Make these PRIVATE instead. * **Don't GLOB files**: Make or another tool will not know if you add files without rerunning CMake. Note that CMake 3.12 adds a `CONFIGURE_DEPENDS` flag that makes this far better if you need to use it. * **Link to built files directly**: Always link to targets if available. -* **Never skip PUBLIC/PRIVATE when linking**: This causes all future linking to be keyword-less. +* **Never skip PUBLIC/PRIVATE when linking**: This causes all future linking to be keyword-less. ## CMake Patterns diff --git a/chapters/intro/installing.md b/chapters/intro/installing.md index ebd539a..ec1a2a0 100644 --- a/chapters/intro/installing.md +++ b/chapters/intro/installing.md @@ -120,7 +120,7 @@ You should only use the default CMake on 18.04+; it's an LTS release with a pret Just `pip install cmake` on many systems. Add `--user` if you have to. ManyLinux1 (old pip or OS) gets CMake 3.13.3. -### CI +### CI | Distribution | CMake version | Notes | |---------------|---------------|-------| diff --git a/chapters/intro/newcmake.md b/chapters/intro/newcmake.md index f86c261..95055c3 100644 --- a/chapters/intro/newcmake.md +++ b/chapters/intro/newcmake.md @@ -79,7 +79,7 @@ This release added Clang-Tidy support, along with more utilities and improvement * External projects can now be shallow clones, and other improvements -## [CMake 3.7][] : Android & CMake Server +## [CMake 3.7][] : Android & CMake Server You can now cross-compile to Android. Useful new if statement options really help clarify code. And the new server mode was supposed to improve integration with IDEs (but is being replaced by a different system in CMake 3.14+). Support for the VIM editor was also improved. @@ -95,7 +95,7 @@ You can now cross-compile to Android. Useful new if statement options really hel ## [CMake 3.8][] : C# & CUDA -This adds CUDA as a language, as well as `cxx_std_11` as a compiler meta-feature. The new generator expression could be really useful if you can require CMake 3.8+! +This adds CUDA as a language, as well as `cxx_std_11` as a compiler meta-feature. The new generator expression could be really useful if you can require CMake 3.8+! * Initially released [April 10, 2017](https://blog.kitware.com/cmake-3-8-0-available-for-download/) * Native support for C# as a language @@ -157,7 +157,7 @@ Very powerful release, containing lots of smaller long-requested features. One o but immediately noticeable changes is the addition of version ranges; you can now set both the minimum and maximum known CMake version easily. You can also set `CONFIGURE_DEPENDS` on a `GLOB`ed set of files, and the build system will check those files and -rerun if needed! You can use the general `PackageName_ROOT` +rerun if needed! You can use the general `PackageName_ROOT` for all `find_package` searches. Lots of additions to strings and lists, module updates, shiny new Python find module (2 and 3 versions too), and many more. @@ -195,7 +195,7 @@ of the source directory, for better file separation. And, `target_sources` *fina ## [CMake 3.14][] : File utilities (AKA [CMake π](https://blog.kitware.com/kitware-gets-mathematical-with-cmake-π-on-pi-day/)) -This release has lots of small cleanups, including several utilities for files. Generator expressions work in a few more places, and list handling is better with empty variables. +This release has lots of small cleanups, including several utilities for files. Generator expressions work in a few more places, and list handling is better with empty variables. Quite a few more find packages produce targets. The new Visual Studio 16 2019 generator is a bit different than older versions. Windows XP and Vista support has been dropped. * Initially released [March 14, 2019](https://blog.kitware.com/cmake-3-14-0-available-for-download/) @@ -241,7 +241,7 @@ fixes were implemented, especially to newer features, such as to FindPython, Fin A FindCUDAToolkit was finally added, which allows finding and using the CUDA toolkit without enabling the CUDA language! CUDA now is a bit more configurable, -such as linking to shared libraries. Quite a bit more polish in the expected areas, +such as linking to shared libraries. Quite a bit more polish in the expected areas, as well, like FindPython. Finally, you can now iterate over multiple lists at a time. * Initially released [March 20, 2020](https://blog.kitware.com/cmake-3-17-0-available-for-download/) @@ -283,19 +283,19 @@ features and papercut fixes are sprinkled throughout, a small selection is below [Releases]: https://cmake.org/cmake/help/latest/release/index.html -[CMake 3.0]: https://cmake.org/cmake/help/latest/release/3.0.html -[CMake 3.1]: https://cmake.org/cmake/help/latest/release/3.1.html -[CMake 3.2]: https://cmake.org/cmake/help/latest/release/3.2.html -[CMake 3.3]: https://cmake.org/cmake/help/latest/release/3.3.html -[CMake 3.4]: https://cmake.org/cmake/help/latest/release/3.4.html -[CMake 3.5]: https://cmake.org/cmake/help/latest/release/3.5.html -[CMake 3.6]: https://cmake.org/cmake/help/latest/release/3.6.html -[CMake 3.7]: https://cmake.org/cmake/help/latest/release/3.7.html -[CMake 3.8]: https://cmake.org/cmake/help/latest/release/3.8.html -[CMake 3.9]: https://cmake.org/cmake/help/latest/release/3.9.html -[CMake 3.10]: https://cmake.org/cmake/help/latest/release/3.10.html -[CMake 3.11]: https://cmake.org/cmake/help/latest/release/3.11.html -[CMake 3.12]: https://cmake.org/cmake/help/latest/release/3.12.html +[CMake 3.0]: https://cmake.org/cmake/help/latest/release/3.0.html +[CMake 3.1]: https://cmake.org/cmake/help/latest/release/3.1.html +[CMake 3.2]: https://cmake.org/cmake/help/latest/release/3.2.html +[CMake 3.3]: https://cmake.org/cmake/help/latest/release/3.3.html +[CMake 3.4]: https://cmake.org/cmake/help/latest/release/3.4.html +[CMake 3.5]: https://cmake.org/cmake/help/latest/release/3.5.html +[CMake 3.6]: https://cmake.org/cmake/help/latest/release/3.6.html +[CMake 3.7]: https://cmake.org/cmake/help/latest/release/3.7.html +[CMake 3.8]: https://cmake.org/cmake/help/latest/release/3.8.html +[CMake 3.9]: https://cmake.org/cmake/help/latest/release/3.9.html +[CMake 3.10]: https://cmake.org/cmake/help/latest/release/3.10.html +[CMake 3.11]: https://cmake.org/cmake/help/latest/release/3.11.html +[CMake 3.12]: https://cmake.org/cmake/help/latest/release/3.12.html [CMake 3.13]: https://cmake.org/cmake/help/latest/release/3.13.html [CMake 3.14]: https://cmake.org/cmake/help/latest/release/3.14.html [CMake 3.15]: https://cmake.org/cmake/help/latest/release/3.15.html diff --git a/chapters/intro/running.md b/chapters/intro/running.md index 2e2b7c3..f28332f 100644 --- a/chapters/intro/running.md +++ b/chapters/intro/running.md @@ -94,4 +94,3 @@ These are common CMake options to most packages: ## Debugging your CMake files We've already mentioned verbose output for the build, but you can also see verbose CMake configure output too. The `--trace` option will print every line of CMake that is run. Since this is very verbose, CMake 3.7 added `--trace-source="filename"`, which will print out every executed line of just the file you are interested in when it runs. If you select the name of the file you are interested in debugging (usually by selecting the parent directory when debugging a CMakeLists.txt, since all of those have the same name), you can just see the lines that run in that file. Very useful! - diff --git a/chapters/packages/CUDA.md b/chapters/packages/CUDA.md index be929c0..0b0bef0 100644 --- a/chapters/packages/CUDA.md +++ b/chapters/packages/CUDA.md @@ -28,7 +28,7 @@ check_language(CUDA) ``` You can see if CUDA is present by checking `CMAKE_CUDA_COMPILER` (was missing -until CMake 3.11). +until CMake 3.11). You can check variables like `CMAKE_CUDA_COMPILER_ID` (for nvcc, this is `"NVIDIA"`, Clang was added in CMake 3.18). You can check the version with @@ -63,7 +63,7 @@ set_target_properties(mylib PROPERTIES You can also directly make a PTX file with the `CUDA_PTX_COMPILATION` property. -### Targeting architectures +### Targeting architectures When you build CUDA code, you generally should be targeting an architecture. If you don't, you compile 'ptx', which provide the basic instructions but is compiled at runtime, making it potentially much slower to load. @@ -106,7 +106,7 @@ to find a variety of useful targets and variables even without enabling the CUDA language. > ### Note that FindCUDA is deprecated, but for for versions of CMake < 3.18, the following functions required FindCUDA: -> +> > * CUDA version checks / picking a version > * Architecture detection (Note: 3.12 fixes this partially) > * Linking to CUDA libraries from non-.cu files @@ -133,5 +133,3 @@ You'll also might want to allow a user to check for the arch flags of their curr ```cmake cuda_select_nvcc_arch_flags(ARCH_FLAGS) # optional argument for arch to add ``` - - diff --git a/chapters/packages/ROOT.md b/chapters/packages/ROOT.md index 3128cf4..20fe7c2 100644 --- a/chapters/packages/ROOT.md +++ b/chapters/packages/ROOT.md @@ -90,7 +90,7 @@ The final argument, listed after `LINKDEF`, must have a name that ends in `LinkD * `lib{NAME}.rootmap` (`G__` prefix removed): The rootmap file in plain text * `lib{NAME}_rdict.pcm` (`G__` prefix removed): A ROOT file -The final two output files must sit next to the library output. This is done by checking `CMAKE_LIBRARY_OUTPUT_DIRECTORY` (it will not pick up local target settings). If you have a libdir set but you don't have (global) install locations set, you'll also need to set `ARG_NOINSTALL` to `TRUE`. +The final two output files must sit next to the library output. This is done by checking `CMAKE_LIBRARY_OUTPUT_DIRECTORY` (it will not pick up local target settings). If you have a libdir set but you don't have (global) install locations set, you'll also need to set `ARG_NOINSTALL` to `TRUE`. [linkdef-root]: https://root.cern.ch/selecting-dictionary-entries-linkdefh @@ -132,4 +132,3 @@ set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY # Make sure you link with ROOT::Flags_CXX too! ``` - diff --git a/chapters/projects.md b/chapters/projects.md index a22297d..8d778ef 100644 --- a/chapters/projects.md +++ b/chapters/projects.md @@ -3,5 +3,4 @@ This is where a good Git system plus CMake shines. You might not be able to solve all the world's problems, but this is pretty close for C++! -There are several methods listed in the chapters in this section. - +There are several methods listed in the chapters in this section. diff --git a/chapters/projects/download.md b/chapters/projects/download.md index dd39a37..e2df823 100644 --- a/chapters/projects/download.md +++ b/chapters/projects/download.md @@ -10,4 +10,4 @@ Until CMake 3.11, the primary download method for packages was done at build tim ## Downloading Method: configure time If you prefer configure time, see the [Crascit/DownloadProject](https://github.com/Crascit/DownloadProject) repository for a drop-in solution. Submodules work so well, though, that I've discontinued most of the downloads for things like GoogleTest and moved them to submodules. Auto downloads are harder to mimic if you -don't have internet access, and they are often implemented in the build directory, wasting time and space if you have multiple build directories. +don't have internet access, and they are often implemented in the build directory, wasting time and space if you have multiple build directories. diff --git a/chapters/projects/fetch.md b/chapters/projects/fetch.md index 4daae0e..ea33b04 100644 --- a/chapters/projects/fetch.md +++ b/chapters/projects/fetch.md @@ -49,4 +49,3 @@ endif() Now you have the CMake 3.14+ syntax in CMake 3.11+. [FetchContent]: https://cmake.org/cmake/help/latest/module/FetchContent.html - diff --git a/examples/extended-project/CMakeLists.txt b/examples/extended-project/CMakeLists.txt index 5f2ceb2..a2759d7 100644 --- a/examples/extended-project/CMakeLists.txt +++ b/examples/extended-project/CMakeLists.txt @@ -2,46 +2,45 @@ cmake_minimum_required(VERSION 3.11...3.16) # Project name and a few useful settings. Other commands can pick up the results -project(ModernCMakeExample - VERSION 0.1 - DESCRIPTION "An example project with CMake" - LANGUAGES CXX) +project( + ModernCMakeExample + VERSION 0.1 + DESCRIPTION "An example project with CMake" + LANGUAGES CXX) # Only do these if this is the main project, and not if it is included through add_subdirectory if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - # Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here - - # Let's ensure -std=c++xx instead of -std=g++xx - set(CMAKE_CXX_EXTENSIONS OFF) + # Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here - # Let's nicely support folders in IDEs - set_property(GLOBAL PROPERTY USE_FOLDERS ON) + # Let's ensure -std=c++xx instead of -std=g++xx + set(CMAKE_CXX_EXTENSIONS OFF) - # Testing only available if this is the main app - # Note this needs to be done in the main CMakeLists - # since it calls enable_testing, which must be in the - # main CMakeLists. - include(CTest) + # Let's nicely support folders in IDEs + set_property(GLOBAL PROPERTY USE_FOLDERS ON) - # Docs only available if this is the main app - find_package(Doxygen) - if(Doxygen_FOUND) - add_subdirectory(docs) - else() - message(STATUS "Doxygen not found, not building docs") - endif() + # Testing only available if this is the main app + # Note this needs to be done in the main CMakeLists + # since it calls enable_testing, which must be in the + # main CMakeLists. + include(CTest) + + # Docs only available if this is the main app + find_package(Doxygen) + if(Doxygen_FOUND) + add_subdirectory(docs) + else() + message(STATUS "Doxygen not found, not building docs") + endif() endif() - # FetchContent added in CMake 3.11, downloads during the configure step include(FetchContent) # FetchContent_MakeAvailable was not added until CMake 3.14; use our shim if(${CMAKE_VERSION} VERSION_LESS 3.14) - include(cmake/add_FetchContent_MakeAvailable.cmake) + include(cmake/add_FetchContent_MakeAvailable.cmake) endif() - # Accumulator library # This is header only, so could be replaced with git submodules or FetchContent find_package(Boost REQUIRED) @@ -51,8 +50,7 @@ find_package(Boost REQUIRED) FetchContent_Declare( fmtlib GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 5.3.0 -) + GIT_TAG 5.3.0) FetchContent_MakeAvailable(fmtlib) # Adds fmt::fmt @@ -64,7 +62,7 @@ add_subdirectory(apps) # Testing only available if this is the main app # Emergency override MODERN_CMAKE_BUILD_TESTING provided as well -if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING) AND BUILD_TESTING) - add_subdirectory(tests) +if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING) + AND BUILD_TESTING) + add_subdirectory(tests) endif() - diff --git a/examples/extended-project/apps/app.cpp b/examples/extended-project/apps/app.cpp index 186f404..26a92ee 100644 --- a/examples/extended-project/apps/app.cpp +++ b/examples/extended-project/apps/app.cpp @@ -8,7 +8,7 @@ int main() { std::vector input = {1.2, 2.3, 3.4, 4.5}; - + auto [mean, moment] = accumulate_vector(input); fmt::print("Mean: {}, Moment: {}\n", mean, moment); diff --git a/examples/extended-project/cmake/FindSomeLib.cmake b/examples/extended-project/cmake/FindSomeLib.cmake index e69de29..8b13789 100644 --- a/examples/extended-project/cmake/FindSomeLib.cmake +++ b/examples/extended-project/cmake/FindSomeLib.cmake @@ -0,0 +1 @@ + diff --git a/examples/extended-project/cmake/add_FetchContent_MakeAvailable.cmake b/examples/extended-project/cmake/add_FetchContent_MakeAvailable.cmake index 3a2a4d5..f939da8 100644 --- a/examples/extended-project/cmake/add_FetchContent_MakeAvailable.cmake +++ b/examples/extended-project/cmake/add_FetchContent_MakeAvailable.cmake @@ -1,8 +1,7 @@ macro(FetchContent_MakeAvailable NAME) - FetchContent_GetProperties(${NAME}) - if(NOT ${NAME}_POPULATED) - FetchContent_Populate(${NAME}) - add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR}) - endif() + FetchContent_GetProperties(${NAME}) + if(NOT ${NAME}_POPULATED) + FetchContent_Populate(${NAME}) + add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR}) + endif() endmacro() - diff --git a/examples/extended-project/docs/CMakeLists.txt b/examples/extended-project/docs/CMakeLists.txt index a8436ba..f833062 100644 --- a/examples/extended-project/docs/CMakeLists.txt +++ b/examples/extended-project/docs/CMakeLists.txt @@ -1,9 +1,5 @@ set(DOXYGEN_EXTRACT_ALL YES) set(DOXYGEN_BUILTIN_STL_SUPPORT YES) -doxygen_add_docs(docs - modern/lib.hpp - "${CMAKE_CURRENT_SOURCE_DIR}/mainpage.md" - WORKING_DIRECTORY - "${PROJECT_SOURCE_DIR}/include" -) +doxygen_add_docs(docs modern/lib.hpp "${CMAKE_CURRENT_SOURCE_DIR}/mainpage.md" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/include") diff --git a/examples/extended-project/include/modern/lib.hpp b/examples/extended-project/include/modern/lib.hpp index 11ab491..a058e69 100644 --- a/examples/extended-project/include/modern/lib.hpp +++ b/examples/extended-project/include/modern/lib.hpp @@ -10,5 +10,3 @@ std::tuple accumulate_vector( const std::vector& values ///< The vector of values ); - - diff --git a/examples/extended-project/src/CMakeLists.txt b/examples/extended-project/src/CMakeLists.txt index 2213707..e3c614d 100644 --- a/examples/extended-project/src/CMakeLists.txt +++ b/examples/extended-project/src/CMakeLists.txt @@ -1,4 +1,3 @@ - # Note that headers are optional, and do not affect add_library, but they will not # show up in IDEs unless they are listed in add_library. @@ -19,4 +18,7 @@ target_link_libraries(modern_library PRIVATE Boost::boost) target_compile_features(modern_library PUBLIC cxx_std_11) # IDEs should put the headers in a nice place -source_group(TREE "${PROJECT_SOURCE_DIR}/include" PREFIX "Header Files" FILES ${HEADER_LIST}) +source_group( + TREE "${PROJECT_SOURCE_DIR}/include" + PREFIX "Header Files" + FILES ${HEADER_LIST}) diff --git a/examples/extended-project/tests/CMakeLists.txt b/examples/extended-project/tests/CMakeLists.txt index 2d06694..80ce3cf 100644 --- a/examples/extended-project/tests/CMakeLists.txt +++ b/examples/extended-project/tests/CMakeLists.txt @@ -1,10 +1,8 @@ - # Testing library FetchContent_Declare( -catch2 -GIT_REPOSITORY https://github.com/catchorg/Catch2.git -GIT_TAG v2.9.1 -) + catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.9.1) FetchContent_MakeAvailable(catch2) # Adds Catch2::Catch2 diff --git a/examples/extended-project/tests/testlib.cpp b/examples/extended-project/tests/testlib.cpp index 3a50df9..e4becee 100644 --- a/examples/extended-project/tests/testlib.cpp +++ b/examples/extended-project/tests/testlib.cpp @@ -9,4 +9,3 @@ TEST_CASE( "Quick check", "[main]" ) { REQUIRE( mean == 2.0 ); REQUIRE( moment == Approx(4.666666) ); } - diff --git a/examples/root-dict/CMakeLists.txt b/examples/root-dict/CMakeLists.txt index 342a9d5..8357102 100644 --- a/examples/root-dict/CMakeLists.txt +++ b/examples/root-dict/CMakeLists.txt @@ -1,4 +1,3 @@ - ## [main] cmake_minimum_required(VERSION 3.4...3.16) @@ -28,6 +27,7 @@ message(STATUS "Original definitions: ${ROOT_DEFINITIONS}") message(STATUS "Original exe flags: ${ROOT_EXE_LINKER_FLAGS}") enable_testing() -add_test(NAME RootDictExample - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - COMMAND "${ROOT_root_CMD}" -b -l -q "${CMAKE_CURRENT_SOURCE_DIR}/CheckLoad.C") +add_test( + NAME RootDictExample + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND "${ROOT_root_CMD}" -b -l -q "${CMAKE_CURRENT_SOURCE_DIR}/CheckLoad.C") diff --git a/examples/root-simple/CMakeLists.txt b/examples/root-simple/CMakeLists.txt index 4203db7..f5d9978 100644 --- a/examples/root-simple/CMakeLists.txt +++ b/examples/root-simple/CMakeLists.txt @@ -1,4 +1,3 @@ - ## [main] cmake_minimum_required(VERSION 3.1...3.16) @@ -9,7 +8,6 @@ project(RootSimpleExample LANGUAGES CXX) find_package(ROOT 6.16 CONFIG REQUIRED) ## [find_package] - # Adding an executable program and linking to needed ROOT libraries ## [add_and_link] add_executable(RootSimpleExample SimpleExample.cxx) diff --git a/examples/root-usefile/CMakeLists.txt b/examples/root-usefile/CMakeLists.txt index 7458ba1..8d3bba2 100644 --- a/examples/root-usefile/CMakeLists.txt +++ b/examples/root-usefile/CMakeLists.txt @@ -1,4 +1,3 @@ - ## [main] cmake_minimum_required(VERSION 3.1...3.16) @@ -17,7 +16,8 @@ include("${ROOT_USE_FILE}") separate_arguments(ROOT_EXE_LINKER_FLAGS) add_executable(RootUseFileExample SimpleExample.cxx) -target_link_libraries(RootUseFileExample PUBLIC ${ROOT_LIBRARIES} ${ROOT_EXE_LINKER_FLAGS}) +target_link_libraries(RootUseFileExample PUBLIC ${ROOT_LIBRARIES} + ${ROOT_EXE_LINKER_FLAGS}) ## [core] ## [main] diff --git a/examples/simple-project/CMakeLists.txt b/examples/simple-project/CMakeLists.txt index f9f6414..70e7045 100644 --- a/examples/simple-project/CMakeLists.txt +++ b/examples/simple-project/CMakeLists.txt @@ -1,4 +1,3 @@ - ## [main] # Almost all CMake files should start with this @@ -9,7 +8,10 @@ cmake_minimum_required(VERSION 3.1...3.16) # This is your project statement. You should always list languages; # Listing the version is nice here since it sets lots of useful variables -project(ModernCMakeExample VERSION 1.0 LANGUAGES CXX) +project( + ModernCMakeExample + VERSION 1.0 + LANGUAGES CXX) # If you set any CMAKE_ variables, that can go here. # (But usually don't do this, except maybe for C++ standard) @@ -39,4 +41,3 @@ target_link_libraries(MyExample PRIVATE MyLibExample) # you'll probably want tests too enable_testing() add_test(NAME MyExample COMMAND MyExample) -