Genex: Add $<BUILD_LOCAL_INTERFACE:...> genex

Fixes: #23209
This commit is contained in:
Kyle Edwards
2022-11-15 15:24:13 -05:00
parent 37b5c78688
commit 38cbf5e15b
10 changed files with 97 additions and 1 deletions
@@ -1704,6 +1704,13 @@ Export And Install Expressions
when the target is used by another target in the same buildsystem. Expands to when the target is used by another target in the same buildsystem. Expands to
the empty string otherwise. the empty string otherwise.
.. genex:: $<BUILD_LOCAL_INTERFACE:...>
.. versionadded:: 3.26
Content of ``...`` when the target is used by another target in the same
buildsystem. Expands to the empty string otherwise.
.. genex:: $<INSTALL_PREFIX> .. genex:: $<INSTALL_PREFIX>
Content of the install prefix when the target is exported via Content of the install prefix when the target is exported via
@@ -0,0 +1,5 @@
build-local-interface-genex
---------------------------
* The :genex:`BUILD_LOCAL_INTERFACE` generator expression was added to
prevent usage requirements from being exported to dependent projects.
+10 -1
View File
@@ -227,8 +227,10 @@ static std::string stripExportInterface(
while (true) { while (true) {
std::string::size_type bPos = input.find("$<BUILD_INTERFACE:", lastPos); std::string::size_type bPos = input.find("$<BUILD_INTERFACE:", lastPos);
std::string::size_type iPos = input.find("$<INSTALL_INTERFACE:", lastPos); std::string::size_type iPos = input.find("$<INSTALL_INTERFACE:", lastPos);
std::string::size_type lPos =
input.find("$<BUILD_LOCAL_INTERFACE:", lastPos);
pos = std::min({ bPos, iPos }); pos = std::min({ bPos, iPos, lPos });
if (pos == std::string::npos) { if (pos == std::string::npos) {
break; break;
} }
@@ -238,6 +240,7 @@ static std::string stripExportInterface(
{ {
BuildInterface, BuildInterface,
InstallInterface, InstallInterface,
BuildLocalInterface,
} foundGenex = FoundGenex::BuildInterface; } foundGenex = FoundGenex::BuildInterface;
if (pos == bPos) { if (pos == bPos) {
foundGenex = FoundGenex::BuildInterface; foundGenex = FoundGenex::BuildInterface;
@@ -245,6 +248,9 @@ static std::string stripExportInterface(
} else if (pos == iPos) { } else if (pos == iPos) {
foundGenex = FoundGenex::InstallInterface; foundGenex = FoundGenex::InstallInterface;
pos += cmStrLen("$<INSTALL_INTERFACE:"); pos += cmStrLen("$<INSTALL_INTERFACE:");
} else if (pos == lPos) {
foundGenex = FoundGenex::BuildLocalInterface;
pos += cmStrLen("$<BUILD_LOCAL_INTERFACE:");
} else { } else {
assert(false && "Invalid position found"); assert(false && "Invalid position found");
} }
@@ -287,6 +293,9 @@ static std::string stripExportInterface(
case FoundGenex::InstallInterface: case FoundGenex::InstallInterface:
result = cmStrCat(result, "$<INSTALL_INTERFACE:", remaining); result = cmStrCat(result, "$<INSTALL_INTERFACE:", remaining);
break; break;
case FoundGenex::BuildLocalInterface:
result = cmStrCat(result, "$<BUILD_LOCAL_INTERFACE:", remaining);
break;
} }
} }
pos += traversed; pos += traversed;
+3
View File
@@ -114,6 +114,8 @@ static const struct OneNode buildInterfaceNode;
static const struct ZeroNode installInterfaceNode; static const struct ZeroNode installInterfaceNode;
static const struct OneNode buildLocalInterfaceNode;
struct BooleanOpNode : public cmGeneratorExpressionNode struct BooleanOpNode : public cmGeneratorExpressionNode
{ {
BooleanOpNode(const char* op_, const char* successVal_, BooleanOpNode(const char* op_, const char* successVal_,
@@ -3320,6 +3322,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
{ "GENEX_EVAL", &genexEvalNode }, { "GENEX_EVAL", &genexEvalNode },
{ "BUILD_INTERFACE", &buildInterfaceNode }, { "BUILD_INTERFACE", &buildInterfaceNode },
{ "INSTALL_INTERFACE", &installInterfaceNode }, { "INSTALL_INTERFACE", &installInterfaceNode },
{ "BUILD_LOCAL_INTERFACE", &buildLocalInterfaceNode },
{ "INSTALL_PREFIX", &installPrefixNode }, { "INSTALL_PREFIX", &installPrefixNode },
{ "JOIN", &joinNode }, { "JOIN", &joinNode },
{ "LINK_ONLY", &linkOnlyNode }, { "LINK_ONLY", &linkOnlyNode },
@@ -0,0 +1,14 @@
enable_language(C)
add_library(mainlib STATIC foo.c)
target_compile_definitions(mainlib INTERFACE
$<BUILD_LOCAL_INTERFACE:BUILD_LOCAL_INTERFACE>
$<BUILD_INTERFACE:BUILD_INTERFACE>
$<INSTALL_INTERFACE:INSTALL_INTERFACE>
)
add_library(locallib STATIC locallib.c)
target_link_libraries(locallib PRIVATE mainlib)
install(TARGETS mainlib EXPORT export)
install(EXPORT export DESTINATION lib/cmake/install FILE install-config.cmake NAMESPACE install::)
export(EXPORT export FILE build-config.cmake NAMESPACE build::)
@@ -0,0 +1,9 @@
enable_language(C)
find_package(build REQUIRED)
find_package(install REQUIRED)
add_library(buildlib STATIC buildlib.c)
target_link_libraries(buildlib PRIVATE build::mainlib)
add_library(installlib STATIC installlib.c)
target_link_libraries(installlib PRIVATE install::mainlib)
@@ -22,3 +22,28 @@ function(run_ExportImport_test case)
endfunction() endfunction()
run_ExportImport_test(SharedDep) run_ExportImport_test(SharedDep)
function(run_ExportImportBuildInstall_test case)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-export-build)
set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root)
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${case}-export)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${case}-export-build ${CMAKE_COMMAND} --build . --config Debug)
run_cmake_command(${case}-export-install ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -P cmake_install.cmake)
unset(RunCMake_TEST_NO_CLEAN)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-import-build)
run_cmake_with_options(${case}-import
-Dbuild_DIR=${RunCMake_BINARY_DIR}/${case}-export-build
-Dinstall_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/install
)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${case}-import-build ${CMAKE_COMMAND} --build . --config Debug)
unset(RunCMake_TEST_NO_CLEAN)
endfunction()
run_ExportImportBuildInstall_test(BuildInstallInterfaceGenex)
+8
View File
@@ -0,0 +1,8 @@
#if !(!defined(BUILD_LOCAL_INTERFACE) && defined(BUILD_INTERFACE) && \
!defined(INSTALL_INTERFACE))
# error "Incorrect compile definitions"
#endif
void buildlib(void)
{
}
+8
View File
@@ -0,0 +1,8 @@
#if !(!defined(BUILD_LOCAL_INTERFACE) && !defined(BUILD_INTERFACE) && \
defined(INSTALL_INTERFACE))
# error "Incorrect compile definitions"
#endif
void installlib(void)
{
}
+8
View File
@@ -0,0 +1,8 @@
#if !(defined(BUILD_LOCAL_INTERFACE) && defined(BUILD_INTERFACE) && \
!defined(INSTALL_INTERFACE))
# error "Incorrect compile definitions"
#endif
void locallib(void)
{
}