Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up Minimum CMake Version to 3.20 #86530

Merged
merged 15 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/workflow/requirements/linux-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Minimum RAM required to build is 1GB. The build is known to fail on 512 MB VMs (

Install the following packages for the toolchain:

* CMake 3.14.5 or newer
* CMake 3.20 or newer
* llvm
* lld
* clang
Expand All @@ -40,12 +40,20 @@ Install the following packages for the toolchain:
* zlib1g-dev
* ninja-build (optional, enables building native code with ninja instead of make)

**NOTE**: If you have an Ubuntu version older than 22.04 LTS, don't install `cmake` using `apt`. Follow the note written down below.

```bash
sudo apt install -y cmake llvm lld clang build-essential \
python-is-python3 curl git lldb libicu-dev liblttng-ust-dev \
libssl-dev libkrb5-dev zlib1g-dev ninja-build
```

**NOTE**: As of now, `apt` only has until CMake version 3.16.3 if you're using Ubuntu 20.04 LTS (or less in older Ubuntu versions), which is lower than the required 3.20. For this case, we use the `snap` package manager, which has version 3.26.4 at the time of writing:

```bash
sudo snap install cmake
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also mention the Kitware APT feed, which always has the most recent version available as an official build from Kitware directly.

You now have all the required components.

#### Additional Requirements for Cross-Building
Expand Down
2 changes: 1 addition & 1 deletion docs/workflow/requirements/macos-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Building _dotnet/runtime_ depends on several tools to be installed. You can down

Install the following packages:

* CMake 3.15.5 or newer
* CMake 3.20 or newer
* icu4c
* [email protected] or openssl@3
* pkg-config
Expand Down
2 changes: 1 addition & 1 deletion docs/workflow/requirements/windows-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ These steps are required only in case the tools have not been installed as Visua
* Install [CMake](https://cmake.org/download) for Windows.
* Add its location (e.g. C:\Program Files (x86)\CMake\bin) to the PATH environment variable. The installation script has a check box to do this, but you can do it yourself after the fact following the instructions at [Adding to the Default PATH variable](#adding-to-the-default-path-variable).

The _dotnet/runtime_ repository recommends using CMake 3.16.4 or newer, but it may work with CMake 3.15.5.
The _dotnet/runtime_ repository requires using CMake 3.20 or newer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention something in the section about the -msbuild flag that CMake 3.21 is required to use that flag (maybe we can add validation of that at some point?)

Copy link
Member Author

@ivdiazsa ivdiazsa May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me. Do you mean that on Windows, if you have CMake 3.21 or later, you have to always use the -msbuild flag? As in:

.\build.cmd <args go here> -msbuild

Otherwise it will fail?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. I mean if you want to use the -msbuild flag on Windows, you need at least CMake 3.21 as the VS2022 generator doesn't exist in CMake until that version.


#### Ninja

Expand Down
15 changes: 4 additions & 11 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
cmake_minimum_required(VERSION 3.6.2)
cmake_minimum_required(VERSION 3.20)

cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH is enabled by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to set these policies individually after specifying minimum required version 3.20?

cmake_minimum_required(VERSION 3.20) should set these policies to NEW according to the docs: https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We plan to update the cmake_policy statements, remove redundant ones, as well as other build improvements after doing the initial minimum version upgrade. We wanted to keep the PR that is most likely to break workflows as small as possible to limit the risk of the change (and risk of having to revert it).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to keep this PR as minimal as possible and keep cleanup for later, this block can stay as is. The if (CMAKE_VERSION VERSION_GREATER ...) conditions are harmless.


if (CMAKE_VERSION VERSION_GREATER 3.7 OR CMAKE_VERSION VERSION_EQUAL 3.7)
cmake_policy(SET CMP0066 NEW) # Honor per-config flags in try_compile() source-file signature.
endif()
if (CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8)
cmake_policy(SET CMP0067 NEW) # Honor language standard in try_compile() source-file signature
endif()
if (CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
cmake_policy(SET CMP0091 NEW) # MSVC runtime library flags are selected by an abstraction.
endif()
cmake_policy(SET CMP0066 NEW) # Honor per-config flags in try_compile() source-file signature.
cmake_policy(SET CMP0067 NEW) # Honor language standard in try_compile() source-file signature
cmake_policy(SET CMP0091 NEW) # MSVC runtime library flags are selected by an abstraction.

# Set the project name
project(CoreCLR)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,12 @@

<ItemGroup>
<NormalTestAppBundles Include="$(NormalTestsAppBundleRoot)*/AppBundle/CMakeLists.txt" />
<NormalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.16)" />
<NormalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.20)" />
<NormalTestCMakeEntries Include="project(NormalTestAppBundles)" />
<NormalTestCMakeEntries Include="add_subdirectory(%(NormalTestAppBundles.RootDir)%(NormalTestAppBundles.Directory) %(NormalTestAppBundles.RecursiveDir) EXCLUDE_FROM_ALL)" />

<FunctionalTestAppBundles Include="$(FunctionalTestsAppBundleRoot)*/AppBundle/CMakeLists.txt" />
<FunctionalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.16)" />
<FunctionalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.20)" />
<FunctionalTestCMakeEntries Include="project(FunctionalTestAppBundles)" />
<FunctionalTestCMakeEntries Include="add_subdirectory(%(FunctionalTestAppBundles.RootDir)%(FunctionalTestAppBundles.Directory) %(FunctionalTestAppBundles.RecursiveDir) EXCLUDE_FROM_ALL)" />
</ItemGroup>
Expand Down
10 changes: 1 addition & 9 deletions src/native/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
cmake_minimum_required(VERSION 3.6.2)
cmake_minimum_required(VERSION 3.20)
include(CheckCCompilerFlag)

if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
# CMake 3.14.5 contains bug fixes for iOS
cmake_minimum_required(VERSION 3.14.5)
elseif (CLR_CMAKE_TARGET_MACCATALYST)
# CMake 3.18.1 properly generates MacCatalyst C compiler
cmake_minimum_required(VERSION 3.18.1)
endif ()

if (WIN32)
cmake_policy(SET CMP0091 NEW)
else ()
Expand Down