Add EXPORT_NO_SYSTEM target property, deprecate IMPORTED_NO_SYSTEM

Issue: #18040

Signed-off-by: Da Quexian <daquexian566@gmail.com>
This commit is contained in:
Da Quexian
2022-06-17 14:41:54 +08:00
parent 467d0e01f8
commit 9680b3b279
7 changed files with 55 additions and 3 deletions

View File

@@ -202,6 +202,7 @@ Properties on Targets
/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG
/prop_tgt/EXPORT_COMPILE_COMMANDS
/prop_tgt/EXPORT_NAME
/prop_tgt/EXPORT_NO_SYSTEM
/prop_tgt/EXPORT_PROPERTIES
/prop_tgt/FOLDER
/prop_tgt/Fortran_BUILDING_INSTRINSIC_MODULES

View File

@@ -0,0 +1,11 @@
EXPORT_NO_SYSTEM
----------------
.. versionadded:: 3.25
Specifies that :command:`install(EXPORT)` and :command:`export` commands will
generate a imported target with :prop_tgt:`SYSTEM` property `OFF`.
See the :prop_tgt:`NO_SYSTEM_FROM_IMPORTED` target property to set this
behavior on the target consuming the include directories rather than
providing them.

View File

@@ -3,6 +3,15 @@ IMPORTED_NO_SYSTEM
.. versionadded:: 3.23
.. deprecated:: 3.25
``IMPORTED_NO_SYSTEM`` is deprecated. Set :prop_tgt:`SYSTEM` to `OFF`
instead if you don't want target's include directories to be ``SYSTEM``
when compiling consumers. Set :prop_tgt:`EXPORT_NO_SYSTEM` to `ON` instead
if you don't want the include directories of the imported target generated
by :command:`install(EXPORT)` and :command:`export` commands to be
``SYSTEM`` when compiling consumers.
Specifies that an :ref:`Imported Target <Imported Targets>` is not
a ``SYSTEM`` library. This has the following effects:

View File

@@ -5,3 +5,11 @@ system
that a target should be treated as a system library (i.e.
its include directories are automatically ``SYSTEM`` when
compiling consumers).
* The :prop_tgt:`EXPORT_NO_SYSTEM` target property was added to
specify that :command:`install(EXPORT)` and :command:`export`
commands will generate a imported target with
:prop_tgt:`SYSTEM` property `OFF`.
* The :prop_tgt:`IMPORTED_NO_SYSTEM` target property was deprecated
in favor of :prop_tgt:`SYSTEM` and :prop_tgt:`EXPORT_NO_SYSTEM`.

View File

@@ -1088,6 +1088,10 @@ void cmExportFileGenerator::GenerateImportTargetCode(
<< " PROPERTY IMPORTED_NO_SYSTEM 1)\n";
}
if (target->GetPropertyAsBool("EXPORT_NO_SYSTEM")) {
os << "set_property(TARGET " << targetName << " PROPERTY SYSTEM 0)\n";
}
os << "\n";
}

View File

@@ -155,6 +155,15 @@ target_include_directories(testInterfaceIncludeUser
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/testInterfaceIncludeUser>"
)
set_property(TARGET testInterfaceIncludeUser PROPERTY IMPORTED_NO_SYSTEM 1)
add_library(testInterfaceIncludeUser2 INTERFACE)
target_include_directories(testInterfaceIncludeUser2
INTERFACE
"$<INSTALL_INTERFACE:include/testInterfaceIncludeUser>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/testInterfaceIncludeUser>"
)
set_property(TARGET testInterfaceIncludeUser2 PROPERTY EXPORT_NO_SYSTEM 1)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/include/testInterfaceIncludeUser/testInterfaceInclude.h"
@@ -562,6 +571,7 @@ install(
TopDirLib SubDirLinkA
systemlib
testInterfaceIncludeUser
testInterfaceIncludeUser2
EXPORT exp
RUNTIME DESTINATION $<1:bin>$<0:/wrong>
LIBRARY DESTINATION $<1:lib>$<0:/wrong> NAMELINK_SKIP
@@ -622,6 +632,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3
TopDirLib SubDirLinkA
systemlib
testInterfaceIncludeUser
testInterfaceIncludeUser2
NAMESPACE bld_
FILE ExportBuildTree.cmake
)

View File

@@ -75,6 +75,10 @@ add_library(imp_testInterfaceInclude1 STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1 SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1 PRIVATE exp_testInterfaceIncludeUser)
add_library(imp_testInterfaceInclude1b STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1b SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1b PRIVATE exp_testInterfaceIncludeUser2)
add_executable(imp_UseSharedLibWithHelper1 ../../../InterfaceLinkLibrariesDirect/UseSharedLibWithHelper.c)
target_link_libraries(imp_UseSharedLibWithHelper1 PRIVATE exp_testSharedLibWithHelper testSharedLibHelperExclude)
@@ -122,9 +126,13 @@ target_link_libraries(imp_testExe1b
bld_testStaticLibWithPlugin
)
add_library(imp_testInterfaceInclude1b STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1b SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1b PRIVATE bld_testInterfaceIncludeUser)
add_library(imp_testInterfaceInclude1c STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1c SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1c PRIVATE bld_testInterfaceIncludeUser)
add_library(imp_testInterfaceInclude1d STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1d SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1d PRIVATE bld_testInterfaceIncludeUser2)
add_custom_target(check_testLib1_genex ALL
COMMAND ${CMAKE_COMMAND} -DtestLib1=$<TARGET_FILE:exp_testLib1>