@@ -558,11 +558,15 @@ struct Generator {
558558 }
559559
560560 void conditional_includes (const parser::ConditionVector &include) {
561- handle_condition (include, [this ](const std::string &, const std::vector<std::string> &includes) { inject_includes (includes); });
561+ handle_condition (include, [this ](const std::string &, const std::vector<std::string> &includes) {
562+ inject_includes (includes);
563+ });
562564 }
563565
564566 void conditional_cmake (const parser::Condition<std::string> &cmake) {
565- handle_condition (cmake, [this ](const std::string &, const std::string &cmake) { inject_cmake (cmake); });
567+ handle_condition (cmake, [this ](const std::string &, const std::string &cmake) {
568+ inject_cmake (cmake);
569+ });
566570 }
567571
568572 bool if_condition (const std::string &condition) {
@@ -719,9 +723,15 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
719723
720724 // Helper lambdas for more convenient CMake generation
721725 auto &ss = gen.ss ;
722- auto cmd = [&gen](const std::string &command) { return gen.cmd (command); };
723- auto comment = [&gen](const std::string &comment) { return gen.comment (comment); };
724- auto endl = [&gen]() { gen.endl (); };
726+ auto cmd = [&gen](const std::string &command) {
727+ return gen.cmd (command);
728+ };
729+ auto comment = [&gen](const std::string &comment) {
730+ return gen.comment (comment);
731+ };
732+ auto endl = [&gen]() {
733+ gen.endl ();
734+ };
725735
726736 std::string cmkr_url = " https://github.com/build-cpp/cmkr" ;
727737 comment (" This file is automatically generated from cmake.toml - DO NOT EDIT" );
@@ -1145,7 +1155,9 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
11451155 for (size_t i = 0 ; i < project.targets .size (); i++) {
11461156 const auto &target = project.targets [i];
11471157
1148- auto throw_target_error = [&target](const std::string &message) { throw std::runtime_error (" [target." + target.name + " ] " + message); };
1158+ auto throw_target_error = [&target](const std::string &message) {
1159+ throw std::runtime_error (" [target." + target.name + " ] " + message);
1160+ };
11491161
11501162 const parser::Template *tmplate = nullptr ;
11511163 std::unique_ptr<ConditionScope> tmplate_cs{};
@@ -1384,8 +1396,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
13841396 }
13851397
13861398 auto target_cmd = [&](const char *command, const parser::ConditionVector &cargs, const std::string &scope) {
1387- gen.handle_condition (cargs,
1388- [&](const std::string &, const std::vector<std::string> &args) { cmd (command)(target.name , scope, args); });
1399+ gen.handle_condition (cargs, [&](const std::string &, const std::vector<std::string> &args) {
1400+ cmd (command)(target.name , scope, args);
1401+ });
1402+ };
1403+
1404+ auto link_libraries = [&](const parser::ConditionVector &cargs, const std::string &scope) {
1405+ gen.handle_condition (cargs, [&](const std::string &, const std::vector<std::string> &args) {
1406+ std::vector<std::string> targs;
1407+ for (const std::string &arg : args) {
1408+ if (arg.find (" ::" ) == 0 ) {
1409+ auto library = arg.substr (2 );
1410+ // clang-format off
1411+ cmd (" if" )(" NOT" , " TARGET" , library);
1412+ cmd (" message" )(" FATAL_ERROR" , " Target \" " + library + " \" referenced by \" " + target.name + " \" does not exist!" );
1413+ cmd (" endif" )().endl ();
1414+ // clang-format on
1415+ targs.push_back (std::move (library));
1416+ } else {
1417+ targs.push_back (arg);
1418+ }
1419+ }
1420+ cmd (" target_link_libraries" )(target.name , scope, targs);
1421+ });
13891422 };
13901423
13911424 auto gen_target_cmds = [&](const parser::Target &t) {
@@ -1404,8 +1437,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
14041437 target_cmd (" target_link_directories" , t.link_directories , target_scope);
14051438 target_cmd (" target_link_directories" , t.private_link_directories , " PRIVATE" );
14061439
1407- target_cmd ( " target_link_libraries " , t.link_libraries , target_scope);
1408- target_cmd ( " target_link_libraries " , t.private_link_libraries , " PRIVATE" );
1440+ link_libraries ( t.link_libraries , target_scope);
1441+ link_libraries ( t.private_link_libraries , " PRIVATE" );
14091442
14101443 target_cmd (" target_link_options" , t.link_options , target_scope);
14111444 target_cmd (" target_link_options" , t.private_link_options , " PRIVATE" );
0 commit comments