Merge branch 'fix/cxxstd' into 'master'
fix: C++ standard should always be CACHE Followup to a suggestion at a meeting a long time ago, it's important that this always be CACHE so it can be changed easily. See merge request CLIUtils/modern-cmake!48
This commit is contained in:
commit
b54c9995f5
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 3.19.0
|
current_version = 3.19.4
|
||||||
|
|
||||||
[bumpversion:file:.gitlab-ci.yml]
|
[bumpversion:file:.gitlab-ci.yml]
|
||||||
search = cmake-{current_version}-Linux
|
search = cmake-{current_version}-Linux
|
||||||
|
@ -5,7 +5,7 @@ test_code:
|
|||||||
- apt-get update && apt-get install -y make cmake libboost-dev git
|
- apt-get update && apt-get install -y make cmake libboost-dev git
|
||||||
# We will install latest CMake, even though Ubuntu has a recent one
|
# We will install latest CMake, even though Ubuntu has a recent one
|
||||||
- mkdir -p $HOME/.local
|
- mkdir -p $HOME/.local
|
||||||
- curl -s "https://cmake.org/files/v3.19/cmake-3.19.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $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
|
||||||
- export PATH=$HOME/.local/bin:$PATH
|
- export PATH=$HOME/.local/bin:$PATH
|
||||||
script:
|
script:
|
||||||
- cmake -S examples -B build
|
- cmake -S examples -B build
|
||||||
|
@ -32,12 +32,12 @@ A related feature, [`WriteCompilerDetectionHeader`](https://cmake.org/cmake/help
|
|||||||
There is another way that C++ standards are supported; a specific set of three properties (both global and target level). The global properties are:
|
There is another way that C++ standards are supported; a specific set of three properties (both global and target level). The global properties are:
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use")
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
```
|
```
|
||||||
|
|
||||||
The first line sets a C++ standard level, and the second tells CMake to use it, and the final line is optional and ensures `-std=c++11` vs. something like `-std=g++11`. This method isn't bad for a final package, but shouldn't be used by a library. You can also set these values on a target:
|
The first line sets a C++ standard level, and the second tells CMake to use it, and the final line is optional and ensures `-std=c++11` vs. something like `-std=g++11`. This method isn't bad for a final package, but shouldn't be used by a library. You should always set this as a cached variable, so you can override it to try a new version easily (or if this gets used as a library, this is the only way to override it - but again, don't use this for libraries). You can also set these values on a target:
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
set_target_properties(myTarget PROPERTIES
|
set_target_properties(myTarget PROPERTIES
|
||||||
@ -47,7 +47,7 @@ set_target_properties(myTarget PROPERTIES
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Which is better, but still doesn't have the sort of explicit control that compiler features have for populating `PRIVATE` and `INTERFACE` properties.
|
Which is better, but still doesn't have the sort of explicit control that compiler features have for populating `PRIVATE` and `INTERFACE` properties, so it really is only useful on final targets.
|
||||||
|
|
||||||
You can find more information about the final two methods on [Craig Scott's useful blog post][crascit].
|
You can find more information about the final two methods on [Craig Scott's useful blog post][crascit].
|
||||||
|
|
||||||
|
@ -29,18 +29,18 @@ Ordered by author preference:
|
|||||||
|
|
||||||
## Official package
|
## Official package
|
||||||
|
|
||||||
You can [download CMake from KitWare][download]. This is how you will probably get CMake if you are on Windows. It's not a bad way to get it on macOS either, but using `brew install cmake` is much nicer if you use [Homebrew](https://brew.sh) (and you should). You can also get it on most other package managers, such as [Chocolatey](https://chocolatey.org) for Windows or [MacPorts](https://www.macports.org) for macOS.
|
You can [download CMake from KitWare][download]. This is how you will probably get CMake if you are on Windows. It's not a bad way to get it on macOS either (and a Universal2 version is supplied supporting both Intel and Apple Silicon), but using `brew install cmake` is much nicer if you use [Homebrew](https://brew.sh) (and you should; Apple even supports Homebrew such as during the Apple Silicon rollout). You can also get it on most other package managers, such as [Chocolatey](https://chocolatey.org) for Windows or [MacPorts](https://www.macports.org) for macOS.
|
||||||
|
|
||||||
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]:
|
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 %}
|
{% term %}
|
||||||
~ $ wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local
|
~ $ wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local
|
||||||
{% endterm %}
|
{% endterm %}
|
||||||
|
|
||||||
If you just want a local folder with CMake only:
|
If you just want a local folder with CMake only:
|
||||||
|
|
||||||
{% term %}
|
{% term %}
|
||||||
~ $ mkdir -p cmake-3.19 && wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.19
|
~ $ 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
|
~ $ export PATH=`pwd`/cmake-3.19/bin:$PATH
|
||||||
{% endterm %}
|
{% endterm %}
|
||||||
|
|
||||||
@ -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.
|
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 %}
|
{% term %}
|
||||||
docker $ wget -qO- "https://cmake.org/files/v3.19/cmake-3.19.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
|
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
|
||||||
{% endterm %}
|
{% endterm %}
|
||||||
|
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ You should only use the default CMake on 18.04+; it's an LTS release with a pret
|
|||||||
[![Conda-forge](https://img.shields.io/conda/vn/conda-forge/cmake.svg)][Conda-Forge]
|
[![Conda-forge](https://img.shields.io/conda/vn/conda-forge/cmake.svg)][Conda-Forge]
|
||||||
[![Anaconda](https://anaconda.org/anaconda/cmake/badges/version.svg?style=flat)][Anaconda]
|
[![Anaconda](https://anaconda.org/anaconda/cmake/badges/version.svg?style=flat)][Anaconda]
|
||||||
|
|
||||||
Just `pip install cmake` on many systems. Add `--user` if you have to (modern pip does this for you if needed).
|
Just `pip install cmake` on many systems. Add `--user` if you have to (modern pip does this for you if needed). This does not supply Universal2 wheels yet.
|
||||||
|
|
||||||
|
|
||||||
### CI
|
### CI
|
||||||
|
@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.4...3.19)
|
|||||||
|
|
||||||
project(RootDictExample LANGUAGES CXX)
|
project(RootDictExample LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
set(CMAKE_PLATFORM_INDEPENDENT_CODE ON)
|
set(CMAKE_PLATFORM_INDEPENDENT_CODE ON)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user