prop_sf/OBJECT_NAME: support custom object names

Projects which ship object files as artifacts may want to control the
object names as much as possible. Support setting explicit object names
as source file properties to support such use cases.
This commit is contained in:
Ben Boeckel
2025-09-03 13:07:26 -04:00
parent 7aff0d37b5
commit 9ef99353cb
71 changed files with 489 additions and 18 deletions
+1
View File
@@ -584,6 +584,7 @@ Properties on Source Files
/prop_sf/LOCATION
/prop_sf/MACOSX_PACKAGE_LOCATION
/prop_sf/OBJECT_DEPENDS
/prop_sf/OBJECT_NAME
/prop_sf/OBJECT_OUTPUTS
/prop_sf/JOB_POOL_COMPILE
/prop_sf/SKIP_AUTOGEN
+26
View File
@@ -0,0 +1,26 @@
OBJECT_NAME
-----------
.. versionadded:: 4.2
Set the object name (without the object extension) of the source file. An
empty string value disables custom object naming. The value must be a relative
path, and may not include special directory components (e.g., ``..``).
Note that the object name may not be used as-is in
:variable:`CMAKE_INTERMEDIATE_DIR_STRATEGY` and
:prop_tgt:`INSTALL_OBJECT_NAME_STRATEGY` strategies, but instead changed as
the strategy requires to fulfill its goals.
This property supports
:manual:`generator expressions <cmake-generator-expressions(7)>`, but does not
allow for context-sensitive (i.e., configuration-dependent) expressions.
.. note::
No collision resistance within a target is performed by CMake. When using
this property, collisions must be avoided in the project code. CMake has a
number of source files it generates that also create object files that may
collide with a given custom name. These include:
* Generated PCH source files (``cmake_pch``)
* Generated Unity compilation files (``unity_``)
* Qt autogen sources (``moc_compilations.cpp``)
@@ -7,7 +7,8 @@ INSTALL_OBJECT_NAME_STRATEGY
specifying the strategy to use when naming installed object files. The
supported values are:
- ``FULL``: Object files are named after the associated source file.
- ``FULL``: Object files are named after the associated source file or
its :prop_sf:`OBJECT_NAME` property.
- ``SHORT``: Object files are named based on the hash of the source file name
to reduce path lengths.
@@ -0,0 +1,5 @@
object-name-properties
----------------------
* The :prop_sf:`OBJECT_NAME` source file property may be used to control
object names of source files.
@@ -10,7 +10,8 @@ supported values are:
- ``FULL``: Intermediate directories are named based on a
``<TARGET_NAME>.dir`` pattern (with some slight deviations and sanitizations
applied in various places). Object file names are based on the filename of
the source file being compiled.
the source file being compiled or, if set, its :prop_sf:`OBJECT_NAME`
property.
- ``SHORT``: Intermediate directories are named from the hash of the target
name and the build directory location. Object file names are based on hashes
of the source file name to reduce path lengths. This may help with projects
+100
View File
@@ -25,6 +25,7 @@
#include "cmsys/RegularExpression.hxx"
#include "cmAlgorithms.h"
#include "cmCMakePath.h"
#include "cmComputeLinkInformation.h"
#include "cmCryptoHash.h"
#include "cmCustomCommand.h"
@@ -4237,6 +4238,94 @@ std::string cmLocalGenerator::GetRelativeSourceFileName(
return objectName;
}
std::string cmLocalGenerator::GetCustomObjectFileName(
cmSourceFile const& source) const
{
if (!this->GetGlobalGenerator()->SupportsCustomObjectNames()) {
return std::string{};
}
if (auto objName = source.GetProperty("OBJECT_NAME")) {
cmGeneratorExpression ge(*this->GetCMakeInstance());
auto cge = ge.Parse(objName);
static std::string const INVALID_GENEX =
"_cmake_invalid_object_name_genex";
static std::string const INVALID_VALUE =
"_cmake_invalid_object_name_value";
if (!cge) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The \"OBJECT_NAME\" property for\n ", source.GetFullPath(),
"\nis not a valid generator expression (", objName, ")."));
return INVALID_GENEX;
}
if (cge->GetHadHeadSensitiveCondition()) {
// Not reachable; all target-sensitive genexes actually fail to parse.
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The \"OBJECT_NAME\" property for\n ", source.GetFullPath(),
"\ncontains a condition that queries the consuming target "
"which is not supported (",
objName, ")."));
return INVALID_GENEX;
}
if (cge->GetHadLinkLanguageSensitiveCondition()) {
// Not reachable; all target-sensitive genexes actually fail to parse.
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The \"OBJECT_NAME\" property for\n ", source.GetFullPath(),
"\ncontains a condition that queries the link language "
"which is not supported (",
objName, ")."));
return INVALID_GENEX;
}
auto objNameValue = cge->Evaluate(this, "");
if (cge->GetHadContextSensitiveCondition()) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The \"OBJECT_NAME\" property for\n ", source.GetFullPath(),
"\ncontains a context-sensitive condition which is not "
"supported (",
objName, ")."));
return INVALID_GENEX;
}
// Skip if it evaluates to empty.
if (!objNameValue.empty()) {
cmCMakePath objNamePath = objNameValue;
// Verify that it is a relative path.
if (objNamePath.IsAbsolute()) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(
"The \"OBJECT_NAME\" property for\n ", source.GetFullPath(),
"\nresolves to an absolute path which is not supported:\n ",
objNameValue));
return INVALID_VALUE;
}
auto isInvalidComponent = [](cmCMakePath const& component) -> bool {
return component == ".."_s;
};
// Verify that it contains no `..` components.
if (std::any_of(objNamePath.begin(), objNamePath.end(),
isInvalidComponent)) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The \"OBJECT_NAME\" property for\n ",
source.GetFullPath(), "\ncontains an invalid component (",
objNameValue, ")."));
return INVALID_VALUE;
}
return objNameValue;
}
}
return std::string{};
}
std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
cmSourceFile const& source, std::string const& dir_max,
bool* hasSourceExtension, char const* customOutputExtension,
@@ -4247,6 +4336,17 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
useShortObjectNames = *forceShortObjectName;
}
if (!useShortObjectNames) {
auto customName = this->GetCustomObjectFileName(source);
if (!customName.empty()) {
auto ext = this->GlobalGenerator->GetLanguageOutputExtension(source);
if (customOutputExtension) {
ext = *customOutputExtension;
}
return cmStrCat(customName, ext);
}
}
// This can return an absolute path in the case where source is
// not relative to the current source or binary directories
std::string objectName = this->GetRelativeSourceFileName(source);
+1
View File
@@ -452,6 +452,7 @@ public:
virtual std::string GetShortObjectFileName(cmSourceFile const& source) const;
virtual std::string ComputeShortTargetDirectory(
cmGeneratorTarget const* gt) const;
std::string GetCustomObjectFileName(cmSourceFile const& source) const;
/**
* Generate a macOS application bundle Info.plist file.
+20 -7
View File
@@ -60,10 +60,16 @@ void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
for (auto const& si : mapping) {
cmSourceFile const* sf = si.first;
std::string objectNameLower = cmStrCat(
cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())),
this->GlobalGenerator->GetLanguageOutputExtension(*sf));
std::string objectName;
auto customObjectName = this->GetCustomObjectFileName(*sf);
if (customObjectName.empty()) {
objectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
} else {
objectName = std::move(customObjectName);
}
objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
std::string objectNameLower = cmSystemTools::LowerCase(objectName);
counts[objectNameLower] += 1;
}
@@ -74,9 +80,16 @@ void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
bool forceShortObjectName = true;
std::string shortObjectName = this->GetObjectFileNameWithoutTarget(
*sf, dir_max, nullptr, nullptr, &forceShortObjectName);
std::string longObjectName = cmStrCat(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()),
this->GlobalGenerator->GetLanguageOutputExtension(*sf));
std::string longObjectName;
auto customObjectName = this->GetCustomObjectFileName(*sf);
if (customObjectName.empty()) {
longObjectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
} else {
longObjectName = std::move(customObjectName);
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
}
longObjectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
if (counts[cmSystemTools::LowerCase(longObjectName)] > 1) {
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
+16 -4
View File
@@ -55,8 +55,13 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
if (gt->GetUseShortObjectNames()) {
baseObjectName = this->GetShortObjectFileName(*sf);
} else {
baseObjectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
auto customObjectName = this->GetCustomObjectFileName(*sf);
if (customObjectName.empty()) {
baseObjectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
} else {
baseObjectName = std::move(customObjectName);
}
}
std::string objectNameLower = cmSystemTools::LowerCase(baseObjectName);
if (custom_ext) {
@@ -74,8 +79,15 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
std::string shortObjectName = this->GetShortObjectFileName(*sf);
std::string longObjectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
std::string longObjectName;
auto customObjectName = this->GetCustomObjectFileName(*sf);
if (customObjectName.empty()) {
longObjectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
} else {
longObjectName = std::move(customObjectName);
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
}
if (custom_ext) {
shortObjectName += custom_ext;
longObjectName += custom_ext;
+10 -5
View File
@@ -2721,16 +2721,21 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
this->WriteExcludeFromBuild(e2, exclude_configs);
}
std::string customObjectName;
if (this->GlobalGenerator->UseShortObjectNames()) {
customObjectName =
this->LocalGenerator->GetShortObjectFileName(*si.Source);
} else {
customObjectName =
this->LocalGenerator->GetCustomObjectFileName(*si.Source);
}
if (!customObjectName.empty()) {
std::string outputName = "ObjectFileName";
if (si.Source->GetLanguage() == "CUDA"_s) {
outputName = "CompileOut";
}
e2.Element(
outputName,
cmStrCat("$(IntDir)",
this->LocalGenerator->GetShortObjectFileName(*si.Source),
".obj"));
e2.Element(outputName,
cmStrCat("$(IntDir)", customObjectName, ".obj"));
}
this->FinishWritingSource(e2, toolSettings);
+1
View File
@@ -570,6 +570,7 @@ if(XCODE_VERSION)
set(ObjectLibrary_ARGS -DXCODE_VERSION=${XCODE_VERSION})
endif()
add_RunCMake_test(ObjectLibrary)
add_RunCMake_test(OBJECT_NAME)
add_RunCMake_test(ParseImplicitIncludeInfo)
add_RunCMake_test(ParseImplicitLinkInfo)
if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16)
project(${RunCMake_TEST} C)
include(${RunCMake_TEST}.cmake)
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
((Ninja)?multiple rules generate CMakeFiles/objlib.dir/objlib_lib.c.o)
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CollisionBuild.cmake")
@@ -0,0 +1 @@
(1|(Makefiles)?2)
@@ -0,0 +1 @@
((Ninja Multi-Config)?multiple rules generate CMakeFiles/objlib.dir/Debug/objlib_lib.c.o|(Makefiles)?((Linux)?undefined reference to `[fg]'|(macOS)?"?_[fg]"?, referenced from:|(Solaris)?[fg][ \t]*CMakeFiles/usefuncs.dir/test.c.o|(AIX)?Undefined symbol: \.[fg]|(FreeBSD)?undefined symbol: [fg])|(NMake Makefiles)?NMAKE : |(NMake Makefiles JOM)?jom: |(Watcom WMake)?Last command making \(usefuncs.exe\) returned a bad status|^$)
@@ -0,0 +1 @@
((NMake Makefiles)?unresolved external symbol [fg] referenced in function main|(Watcom WMake)?undefined symbol [fg]_|)
@@ -0,0 +1 @@
((Makefiles)?Warning: Source file "[^"]*/Tests/RunCMake/OBJECT_NAME/lib2?.c" is listed multiple times for target "objlib".|^$)
@@ -0,0 +1,7 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(objlib OBJECT lib.c lib2.c)
set_property(SOURCE lib.c lib2.c PROPERTY OBJECT_NAME "objlib_lib.c")
add_executable(usefuncs test.c)
target_link_libraries(usefuncs PRIVATE objlib)
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/Consume.cmake")
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/Consume.cmake")
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/Consume.cmake")
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/Consume.cmake")
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/Consume.cmake")
+7
View File
@@ -0,0 +1,7 @@
find_package(ON CONFIG REQUIRED)
add_executable(main main.c)
target_link_libraries(main PRIVATE ON::objlib)
enable_testing()
add_test(NAME run COMMAND main)
@@ -0,0 +1,5 @@
set(ext_suffix ".c")
if (RunCMake_GENERATOR MATCHES "(Visual Studio|Xcode)")
set(ext_suffix "")
endif ()
check_build_object(objlib "lib${ext_suffix}")
@@ -0,0 +1,5 @@
set(ext_suffix ".c")
if (RunCMake_GENERATOR MATCHES "(Visual Studio|Xcode)")
set(ext_suffix "")
endif ()
check_installed_object("${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/lib${ext_suffix}${CMAKE_C_OUTPUT_EXTENSION}")
@@ -0,0 +1,6 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<$<BOOL:0>:objlib_lib.c>")
install(TARGETS objlib EXPORT exp OBJECTS DESTINATION "lib/objlib")
install(EXPORT exp DESTINATION lib/cmake/ON FILE on-config.cmake NAMESPACE ON::)
@@ -0,0 +1 @@
check_build_object(exe exe_main.c)
@@ -0,0 +1,4 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_executable(exe main.c lib.c)
set_property(SOURCE main.c PROPERTY OBJECT_NAME "exe_main.c")
@@ -0,0 +1 @@
check_build_object(objlib 1/objlib_lib.c)
@@ -0,0 +1 @@
check_installed_object("${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/1/objlib_lib.c${CMAKE_C_OUTPUT_EXTENSION}")
@@ -0,0 +1,6 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<BOOL:ON>/objlib_lib.c")
install(TARGETS objlib EXPORT exp OBJECTS DESTINATION "lib/objlib")
install(EXPORT exp DESTINATION lib/cmake/ON FILE on-config.cmake NAMESPACE ON::)
+10
View File
@@ -0,0 +1,10 @@
enable_language(C)
set(info "")
# Forward information about the C++ compile features.
string(APPEND info "\
set(CMAKE_C_OUTPUT_EXTENSION \"${CMAKE_C_OUTPUT_EXTENSION}\")
")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}")
@@ -0,0 +1 @@
1
@@ -0,0 +1,9 @@
CMake Error:
Error evaluating generator expression:
\$<invalid>
Expression did not evaluate to a known generator expression
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<invalid>")
@@ -0,0 +1 @@
1
@@ -0,0 +1,11 @@
CMake Error in CMakeLists.txt:
The "OBJECT_NAME" property for
.*/Tests/RunCMake/OBJECT_NAME/lib.c
resolves to an absolute path which is not supported:
.*/Tests/RunCMake/OBJECT_NAME/NoAbsolute-build/lib.c
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(static STATIC lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "${CMAKE_BINARY_DIR}/lib.c")
@@ -0,0 +1 @@
1
@@ -0,0 +1,9 @@
CMake Error in CMakeLists.txt:
The "OBJECT_NAME" property for
.*/Tests/RunCMake/OBJECT_NAME/lib.c
contains an invalid component \(subdir/\.\./sibling/lib.c\).
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(static STATIC lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "subdir/../sibling/lib.c")
@@ -0,0 +1 @@
check_build_object(objlib objlib_lib.c)
@@ -0,0 +1 @@
check_installed_object("${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/objlib_lib.c${CMAKE_C_OUTPUT_EXTENSION}")
@@ -0,0 +1,6 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "objlib_lib.c")
install(TARGETS objlib EXPORT exp OBJECTS DESTINATION "lib/objlib")
install(EXPORT exp DESTINATION lib/cmake/ON FILE on-config.cmake NAMESPACE ON::)
@@ -0,0 +1,103 @@
cmake_minimum_required(VERSION 3.16)
include(RunCMake)
# This test does installation of `OBJECT` libraries which does not work with
# multi-arch compilation under Xcode.
if (RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]")
return ()
endif ()
function(run_build_test case)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE:STRING=Debug)
run_cmake(${case})
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug)
endfunction()
function(run_install_test case)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/fake_install")
run_cmake(${case})
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug)
set(prefix "${RunCMake_TEST_BINARY_DIR}/real_install")
run_cmake_command(${case}-install ${CMAKE_COMMAND} --install . --config Debug --prefix "${prefix}")
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Consume-${case}-build)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_PREFIX_PATH:PATH=${prefix}")
run_cmake(Consume-${case} "-DCMAKE_PREFIX_PATH=${prefix}")
run_cmake_command(Consume-${case}-build ${CMAKE_COMMAND} --build . --config Debug)
run_cmake_command(Consume-${case}-test ${CMAKE_CTEST_COMMAND} -C Debug)
endfunction()
function (check_build_object target objname)
set(cmf_subdir "CMakeFiles/")
set(config_subdir "")
if (RunCMake_GENERATOR MATCHES "Visual Studio")
set(cmf_subdir "")
endif ()
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(config_subdir "Debug/")
endif ()
set(path "${RunCMake_TEST_BINARY_DIR}/${cmf_subdir}${target}.dir/${config_subdir}${objname}${CMAKE_C_OUTPUT_EXTENSION}")
if (NOT EXISTS "${path}")
list(APPEND RunCMake_TEST_FAILED
"Could not find built object at '${path}'")
endif ()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endfunction ()
function (check_short_build_object target objname)
set(config_subdir "")
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(config_subdir "Debug/")
endif ()
set(obj_subdir ".o")
if (RunCMake_GENERATOR MATCHES "(Borland Makefiles|Watcom WMake)")
set(obj_subdir "_o")
endif ()
set(path "${RunCMake_TEST_BINARY_DIR}/${obj_subdir}/${target}/${config_subdir}${objname}${CMAKE_C_OUTPUT_EXTENSION}")
if (NOT EXISTS "${path}")
list(APPEND RunCMake_TEST_FAILED
"Could not find built object at '${path}'")
endif ()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endfunction ()
function (check_installed_object path)
if (NOT EXISTS "${path}")
list(APPEND RunCMake_TEST_FAILED
"Could not find installed object at '${path}'")
endif ()
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endfunction ()
run_cmake(Inspect)
include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake")
run_build_test(Executable)
run_build_test(SharedLibrary)
run_build_test(StaticLibrary)
if (RunCMake_GENERATOR STREQUAL "Ninja")
run_cmake(Collision)
else ()
run_build_test(CollisionBuild)
endif ()
run_cmake(NoAbsolute)
run_cmake(NoDotDot)
run_cmake(InvalidGeneratorExpression)
run_cmake(UnsupportedGeneratorExpressionContextSensitive)
run_cmake(UnsupportedGeneratorExpressionHeadTarget)
run_cmake(UnsupportedGeneratorExpressionLinkLanguage)
run_install_test(ObjectLibrary)
run_install_test(DisableOnEmpty)
if (RunCMake_GENERATOR MATCHES "(Ninja|Makefiles|Visual Studio)")
run_install_test(ShortStrategy)
run_install_test(ShortInstallStrategy)
endif ()
run_install_test(GeneratorExpression)
@@ -0,0 +1 @@
check_build_object(sharedlib sharedlib_lib.c)
@@ -0,0 +1,4 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(sharedlib SHARED lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "sharedlib_lib.c")
@@ -0,0 +1 @@
check_build_object(objlib objlib_lib.c)
@@ -0,0 +1 @@
check_installed_object("${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/d33a1361${CMAKE_C_OUTPUT_EXTENSION}")
@@ -0,0 +1,6 @@
set(CMAKE_INSTALL_OBJECT_NAME_STRATEGY SHORT)
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "objlib_lib.c")
install(TARGETS objlib EXPORT exp OBJECTS DESTINATION "lib/objlib")
install(EXPORT exp DESTINATION lib/cmake/ON FILE on-config.cmake NAMESPACE ON::)
@@ -0,0 +1 @@
check_short_build_object(fbbbd702 d33a1361)
@@ -0,0 +1 @@
check_installed_object("${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/objlib_lib.c${CMAKE_C_OUTPUT_EXTENSION}")
@@ -0,0 +1,6 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY SHORT CACHE STRING "" FORCE)
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "objlib_lib.c")
install(TARGETS objlib EXPORT exp OBJECTS DESTINATION "lib/objlib")
install(EXPORT exp DESTINATION lib/cmake/ON FILE on-config.cmake NAMESPACE ON::)
@@ -0,0 +1 @@
check_build_object(staticlib staticlib_lib.c)
@@ -0,0 +1,4 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
add_library(staticlib STATIC lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "staticlib_lib.c")
@@ -0,0 +1,10 @@
CMake Error in CMakeLists.txt:
The "OBJECT_NAME" property for
.*/Tests/RunCMake/OBJECT_NAME/lib.c
contains a context-sensitive condition which is not supported
\(\$<CONFIG>/objlib_lib.c\).
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<CONFIG>/objlib_lib.c")
@@ -0,0 +1,12 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:foo>
\$<TARGET_PROPERTY:prop> may only be used with binary targets. It may not
be used with add_custom_command or add_custom_target. Specify the target
to read a property from using the \$<TARGET_PROPERTY:tgt,prop> signature
instead.
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<TARGET_PROPERTY:foo>/objlib_lib.c")
@@ -0,0 +1,10 @@
CMake Error:
Error evaluating generator expression:
\$<LINK_LANGUAGE>
\$<LINK_LANGUAGE:...> may only be used with binary targets to specify link
libraries, link directories, link options and link depends.
CMake Generate step failed. Build files cannot be regenerated correctly.
@@ -0,0 +1,2 @@
add_library(objlib OBJECT lib.c)
set_property(SOURCE lib.c PROPERTY OBJECT_NAME "$<LINK_LANGUAGE>/objlib_lib.c")
+4
View File
@@ -0,0 +1,4 @@
int f(int a)
{
return a;
}
+4
View File
@@ -0,0 +1,4 @@
int g(int a)
{
return a;
}
+6
View File
@@ -0,0 +1,6 @@
int f(int a);
int main(void)
{
return f(0);
}
+7
View File
@@ -0,0 +1,7 @@
int f(int);
int g(int);
int main(void)
{
return f(0) + g(0);
}