@@ -1401,6 +1401,26 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
14011401 });
14021402 };
14031403
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+ });
1422+ };
1423+
14041424 auto gen_target_cmds = [&](const parser::Target &t) {
14051425 target_cmd (" target_compile_definitions" , t.compile_definitions , target_scope);
14061426 target_cmd (" target_compile_definitions" , t.private_compile_definitions , " PRIVATE" );
@@ -1417,8 +1437,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
14171437 target_cmd (" target_link_directories" , t.link_directories , target_scope);
14181438 target_cmd (" target_link_directories" , t.private_link_directories , " PRIVATE" );
14191439
1420- target_cmd ( " target_link_libraries " , t.link_libraries , target_scope);
1421- 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" );
14221442
14231443 target_cmd (" target_link_options" , t.link_options , target_scope);
14241444 target_cmd (" target_link_options" , t.private_link_options , " PRIVATE" );
0 commit comments