From 624b9a7d53c0a41e82190900d39faefb0f275248 Mon Sep 17 00:00:00 2001 From: qqiangwu Date: Sun, 20 Apr 2025 14:52:47 +0800 Subject: [PATCH] fix(build): fix missing linkflags support --- lib/cmake/generator.cpp | 6 ++++++ tests/cmake/generator.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/cmake/generator.cpp b/lib/cmake/generator.cpp index 00b91c5..23fae82 100644 --- a/lib/cmake/generator.cpp +++ b/lib/cmake/generator.cpp @@ -375,6 +375,9 @@ class ProfileOptionGen { for (const auto& opt : config.cxxflags) { mOut << fmt::format("{}add_compile_options($<$:{}>)\n", indent, profile, opt); } + for (const auto& opt : config.linkflags) { + mOut << fmt::format("{}add_link_options($<$:{}>)\n", indent, profile, opt); + } for (const auto& def : config.definitions) { mOut << fmt::format("{}add_compile_definitions($<$:{}>)\n", indent, profile, def); } @@ -409,6 +412,9 @@ class ProfileOptionGen { for (const auto& opt : config.cxxflags) { mOut << fmt::format("{}add_compile_options({})\n", indent, opt); } + for (const auto& opt : config.linkflags) { + mOut << fmt::format("{}add_link_options({}>)\n", indent, opt); + } for (const auto& def : config.definitions) { mOut << fmt::format("{}add_compile_definitions({})\n", indent, def); } diff --git a/tests/cmake/generator.cpp b/tests/cmake/generator.cpp index d138be5..981f7c9 100644 --- a/tests/cmake/generator.cpp +++ b/tests/cmake/generator.cpp @@ -41,3 +41,31 @@ version = "0.1.0" const auto content = std::move(gen).build(); EXPECT_TRUE(boost::contains(content, "target_compile_definitions(tmp_bin PRIVATE ABC_ABC_ABC_VERSION=")); } + +TEST(generator, ProfileOptions) +{ + const auto dir = fs::temp_directory_path(); + create_if_not_exist(dir / kSrcPath); + write(dir / kSrcPath / "main.cpp", ""); + + Layout layout(dir, "tmp"); + auto meta = mock_manifest(R"([package] +name = "abc-abc-abc" +version = "0.1.0" + +[profile] +cxxflags = ["-Wall"] +linkflags = ["-lpthread"] + +[profile.debug] +cxxflags = ["-Wextra"] +linkflags = ["-lz"] + )"); + CmakeGenerator gen(&layout, meta.get_if_package(), {}); + const auto content = std::move(gen).build(); + EXPECT_TRUE(boost::contains(content, "add_compile_options(-Wall)")); + EXPECT_TRUE(boost::contains(content, "add_link_options(-lpthread>)")); + EXPECT_TRUE(boost::contains(content, "add_compile_options($<$:-Wextra>)")); + EXPECT_TRUE(boost::contains(content, "add_link_options($<$:-lz>)")); + EXPECT_TRUE(boost::contains(content, "target_compile_definitions(tmp_bin PRIVATE ABC_ABC_ABC_VERSION=")); +}