mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-25 01:28:50 -05:00
Merge topic 'vs-global-props-for-all-targets'
36489b85aaVS: Add test for CMAKE_VS_GLOBALS22e670a306VS: Add option to set VS_GLOBAL_* for all targets Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2345
This commit is contained in:
@@ -395,6 +395,7 @@ Variables that Control the Build
|
||||
/variable/CMAKE_TRY_COMPILE_TARGET_TYPE
|
||||
/variable/CMAKE_USE_RELATIVE_PATHS
|
||||
/variable/CMAKE_VISIBILITY_INLINES_HIDDEN
|
||||
/variable/CMAKE_VS_GLOBALS
|
||||
/variable/CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD
|
||||
/variable/CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD
|
||||
/variable/CMAKE_VS_SDK_EXCLUDE_DIRECTORIES
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
vs-global-props-for-all-targets
|
||||
-------------------------------
|
||||
|
||||
* A :variable:`CMAKE_VS_GLOBALS` variable was added to initialize
|
||||
:prop_tgt:`VS_GLOBAL_<variable>` target properties on targets as
|
||||
they are created.
|
||||
@@ -0,0 +1,21 @@
|
||||
CMAKE_VS_GLOBALS
|
||||
----------------
|
||||
|
||||
List of ``Key=Value`` records to be set per target as target properties
|
||||
:prop_tgt:`VS_GLOBAL_<variable>` with ``variable=Key`` and value ``Value``.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set(CMAKE_VS_GLOBALS
|
||||
"DefaultLanguage=en-US"
|
||||
"MinimumVisualStudioVersion=14.0"
|
||||
)
|
||||
|
||||
will set properties ``VS_GLOBAL_DefaultLanguage`` to ``en-US`` and
|
||||
``VS_GLOBAL_MinimumVisualStudioVersion`` to ``14.0`` for all targets
|
||||
(except for ``INTERFACE`` libraries).
|
||||
|
||||
This variable is meant to be set by a
|
||||
:variable:`toolchain file <CMAKE_TOOLCHAIN_FILE>`.
|
||||
@@ -454,6 +454,31 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
|
||||
if (this->TargetTypeValue <= cmStateEnums::UTILITY) {
|
||||
this->SetPropertyDefault("DOTNET_TARGET_FRAMEWORK_VERSION", nullptr);
|
||||
}
|
||||
|
||||
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
|
||||
this->GetType() != cmStateEnums::UTILITY) {
|
||||
|
||||
// check for "CMAKE_VS_GLOBALS" variable and set up target properties
|
||||
// if any
|
||||
const char* globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
|
||||
if (globals) {
|
||||
const std::string genName = mf->GetGlobalGenerator()->GetName();
|
||||
if (cmHasLiteralPrefix(genName, "Visual Studio")) {
|
||||
std::vector<std::string> props;
|
||||
cmSystemTools::ExpandListArgument(globals, props);
|
||||
const std::string vsGlobal = "VS_GLOBAL_";
|
||||
for (const std::string& i : props) {
|
||||
// split NAME=VALUE
|
||||
const std::string::size_type assignment = i.find('=');
|
||||
if (assignment != std::string::npos) {
|
||||
const std::string propName = vsGlobal + i.substr(0, assignment);
|
||||
const std::string propValue = i.substr(assignment + 1);
|
||||
this->SetPropertyDefault(propName, propValue.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
|
||||
|
||||
@@ -13,3 +13,4 @@ run_cmake(VsCSharpCustomTags)
|
||||
run_cmake(VsCSharpReferenceProps)
|
||||
run_cmake(VsCSharpWithoutSources)
|
||||
run_cmake(VsSdkDirectories)
|
||||
run_cmake(VsGlobals)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
|
||||
if(NOT EXISTS "${vcProjectFile}")
|
||||
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(InsideGlobals FALSE)
|
||||
set(DefaultLanguageSet FALSE)
|
||||
set(MinimumVisualStudioVersionSet FALSE)
|
||||
|
||||
file(STRINGS "${vcProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<PropertyGroup Label=\"Globals\"> *$")
|
||||
set(InsideGlobals TRUE)
|
||||
elseif(line MATCHES "^ *<DefaultLanguage>([a-zA-Z\\-]+)</DefaultLanguage> *$")
|
||||
if("${CMAKE_MATCH_1}" STREQUAL "en-US")
|
||||
if(InsideGlobals)
|
||||
message(STATUS "foo.vcxproj has correct DefaultLanguage global property")
|
||||
set(DefaultLanguageSet TRUE)
|
||||
else()
|
||||
message(STATUS "DefaultLanguage is set but not within \"Globals\" property group")
|
||||
endif()
|
||||
endif()
|
||||
elseif(line MATCHES "^ *<MinimumVisualStudioVersion>([0-9\\.]+)</MinimumVisualStudioVersion> *$")
|
||||
if("${CMAKE_MATCH_1}" STREQUAL "14.0")
|
||||
if(InsideGlobals)
|
||||
message(STATUS "foo.vcxproj has correct MinimumVisualStudioVersion global property")
|
||||
set(MinimumVisualStudioVersionSet TRUE)
|
||||
else()
|
||||
message(STATUS "MinimumVisualStudioVersion is set but not within \"Globals\" property group")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT DefaultLanguageSet)
|
||||
set(RunCMake_TEST_FAILED "DefaultLanguageSet not found or not set correctly.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT MinimumVisualStudioVersionSet)
|
||||
set(RunCMake_TEST_FAILED "MinimumVisualStudioVersionSet not found or not set correctly.")
|
||||
return()
|
||||
endif()
|
||||
@@ -0,0 +1,8 @@
|
||||
enable_language(CXX)
|
||||
|
||||
set(CMAKE_VS_GLOBALS
|
||||
"DefaultLanguage=en-US"
|
||||
"MinimumVisualStudioVersion=14.0"
|
||||
)
|
||||
|
||||
add_library(foo foo.cpp)
|
||||
Reference in New Issue
Block a user