CPS: Support importing executables

Fixes: #27964
This commit is contained in:
Vito Gamberini
2026-07-22 10:45:59 -04:00
parent 177047cb42
commit 207c132378
16 changed files with 114 additions and 12 deletions
@@ -0,0 +1,4 @@
cps-import-executable
---------------------
* CPS import now supports `executable` components.
+5 -3
View File
@@ -869,7 +869,7 @@ void cmPackageInfoReader::ReadCxxModulesMetadata(
#endif
}
cmTarget* cmPackageInfoReader::AddLibraryComponent(
cmTarget* cmPackageInfoReader::AddComponent(
cmMakefile* makefile, cm::TargetType type, std::string const& name,
Json::Value const& data, std::string const& package,
cm::ImportedTargetScope scope) const
@@ -959,14 +959,16 @@ bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
}
auto createTarget = [&](cm::TargetType typeEnum) {
return this->AddLibraryComponent(makefile, typeEnum, fullName, *ci,
package, scope);
return this->AddComponent(makefile, typeEnum, fullName, *ci, package,
scope);
};
cmTarget* target = nullptr;
if (type == "symbolic"_s) {
target = createTarget(cm::TargetType::INTERFACE_LIBRARY);
target->SetSymbolic(true);
} else if (type == "executable"_s) {
target = createTarget(cm::TargetType::EXECUTABLE);
} else if (type == "dylib"_s) {
target = createTarget(cm::TargetType::SHARED_LIBRARY);
} else if (type == "module"_s) {
+4 -5
View File
@@ -90,11 +90,10 @@ public:
private:
cmPackageInfoReader() = default;
cmTarget* AddLibraryComponent(cmMakefile* makefile, cm::TargetType type,
std::string const& name,
Json::Value const& data,
std::string const& package,
cm::ImportedTargetScope scope) const;
cmTarget* AddComponent(cmMakefile* makefile, cm::TargetType type,
std::string const& name, Json::Value const& data,
std::string const& package,
cm::ImportedTargetScope scope) const;
void AddTargetConfiguration(cmTarget* target,
cm::string_view configuration) const;
+8
View File
@@ -169,17 +169,25 @@ elseif(NOT TARGET Foo::PrefixTest)
message(SEND_ERROR "Foo::PrefixTest missing !")
elseif(NOT TARGET Foo::RelativeTest)
message(SEND_ERROR "Foo::RelativeTest missing !")
elseif(NOT TARGET Foo::ExecutableTest)
message(SEND_ERROR "Foo::ExecutableTest missing !")
elseif(NOT TARGET Foo::Empty)
message(SEND_ERROR "Foo::Empty missing !")
else()
expect_property(Foo::PrefixTest TYPE "type" "INTERFACE_LIBRARY")
expect_property(
Foo::PrefixTest INTERFACE_INCLUDE_DIRECTORIES "includes"
"$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/include>")
expect_property(Foo::RelativeTest TYPE "type" "INTERFACE_LIBRARY")
expect_property(
Foo::RelativeTest INTERFACE_INCLUDE_DIRECTORIES "includes"
"$<$<CONFIG:default>:${CMAKE_CURRENT_SOURCE_DIR}/cps/../include>")
expect_property(Foo::ExecutableTest TYPE "type" "EXECUTABLE")
expect_property(Foo::ExecutableTest IMPORTED_LOCATION_DEFAULT "location"
"${CMAKE_CURRENT_SOURCE_DIR}/foo")
expect_global(Foo::Empty FALSE)
endif()
+3
View File
@@ -9,6 +9,9 @@
},
"Empty": {
"type": "interface"
},
"ExecutableTest": {
"type": "executable"
}
}
}
@@ -5,6 +5,9 @@
"components": {
"PrefixTest": {
"includes": ["@prefix@/include"]
},
"ExecutableTest": {
"location": "@prefix@/foo"
}
}
}
@@ -14,4 +14,5 @@ function(build_project test)
endfunction()
build_project(TestLibrary)
build_project(TestTool)
build_project(TestExecutable)
@@ -2,10 +2,18 @@ project(TestLibrary C)
set(liba_DIR "${CMAKE_BINARY_DIR}/../TestLibrary-build/cps/liba")
set(libb_DIR "${CMAKE_BINARY_DIR}/../TestLibrary-build/cps/libb")
set(tool_DIR "${CMAKE_BINARY_DIR}/../TestTool-build/cps/tool")
find_package(libb REQUIRED COMPONENTS libb)
find_package(tool REQUIRED COMPONENTS tool)
add_executable(app app.c)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen.c"
COMMAND tool::tool "${CMAKE_CURRENT_BINARY_DIR}/gen.c"
VERBATIM
)
add_executable(app app.c "${CMAKE_CURRENT_BINARY_DIR}/gen.c")
target_link_libraries(app PUBLIC libb::libb)
@@ -0,0 +1,6 @@
project(TestTool C)
add_executable(tool tool.c)
install(TARGETS tool EXPORT tool)
export(PACKAGE_INFO tool EXPORT tool)
+3 -1
View File
@@ -1,8 +1,10 @@
#include <libb.h>
#include <stdio.h>
extern int gen(void);
int main(void)
{
printf("%i\n", ask());
printf("%i\n", ask() + gen());
return 0;
}
@@ -0,0 +1,24 @@
#ifndef _CRT_SECURE_NO_DEPRECATE
# define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
int main(int argc, char* argv[])
{
FILE* out;
if (argc < 2) {
return 1;
}
out = fopen(argv[1], "w");
if (!out) {
return 1;
}
fprintf(out, "int gen(void)\n{\n return 42;\n}\n");
fclose(out);
return 0;
}
@@ -15,4 +15,5 @@ function(build_project test)
endfunction()
build_project(TestLibrary)
build_project(TestTool)
build_project(TestExecutable)
@@ -4,8 +4,15 @@ set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/../install")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/../install")
find_package(libb REQUIRED COMPONENTS libb)
find_package(tool REQUIRED COMPONENTS tool)
add_executable(app app.c)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen.c"
COMMAND tool::tool "${CMAKE_CURRENT_BINARY_DIR}/gen.c"
VERBATIM
)
add_executable(app app.c "${CMAKE_CURRENT_BINARY_DIR}/gen.c")
target_link_libraries(app PUBLIC libb::libb)
@@ -0,0 +1,8 @@
project(TestTool C)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/../install")
add_executable(tool tool.c)
install(TARGETS tool EXPORT tool)
install(PACKAGE_INFO tool DESTINATION cps EXPORT tool)
+3 -1
View File
@@ -1,8 +1,10 @@
#include <libb.h>
#include <stdio.h>
extern int gen(void);
int main(void)
{
printf("%i\n", ask());
printf("%i\n", ask() + gen());
return 0;
}
@@ -0,0 +1,24 @@
#ifndef _CRT_SECURE_NO_DEPRECATE
# define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
int main(int argc, char* argv[])
{
FILE* out;
if (argc < 2) {
return 1;
}
out = fopen(argv[1], "w");
if (!out) {
return 1;
}
fprintf(out, "int gen(void)\n{\n return 42;\n}\n");
fclose(out);
return 0;
}