diff --git a/Help/release/dev/cps-import-executable.rst b/Help/release/dev/cps-import-executable.rst new file mode 100644 index 0000000000..b13e6184e9 --- /dev/null +++ b/Help/release/dev/cps-import-executable.rst @@ -0,0 +1,4 @@ +cps-import-executable +--------------------- + +* CPS import now supports `executable` components. diff --git a/Source/cmPackageInfoReader.cxx b/Source/cmPackageInfoReader.cxx index 27ae441aca..a51eafa159 100644 --- a/Source/cmPackageInfoReader.cxx +++ b/Source/cmPackageInfoReader.cxx @@ -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) { diff --git a/Source/cmPackageInfoReader.h b/Source/cmPackageInfoReader.h index 0228d4d984..c66ad82e5d 100644 --- a/Source/cmPackageInfoReader.h +++ b/Source/cmPackageInfoReader.h @@ -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; diff --git a/Tests/FindPackageCpsTest/CMakeLists.txt b/Tests/FindPackageCpsTest/CMakeLists.txt index 380e108400..94f959cc6c 100644 --- a/Tests/FindPackageCpsTest/CMakeLists.txt +++ b/Tests/FindPackageCpsTest/CMakeLists.txt @@ -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" "$<$:${CMAKE_CURRENT_SOURCE_DIR}/include>") + expect_property(Foo::RelativeTest TYPE "type" "INTERFACE_LIBRARY") expect_property( Foo::RelativeTest INTERFACE_INCLUDE_DIRECTORIES "includes" "$<$:${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() diff --git a/Tests/FindPackageCpsTest/cps/foo.cps b/Tests/FindPackageCpsTest/cps/foo.cps index 0475a9fb8f..7c93e1fb2b 100644 --- a/Tests/FindPackageCpsTest/cps/foo.cps +++ b/Tests/FindPackageCpsTest/cps/foo.cps @@ -9,6 +9,9 @@ }, "Empty": { "type": "interface" + }, + "ExecutableTest": { + "type": "executable" } } } diff --git a/Tests/FindPackageCpsTest/cps/foo@default.cps b/Tests/FindPackageCpsTest/cps/foo@default.cps index a5b4147135..ee5c8204b2 100644 --- a/Tests/FindPackageCpsTest/cps/foo@default.cps +++ b/Tests/FindPackageCpsTest/cps/foo@default.cps @@ -5,6 +5,9 @@ "components": { "PrefixTest": { "includes": ["@prefix@/include"] + }, + "ExecutableTest": { + "location": "@prefix@/foo" } } } diff --git a/Tests/RunCMake/CpsExportImportBuild/RunCMakeTest.cmake b/Tests/RunCMake/CpsExportImportBuild/RunCMakeTest.cmake index d0c460d8fa..7813e50f8d 100644 --- a/Tests/RunCMake/CpsExportImportBuild/RunCMakeTest.cmake +++ b/Tests/RunCMake/CpsExportImportBuild/RunCMakeTest.cmake @@ -14,4 +14,5 @@ function(build_project test) endfunction() build_project(TestLibrary) +build_project(TestTool) build_project(TestExecutable) diff --git a/Tests/RunCMake/CpsExportImportBuild/TestExecutable.cmake b/Tests/RunCMake/CpsExportImportBuild/TestExecutable.cmake index 9218737e37..84ee9b1acf 100644 --- a/Tests/RunCMake/CpsExportImportBuild/TestExecutable.cmake +++ b/Tests/RunCMake/CpsExportImportBuild/TestExecutable.cmake @@ -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) diff --git a/Tests/RunCMake/CpsExportImportBuild/TestTool.cmake b/Tests/RunCMake/CpsExportImportBuild/TestTool.cmake new file mode 100644 index 0000000000..6c069571d2 --- /dev/null +++ b/Tests/RunCMake/CpsExportImportBuild/TestTool.cmake @@ -0,0 +1,6 @@ +project(TestTool C) + +add_executable(tool tool.c) + +install(TARGETS tool EXPORT tool) +export(PACKAGE_INFO tool EXPORT tool) diff --git a/Tests/RunCMake/CpsExportImportBuild/app.c b/Tests/RunCMake/CpsExportImportBuild/app.c index 036919d7f7..59b50e5e51 100644 --- a/Tests/RunCMake/CpsExportImportBuild/app.c +++ b/Tests/RunCMake/CpsExportImportBuild/app.c @@ -1,8 +1,10 @@ #include #include +extern int gen(void); + int main(void) { - printf("%i\n", ask()); + printf("%i\n", ask() + gen()); return 0; } diff --git a/Tests/RunCMake/CpsExportImportBuild/tool.c b/Tests/RunCMake/CpsExportImportBuild/tool.c new file mode 100644 index 0000000000..c8983d1883 --- /dev/null +++ b/Tests/RunCMake/CpsExportImportBuild/tool.c @@ -0,0 +1,24 @@ +#ifndef _CRT_SECURE_NO_DEPRECATE +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include + +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; +} diff --git a/Tests/RunCMake/CpsExportImportInstall/RunCMakeTest.cmake b/Tests/RunCMake/CpsExportImportInstall/RunCMakeTest.cmake index bdc5e34f75..ee7cdc7659 100644 --- a/Tests/RunCMake/CpsExportImportInstall/RunCMakeTest.cmake +++ b/Tests/RunCMake/CpsExportImportInstall/RunCMakeTest.cmake @@ -15,4 +15,5 @@ function(build_project test) endfunction() build_project(TestLibrary) +build_project(TestTool) build_project(TestExecutable) diff --git a/Tests/RunCMake/CpsExportImportInstall/TestExecutable.cmake b/Tests/RunCMake/CpsExportImportInstall/TestExecutable.cmake index cced129ec3..2fba7632a7 100644 --- a/Tests/RunCMake/CpsExportImportInstall/TestExecutable.cmake +++ b/Tests/RunCMake/CpsExportImportInstall/TestExecutable.cmake @@ -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) diff --git a/Tests/RunCMake/CpsExportImportInstall/TestTool.cmake b/Tests/RunCMake/CpsExportImportInstall/TestTool.cmake new file mode 100644 index 0000000000..f2fa14732d --- /dev/null +++ b/Tests/RunCMake/CpsExportImportInstall/TestTool.cmake @@ -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) diff --git a/Tests/RunCMake/CpsExportImportInstall/app.c b/Tests/RunCMake/CpsExportImportInstall/app.c index 036919d7f7..59b50e5e51 100644 --- a/Tests/RunCMake/CpsExportImportInstall/app.c +++ b/Tests/RunCMake/CpsExportImportInstall/app.c @@ -1,8 +1,10 @@ #include #include +extern int gen(void); + int main(void) { - printf("%i\n", ask()); + printf("%i\n", ask() + gen()); return 0; } diff --git a/Tests/RunCMake/CpsExportImportInstall/tool.c b/Tests/RunCMake/CpsExportImportInstall/tool.c new file mode 100644 index 0000000000..c8983d1883 --- /dev/null +++ b/Tests/RunCMake/CpsExportImportInstall/tool.c @@ -0,0 +1,24 @@ +#ifndef _CRT_SECURE_NO_DEPRECATE +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include + +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; +}