From 3b23ffba1c09d182541becb4ea1767f538af223e Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 23 Mar 2021 19:19:41 +0000 Subject: [PATCH] feat: CMake 3.20 --- .bumpversion.cfg | 10 +++++----- .gitlab-ci.yml | 2 +- README.md | 2 +- chapters/basics.md | 6 +++--- chapters/features/cpp11.md | 2 -- chapters/features/modules.md | 24 ------------------------ chapters/intro/installing.md | 12 ++++++------ chapters/intro/newcmake.md | 16 ++++++++++++++++ examples/CMakeLists.txt | 2 +- examples/extended-project/CMakeLists.txt | 4 ++-- examples/fetch/CMakeLists.txt | 2 +- examples/root-dict/CMakeLists.txt | 2 +- examples/root-simple/CMakeLists.txt | 2 +- examples/root-usefile/CMakeLists.txt | 2 +- examples/simple-project/CMakeLists.txt | 2 +- 15 files changed, 40 insertions(+), 50 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 4b7b88e..b0c0e5a 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,16 +1,16 @@ [bumpversion] -current_version = 3.19.4 +current_version = 3.20.0 [bumpversion:file:.gitlab-ci.yml] -search = cmake-{current_version}-Linux -replace = cmake-{new_version}-Linux +search = cmake-{current_version}-linux +replace = cmake-{new_version}-linux [bumpversion:file (2):.gitlab-ci.yml] serialize = {major}.{minor} [bumpversion:file:chapters/intro/installing.md] -search = cmake-{current_version}-Linux -replace = cmake-{new_version}-Linux +search = cmake-{current_version}-linux +replace = cmake-{new_version}-linux [bumpversion:file (2):chapters/intro/installing.md] serialize = {major}.{minor} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a3e4001..fa86bb0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ test_code: - apt-get update && apt-get install -y make cmake libboost-dev git # We will install latest CMake, even though Ubuntu has a recent one - mkdir -p $HOME/.local - - curl -s "https://cmake.org/files/v3.19/cmake-3.19.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local + - curl -s "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local - export PATH=$HOME/.local/bin:$PATH script: - cmake -S examples -B build diff --git a/README.md b/README.md index 6d3561b..5d9a942 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Certainly there are no shortage of problems when building. But I think that, in 2020, we have a very good solution to quite a few of those problems. It's CMake. Not CMake 2.8 though; that was released before C++11 even existed! Nor the horrible examples out there for CMake (even those posted on KitWare's own tutorials list). -I'm talking about Modern CMake. CMake 3.1+, maybe even CMake 3.19+! +I'm talking about Modern CMake. CMake 3.1+, maybe even CMake 3.20+! It's clean, powerful, and elegant, so you can spend most of your time coding, not adding lines to an unreadable, unmaintainable Make (Or CMake 2) file. And CMake 3.11+ is supposed to be significantly faster, as well! diff --git a/chapters/basics.md b/chapters/basics.md index e33d4c0..3629361 100644 --- a/chapters/basics.md +++ b/chapters/basics.md @@ -36,7 +36,7 @@ Windows users, who also usually have a very recent version of CMake. This is what new projects should do: ```cmake -cmake_minimum_required(VERSION 3.7...3.19) +cmake_minimum_required(VERSION 3.7...3.20) if(${CMAKE_VERSION} VERSION_LESS 3.12) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) @@ -56,10 +56,10 @@ you will want to do this instead: ```cmake cmake_minimum_required(VERSION 3.7) -if(${CMAKE_VERSION} VERSION_LESS 3.19) +if(${CMAKE_VERSION} VERSION_LESS 3.20) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.19) + cmake_policy(VERSION 3.20) endif() ``` diff --git a/chapters/features/cpp11.md b/chapters/features/cpp11.md index a7525e4..00a86c2 100644 --- a/chapters/features/cpp11.md +++ b/chapters/features/cpp11.md @@ -24,8 +24,6 @@ You can ask for specific compiler features to be available. This was more granul If you have optional features, you can use the list `CMAKE_CXX_COMPILE_FEATURES` and use `if(... IN_LIST ...)` from CMake 3.3+ to see if that feature is supported, and add it conditionally. See [the docs here](https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html) for other use cases. -A related feature, [`WriteCompilerDetectionHeader`](https://cmake.org/cmake/help/latest/module/WriteCompilerDetectionHeader.html), is worth checking out. It is a module that lets you make a file with macros allowing you to check and support optional features for specific compilers. Like any header generator, this will require that you build with CMake so that your header can be generated as part of the build process (only important if you care about supporting multiple build systems, or if you are making a no-build header-only library). - ## CMake 3.1+: Global and property settings diff --git a/chapters/features/modules.md b/chapters/features/modules.md index 561b802..dda06ad 100644 --- a/chapters/features/modules.md +++ b/chapters/features/modules.md @@ -50,30 +50,6 @@ Note that `OUTPUT_VARIABLE` will also appear in the configuration printout, so c This is just one of many similar modules, such as `CheckIncludeFileCXX`, `CheckStructHasMember`, `TestBigEndian`, and `CheckTypeSize` that allow you to check for information about the system (and you can communicate that to your source code). -## «module:WriteCompilerDetectionHeader» - -This is an amazing module similar to the ones listed above, but special enough to deserve its own section. It allows you -to look for a list of features that some compilers support, and write out a C++ header file that lets you know whether that -feature is available. It even can provide compatibility macros for features that have changed names! - -To use: - -```cmake -write_compiler_detection_header( - FILE myoutput.h - PREFIX My - COMPILERS GNU Clang MSVC Intel - FEATURES cxx_variadic_templates -) -``` - -This supports compiler features (defined to 0 or 1), symbols (defined to empty or the symbol), and macros that -support different names. They will be prefixed with the PREFIX you provide. You can separate compilers into different -files using `OUTPUT_FILES_DIR`. - -The downside is that you do have to list the compilers you expect to support. If you use the `ALLOW_UNKNOWN_COMPILERS` flag(s), -you can keep this from erroring on unknown compilers, but it will still leave all features empty. - ## «command:`try_compile`»/«command:`try_run`» This is not exactly a module, but is crucial to many of the modules listed above. You can attempt to compile (and possibly run) a bit of code at configure time. This can allow you to get information about the capabilities of your system. The basic syntax is: diff --git a/chapters/intro/installing.md b/chapters/intro/installing.md index ed35691..912e172 100644 --- a/chapters/intro/installing.md +++ b/chapters/intro/installing.md @@ -4,7 +4,7 @@ Your CMake version should be newer than your compiler. It should be newer than the libraries you are using (especially Boost). New versions work better for everyone. {% endhint %} -If you have a built in copy of CMake, it isn't special or customized for your system. You can easily install a new one instead, either on the system level or the user level. Feel free to instruct your users here if they complain about a CMake requirement being set too high. Especially if they want 3.1+ support. Maybe even if they want 3.19+ support... +If you have a built in copy of CMake, it isn't special or customized for your system. You can easily install a new one instead, either on the system level or the user level. Feel free to instruct your users here if they complain about a CMake requirement being set too high. Especially if they want 3.1+ support. Maybe even if they want 3.20+ support... #### Quick list (more info on each method below) @@ -34,14 +34,14 @@ You can [download CMake from KitWare][download]. This is how you will probably g On Linux, there are several options. Kitware provides a [Debian/Ubunutu apt repository][apt], as well as [snap packages][snap]. There are universal Linux binaries provided, but you'll need to pick an install location. If you already use `~/.local` for user-space packages, the following single line command[^1] will get CMake for you [^2]: {% term %} -~ $ wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local +~ $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local {% endterm %} -If you just want a local folder with CMake only: +The names changed in 3.20; older releases had names like `cmake-3.19.7-Linux-x86_64.tar.gz`. If you just want a local folder with CMake only: {% term %} -~ $ mkdir -p cmake-3.19 && wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.19 -~ $ export PATH=`pwd`/cmake-3.19/bin:$PATH +~ $ mkdir -p cmake-3.20 && wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.20 +~ $ export PATH=`pwd`/cmake-3.20/bin:$PATH {% endterm %} You'll obviously want to append to the PATH every time you start a new terminal, or add it to your `.bashrc` or to an [LMod][] system. @@ -49,7 +49,7 @@ You'll obviously want to append to the PATH every time you start a new terminal, And, if you want a system install, install to `/usr/local`; this is an excellent choice in a Docker container, for example on GitLab CI. Do not try it on a non-containerized system. {% term %} -docker $ wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local +docker $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local {% endterm %} diff --git a/chapters/intro/newcmake.md b/chapters/intro/newcmake.md index 9dcbb94..dee38cb 100644 --- a/chapters/intro/newcmake.md +++ b/chapters/intro/newcmake.md @@ -305,6 +305,21 @@ for permissions. Further support for generator expressions in more places. * FindPython: `Python*_LINK_OPTIONS` added * `compute-sanitizer` for ctest now supports CUDA for memcheck +## [CMake 3.20][] : ... + +The CMake docs received a major boost in productivity by adding "new in" tags +to quickly see what was added without having to toggle documentation versions! +C++ 23 support added. Source files must have the extension listed now, and +LANGUAGE is always respected. Quite a bit of cleanup was done; make sure your +code is tested with `...3.20` before deploying that as your maximum. + +* Support added for C++23 +* CUDAARCHS environment variable for setting CUDA architectures. +* The new `IntelLLVM` compilers are now supported (OneAPI 2021.1), and `NVHPC` NVIDIA HPC SDK, as well. +* Some expanded generator expression support in custom commands/targets, install renaming. +* New `cmake_path` command for working with paths. +* Several removals, like `cmake-server`, `WriteCompilerDetectionHeader` (if policy set to 3.20+), and a few things that have newer methods now. + [Releases]: https://cmake.org/cmake/help/latest/release/index.html [CMake 3.0]: https://cmake.org/cmake/help/latest/release/3.0.html @@ -327,6 +342,7 @@ for permissions. Further support for generator expressions in more places. [CMake 3.17]: https://cmake.org/cmake/help/latest/release/3.17.html [CMake 3.18]: https://cmake.org/cmake/help/latest/release/3.18.html [CMake 3.19]: https://cmake.org/cmake/help/latest/release/3.19.html +[CMake 3.20]: https://cmake.org/cmake/help/latest/release/3.20.html [CMake master]: https://cmake.org/cmake/help/git-master/release/index.html [fastercmake]: https://blog.kitware.com/improving-cmakes-runtime-performance/ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 18f4646..eb9f6b3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11...3.19) +cmake_minimum_required(VERSION 3.11...3.20) project(ModernCMakeExamples) set(MODERN_CMAKE_BUILD_TESTING ON) diff --git a/examples/extended-project/CMakeLists.txt b/examples/extended-project/CMakeLists.txt index 3b97f22..d3a24e8 100644 --- a/examples/extended-project/CMakeLists.txt +++ b/examples/extended-project/CMakeLists.txt @@ -1,5 +1,5 @@ -# Works with 3.11 and tested through 3.19 -cmake_minimum_required(VERSION 3.11...3.19) +# Works with 3.11 and tested through 3.20 +cmake_minimum_required(VERSION 3.11...3.20) # Project name and a few useful settings. Other commands can pick up the results project( diff --git a/examples/fetch/CMakeLists.txt b/examples/fetch/CMakeLists.txt index e0df994..0046d01 100644 --- a/examples/fetch/CMakeLists.txt +++ b/examples/fetch/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14...3.19) +cmake_minimum_required(VERSION 3.14...3.20) project(FetchExample LANGUAGES CXX) diff --git a/examples/root-dict/CMakeLists.txt b/examples/root-dict/CMakeLists.txt index 981c1f6..755b78b 100644 --- a/examples/root-dict/CMakeLists.txt +++ b/examples/root-dict/CMakeLists.txt @@ -2,7 +2,7 @@ ## [main] -cmake_minimum_required(VERSION 3.4...3.19) +cmake_minimum_required(VERSION 3.4...3.20) project(RootDictExample LANGUAGES CXX) diff --git a/examples/root-simple/CMakeLists.txt b/examples/root-simple/CMakeLists.txt index 0cb3006..bf6aab8 100644 --- a/examples/root-simple/CMakeLists.txt +++ b/examples/root-simple/CMakeLists.txt @@ -1,7 +1,7 @@ # CMake ROOT simple example ## [main] -cmake_minimum_required(VERSION 3.1...3.19) +cmake_minimum_required(VERSION 3.1...3.20) project(RootSimpleExample LANGUAGES CXX) diff --git a/examples/root-usefile/CMakeLists.txt b/examples/root-usefile/CMakeLists.txt index 512c240..f9e978f 100644 --- a/examples/root-usefile/CMakeLists.txt +++ b/examples/root-usefile/CMakeLists.txt @@ -1,7 +1,7 @@ # CMake ROOT usefile example ## [main] -cmake_minimum_required(VERSION 3.1...3.19) +cmake_minimum_required(VERSION 3.1...3.20) project(RootUseFileExample LANGUAGES CXX) diff --git a/examples/simple-project/CMakeLists.txt b/examples/simple-project/CMakeLists.txt index ff5b4d7..5614e83 100644 --- a/examples/simple-project/CMakeLists.txt +++ b/examples/simple-project/CMakeLists.txt @@ -6,7 +6,7 @@ # You should always specify a range with the newest # and oldest tested versions of CMake. This will ensure # you pick up the best policies. -cmake_minimum_required(VERSION 3.1...3.19) +cmake_minimum_required(VERSION 3.1...3.20) # This is your project statement. You should always list languages; # Listing the version is nice here since it sets lots of useful variables