Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,195
    • Issues 3,195
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 15
    • Merge Requests 15
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • CMake
  • CMakeCMake
  • Issues
  • #19854

Closed
Open
Opened Oct 18, 2019 by Deniz Bahadir@dbahadirContributor

Missing `CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE`

TL;DR;

Please implement missing CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE which acts similar to CMAKE_PROJECT_INCLUDE_BEFORE and CMAKE_PROJECT_<PROJECT_NAME>_INCLUDE.

Problem:

When using FetchContent with some (external) projects that use quite old CMake style (GoogleTest comes to mind) very often several policy warnings occur.

For example for GoogleTest (v1.8.0) the following warning occurs three times, once for each CMakeLists.txt:

  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

Just ignoring the warning with -Wno-dev is not possible, as that is a command-line option to be used when calling the cmake executable, which cannot be set through FetchContent. (See: https://stackoverflow.com/q/53562639/3115457)

Hack-ish solution:

We could use the PATCH_COMMAND option of FetchContent_Declare to patch the problematic CMakeLists.txt files but that is difficult to achieve and maintain correctly.

Cleaner, almost complete solution:

Using the CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE variable would be an easier and almost complete solution.
Using that would allow to make the fetched CMakeLists.txt files include a specific file which might set the missing policies to appropriate values.

For the GoogleTest example from above the following reduces the number of occurrences of the shown policy warning to one:

## in ./GoogleTest-policies-fix.cmake
cmake_policy( SET CMP0048 NEW )


## in ./CMakeLists.txt
...
FetchContent_Declare( googletest ... )

# Note: `googletest-distribution` is the name of the root-project of the fetched `GoogleTest`.
set( CMAKE_PROJECT_googletest-distribution_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/GoogleTest-policies-fix.cmake" )

FetchContent_MakeAvailable( googletest )

The only warning that remains stems from the call to project() in GoogleTests root CMakeLists.txt, because that file with the policy-fix is only included at the end of the call to project() at which point the warning already was triggered.

Best and preferred solution:


With the help of a variable CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE, which is included directly before the call to project() (similar to CMAKE_PROJECT_INCLUDE_BEFORE), even that last warning from the fetched root CMakeLists.txt would be gone.

Additionally, it would be quite logical to provide that, as we already have the other pendents and only it is missing:

  • available: CMAKE_PROJECT_INCLUDE_BEFORE
  • available: CMAKE_PROJECT_INCLUDE
  • missing: CMAKE_PROJECT_<PROJECT_NAME>_INCLUDE_BEFORE
  • available: CMAKE_PROJECT_<PROJECT_NAME>_INCLUDE
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: cmake/cmake#19854