@@ -558,11 +558,15 @@ struct Generator {
558
558
}
559
559
560
560
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
+ });
562
564
}
563
565
564
566
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
+ });
566
570
}
567
571
568
572
bool if_condition (const std::string &condition) {
@@ -719,9 +723,15 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
719
723
720
724
// Helper lambdas for more convenient CMake generation
721
725
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
+ };
725
735
726
736
std::string cmkr_url = " https://github.com/build-cpp/cmkr" ;
727
737
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) {
1145
1155
for (size_t i = 0 ; i < project.targets .size (); i++) {
1146
1156
const auto &target = project.targets [i];
1147
1157
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
+ };
1149
1161
1150
1162
const parser::Template *tmplate = nullptr ;
1151
1163
std::unique_ptr<ConditionScope> tmplate_cs{};
@@ -1384,8 +1396,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
1384
1396
}
1385
1397
1386
1398
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
+ });
1389
1422
};
1390
1423
1391
1424
auto gen_target_cmds = [&](const parser::Target &t) {
@@ -1404,8 +1437,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
1404
1437
target_cmd (" target_link_directories" , t.link_directories , target_scope);
1405
1438
target_cmd (" target_link_directories" , t.private_link_directories , " PRIVATE" );
1406
1439
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" );
1409
1442
1410
1443
target_cmd (" target_link_options" , t.link_options , target_scope);
1411
1444
target_cmd (" target_link_options" , t.private_link_options , " PRIVATE" );
0 commit comments