Commit 667f2861 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'project-include-before'

f7acc126 project: Add variable CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3936
parents 53f95dc5 f7acc126
Pipeline #148900 passed with stage
in 0 seconds
...@@ -102,9 +102,12 @@ options are intended for use as default values in package metadata and documenta ...@@ -102,9 +102,12 @@ options are intended for use as default values in package metadata and documenta
Code Injection Code Injection
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
If the :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variable is set, the file If the :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` or
pointed to by that variable will be included as the first step of the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE` variables are set,
the files they point to will be included as the first step of the
``project()`` command. ``project()`` command.
If both are set, then :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` will be
included before :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE`.
If the :variable:`CMAKE_PROJECT_INCLUDE` or If the :variable:`CMAKE_PROJECT_INCLUDE` or
:variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables are set, the files :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables are set, the files
......
...@@ -216,6 +216,7 @@ Variables that Change Behavior ...@@ -216,6 +216,7 @@ Variables that Change Behavior
/variable/CMAKE_PROJECT_INCLUDE /variable/CMAKE_PROJECT_INCLUDE
/variable/CMAKE_PROJECT_INCLUDE_BEFORE /variable/CMAKE_PROJECT_INCLUDE_BEFORE
/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE /variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE
/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE_BEFORE
/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY /variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
/variable/CMAKE_STAGING_PREFIX /variable/CMAKE_STAGING_PREFIX
/variable/CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS /variable/CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
......
...@@ -5,5 +5,6 @@ A CMake language file or module to be included as the last step of all ...@@ -5,5 +5,6 @@ A CMake language file or module to be included as the last step of all
:command:`project` command calls. This is intended for injecting custom code :command:`project` command calls. This is intended for injecting custom code
into project builds without modifying their source. into project builds without modifying their source.
See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` and See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
:variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE` and
:variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables. :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables.
...@@ -5,5 +5,6 @@ A CMake language file or module to be included as the first step of all ...@@ -5,5 +5,6 @@ A CMake language file or module to be included as the first step of all
:command:`project` command calls. This is intended for injecting custom code :command:`project` command calls. This is intended for injecting custom code
into project builds without modifying their source. into project builds without modifying their source.
See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` and See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
:variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE` and
:variable:`CMAKE_PROJECT_INCLUDE` variables. :variable:`CMAKE_PROJECT_INCLUDE` variables.
...@@ -6,5 +6,6 @@ A CMake language file or module to be included as the last step of any ...@@ -6,5 +6,6 @@ A CMake language file or module to be included as the last step of any
name. This is intended for injecting custom code into project builds without name. This is intended for injecting custom code into project builds without
modifying their source. modifying their source.
See also the :variable:`CMAKE_PROJECT_INCLUDE` and See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE`,
:variable:`CMAKE_PROJECT_INCLUDE` and
:variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables. :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables.
CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE
-------------------------------------------
A CMake language file or module to be included as the first step of any
:command:`project` command calls that specify ``<PROJECT-NAME>`` as the project
name. This is intended for injecting custom code into project builds without
modifying their source.
See also the :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
:variable:`CMAKE_PROJECT_INCLUDE` and
:variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables.
...@@ -39,6 +39,11 @@ bool cmProjectCommand(std::vector<std::string> const& args, ...@@ -39,6 +39,11 @@ bool cmProjectCommand(std::vector<std::string> const& args,
std::string const& projectName = args[0]; std::string const& projectName = args[0];
if (!IncludeByVariable(status,
"CMAKE_PROJECT_" + projectName + "_INCLUDE_BEFORE")) {
return false;
}
mf.SetProjectName(projectName); mf.SetProjectName(projectName);
mf.AddCacheDefinition(projectName + "_BINARY_DIR", mf.AddCacheDefinition(projectName + "_BINARY_DIR",
......
...@@ -75,6 +75,12 @@ add_test(CMakeOnly.ProjectIncludeAny ${CMAKE_CMAKE_COMMAND} ...@@ -75,6 +75,12 @@ add_test(CMakeOnly.ProjectIncludeAny ${CMAKE_CMAKE_COMMAND}
add_test(CMakeOnly.ProjectIncludeBefore ${CMAKE_CMAKE_COMMAND} add_test(CMakeOnly.ProjectIncludeBefore ${CMAKE_CMAKE_COMMAND}
-DTEST=ProjectIncludeBefore -DTEST=ProjectIncludeBefore
-DCMAKE_ARGS=-DCMAKE_PROJECT_ProjectInclude_INCLUDE_BEFORE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectIncludeBefore/include.cmake
-P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
)
add_test(CMakeOnly.ProjectIncludeBeforeAny ${CMAKE_CMAKE_COMMAND}
-DTEST=ProjectIncludeBeforeAny
-DCMAKE_ARGS=-DCMAKE_PROJECT_INCLUDE_BEFORE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectIncludeBefore/include.cmake -DCMAKE_ARGS=-DCMAKE_PROJECT_INCLUDE_BEFORE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectIncludeBefore/include.cmake
-P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
) )
......
set(FOO TRUE)
project(ProjectInclude LANGUAGES NONE)
if(NOT AUTO_INCLUDE)
message(FATAL_ERROR "include file not found")
endif()
if(NOT FOO)
message(FATAL_ERROR "FOO is not set")
endif()
if(NOT "${PROJECT_NAME}" STREQUAL "")
message(FATAL_ERROR "PROJECT_NAME should be empty")
endif()
set(AUTO_INCLUDE TRUE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment