@@ -129,6 +129,9 @@ class ScopedDependencyCondition
129129
130130String cmake_debug_message (const String &s)
131131{
132+ if (!Settings::get_local_settings ().debug_generated_cmake_configs )
133+ return " " ;
134+
132135 return cmake_debug_message_fun + " (\" " + s + " \" )" ;
133136}
134137
@@ -184,6 +187,9 @@ void file_header(CMakeContext &ctx, const Package &d, bool root)
184187 ctx.addLine (" include(" + normalize_path (directories.get_static_files_dir () / cmake_header_filename) + " )" );
185188 ctx.addLine ();
186189
190+ if (!Settings::get_local_settings ().debug_generated_cmake_configs )
191+ return ;
192+
187193 // before header message
188194 if (!root)
189195 {
@@ -205,6 +211,9 @@ void file_header(CMakeContext &ctx, const Package &d, bool root)
205211
206212void file_footer (CMakeContext &ctx, const Package &d)
207213{
214+ if (!Settings::get_local_settings ().debug_generated_cmake_configs )
215+ return ;
216+
208217 config_section_title (ctx, " footer" , true );
209218 ctx.addLine (cmake_debug_message (" Leaving file: ${CMAKE_CURRENT_LIST_FILE}" ));
210219 ctx.addLine ();
@@ -775,6 +784,11 @@ void CMakePrinter::print_copy_dependencies(CMakeContext &ctx, const String &targ
775784 ctx.addLine (" set(copy_content \" ${copy_content} @setlocal\\ n\" )" );
776785 ctx.endif ();
777786
787+ // we're in helper, set this var to build target
788+ if (d.empty ())
789+ ctx.addLine (" set(this " + target + " )" );
790+ ctx.emptyLines ();
791+
778792 ctx.addLine (" set(output_dir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})" );
779793 ctx.if_ (" NOT output_dir" );
780794 ctx.addLine (" set(output_dir ${CMAKE_BINARY_DIR})" );
@@ -914,6 +928,61 @@ add_custom_command(TARGET )" + target + R"( POST_BUILD
914928
915929 ctx.endif ();
916930 ctx.addLine ();
931+
932+ // like with build deps
933+ for (auto &dp : copy_deps)
934+ {
935+ auto &p = dp.second ;
936+
937+ // local projects are always built inside solution
938+ if (p.flags [pfLocalProject])
939+ continue ;
940+
941+ ScopedDependencyCondition sdc (ctx, p);
942+ ctx.addLine (" get_target_property(imploc_" + p.variable_name + " " + p.target_name + " IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPER})" );
943+ }
944+ ctx.emptyLines ();
945+
946+ bool deps = false ;
947+ String build_deps_tgt = " ${this}" ;
948+ if (d.empty () && target.find (" -c" ) != target.npos )
949+ {
950+ build_deps_tgt += " -d" ; // deps
951+ deps = true ;
952+ }
953+ else
954+ build_deps_tgt += " -c-d" ;
955+
956+ // do not use add_custom_command as it doesn't work
957+ // add custom target and add a dependency below
958+ // second way is to use add custom target + add custom command (POST?(PRE)_BUILD)
959+ ctx.addLine (" set(bp)" );
960+ // for (auto &dp : build_deps_all)
961+ for (auto &dp : copy_deps)
962+ {
963+ auto &p = dp.second ;
964+
965+ // local projects are always built inside solution
966+ if (p.flags [pfLocalProject])
967+ continue ;
968+
969+ ScopedDependencyCondition sdc (ctx, p, false );
970+ ctx.addLine (" set(bp ${bp} ${imploc_" + p.variable_name + " })" );
971+ }
972+ ctx.emptyLines ();
973+
974+ ctx.increaseIndent (" add_custom_target(" + build_deps_tgt);
975+ ctx.addLine (" COMMAND ${file}" );
976+ ctx.increaseIndent (" BYPRODUCTS ${bp}" );
977+ ctx.decreaseIndent (" )" , 2 );
978+ ctx.addLine (" add_dependencies(${this} " + build_deps_tgt + " )" );
979+ print_solution_folder (ctx, build_deps_tgt, deps ? service_folder : service_deps_folder);
980+ // this causes long paths issue
981+ // if (deps)
982+ // set_target_properties(ctx, build_deps_tgt, "PROJECT_LABEL", "dependencies");
983+ // else
984+ // set_target_properties(ctx, build_deps_tgt, "PROJECT_LABEL", (d.flags[pfLocalProject] ? d.ppath.back() : d.target_name) + "-build-dependencies");
985+ ctx.addLine ();
917986}
918987
919988void CMakePrinter::prepare_rebuild () const
@@ -2953,7 +3022,7 @@ endif()
29533022 \"${CMAKE_TOOLCHAIN_FILE}\"
29543023 )" s;
29553024 ctx.if_ (" CPPAN_COMMAND" );
2956- ctx. addLine ( " cppan_debug_message( \" " + cmd + " \" ) " );
3025+ cmake_debug_message ( cmd);
29573026 ctx.addLine (" execute_process(" + cmd + " RESULT_VARIABLE ret)" );
29583027 ctx.addLine (" check_result_variable(${ret} \" " + cmd + " \" )" );
29593028 ctx.endif ();
0 commit comments