Skip to content

Commit 4c5729f

Browse files
committed
Fix issues with building deps.
1 parent ac9660e commit 4c5729f

2 files changed

Lines changed: 52 additions & 34 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
cppan
66
.cppan*
77

8+
*.kdev*
9+
810
/packages
911

1012
/*.bat

src/printers/cmake.cpp

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ void gather_build_deps(const Packages &dd, Packages &out, bool recursive = false
413413
if (d.flags[pfHeaderOnly] || d.flags[pfIncludeDirectoriesOnly])
414414
continue;
415415
auto i = out.insert(dp);
416+
// add executable, but not its deps
417+
// exe will build its deps themselves
418+
if (d.flags[pfExecutable])
419+
continue;
416420
if (i.second && recursive)
417421
gather_build_deps(rd[d].dependencies, out, recursive);
418422
}
@@ -514,12 +518,31 @@ void CMakePrinter::print_build_dependencies(CMakeContext &ctx, const String &tar
514518
}
515519
local.emptyLines();
516520

521+
#define ADD_VAR(v) rest += "-D" #v "=${" #v "} "
522+
String rest;
523+
// we do not pass this var to children
524+
//ADD_VAR(CPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIG);
525+
ADD_VAR(CPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIGURATION);
526+
ADD_VAR(CMAKE_BUILD_TYPE);
527+
ADD_VAR(CPPAN_BUILD_VERBOSE);
528+
ADD_VAR(CPPAN_BUILD_WARNING_LEVEL);
529+
ADD_VAR(CPPAN_COPY_ALL_LIBRARIES_TO_OUTPUT);
530+
ADD_VAR(N_CORES);
531+
ADD_VAR(XCODE);
532+
ADD_VAR(NINJA);
533+
ADD_VAR(VISUAL_STUDIO);
534+
#undef ADD_VAR
535+
536+
local.addLine("set(rest \"" + rest + "\")");
537+
local.emptyLines();
538+
517539
local.increaseIndent(R"(set(ext sh)
518540
if (WIN32)
519541
set(ext bat)
520542
endif()
521-
file(GENERATE OUTPUT ${BDIR}/cppan_build_deps_$<CONFIG>.${ext} CONTENT "
522-
)");
543+
544+
file(GENERATE OUTPUT ${BDIR}/cppan_build_deps_$<CONFIG>.${ext} CONTENT ")");
545+
523546
bool has_build_deps = false;
524547
for (auto &dp : build_deps)
525548
{
@@ -529,33 +552,25 @@ file(GENERATE OUTPUT ${BDIR}/cppan_build_deps_$<CONFIG>.${ext} CONTENT "
529552
if (p.flags[pfLocalProject])
530553
continue;
531554

555+
String cfg = "config";
556+
if (p.flags[pfExecutable] && !p.flags[pfLocalProject])
557+
cfg = "config_exe";
558+
532559
has_build_deps = true;
560+
local.addNoNewLine("");
533561
local.addText("\\\"${CMAKE_COMMAND}\\\" ");
534562
local.addText("-DTARGET_FILE=$<TARGET_FILE:" + p.target_name + "> ");
535563
local.addText("-DCONFIG=$<CONFIG> ");
536-
String cfg = "config";
537-
if (p.flags[pfExecutable] && !p.flags[pfLocalProject])
538-
cfg = "config_exe";
539564
local.addText("-DBUILD_DIR=" + normalize_path(p.getDirObj()) + "/build/${" + cfg + "} ");
540565
local.addText("-DEXECUTABLE="s + (p.flags[pfExecutable] ? "1" : "0") + " ");
541-
// we do not pass this var to children
542-
//local.addText("-DCPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIG=${CPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIG} ");
543-
local.addText("-DCPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIGURATION=${CPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIGURATION} ");
544-
local.addText("-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ");
545-
local.addText("-DCPPAN_BUILD_VERBOSE=${CPPAN_BUILD_VERBOSE} ");
546-
local.addText("-DCPPAN_BUILD_WARNING_LEVEL=${CPPAN_BUILD_WARNING_LEVEL} ");
547-
local.addText("-DCPPAN_COPY_ALL_LIBRARIES_TO_OUTPUT=${CPPAN_COPY_ALL_LIBRARIES_TO_OUTPUT} ");
548-
local.addText("-DN_CORES=${N_CORES} ");
549566
if (d.empty())
550567
local.addText("-DMULTICORE=1 ");
551-
local.addText("-DXCODE=${XCODE} ");
552-
local.addText("-DNINJA=${NINJA} ");
553-
local.addText("-DVISUAL_STUDIO=${VISUAL_STUDIO} ");
568+
local.addText("${rest} ");
569+
554570
local.addText("-P " + normalize_path(p.getDirObj()) + "/" + cmake_obj_build_filename);
555-
local.addLine();
556571
}
557-
local.addLine("\"");
558-
local.decreaseIndent(")");
572+
local.decreaseIndent("\")");
573+
local.emptyLines();
559574

560575
bool deps = false;
561576
String build_deps_tgt = "${this}";
@@ -612,7 +627,7 @@ file(GENERATE OUTPUT ${BDIR}/cppan_build_deps_$<CONFIG>.${ext} CONTENT "
612627
}
613628

614629
if (has_build_deps)
615-
ctx += local;
630+
ctx.addWithRelativeIndent(local);
616631
}
617632

618633
ctx.endif();
@@ -1431,12 +1446,13 @@ endif()
14311446
{
14321447
case 17:
14331448
ctx.if_("UNIX");
1449+
// if compiler supports c++17, set it
14341450
ctx.addLine("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1z\")");
14351451
ctx.endif();
14361452
break;
14371453
case 20:
14381454
ctx.if_("UNIX");
1439-
ctx.addLine("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++2x\")");
1455+
ctx.addLine("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++2x\")"); // 2a?
14401456
ctx.endif();
14411457
break;
14421458
default:
@@ -1786,19 +1802,19 @@ endif()
17861802

17871803
// some compiler options
17881804
ctx.addLine(R"(if (MSVC)
1789-
target_compile_definitions(${this}
1790-
PRIVATE _CRT_SECURE_NO_WARNINGS # disable warning about non-standard functions
1791-
)
1792-
target_compile_options(${this}
1793-
PRIVATE /wd4005 # macro redefinition
1794-
PRIVATE /wd4996 # The POSIX name for this item is deprecated.
1795-
)
1805+
target_compile_definitions(${this}
1806+
PRIVATE _CRT_SECURE_NO_WARNINGS # disable warning about non-standard functions
1807+
)
1808+
target_compile_options(${this}
1809+
PRIVATE /wd4005 # macro redefinition
1810+
PRIVATE /wd4996 # The POSIX name for this item is deprecated.
1811+
)
17961812
endif()
17971813
17981814
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
1799-
target_compile_options(${this}
1800-
PRIVATE -Wno-macro-redefined
1801-
)
1815+
target_compile_options(${this}
1816+
PRIVATE -Wno-macro-redefined
1817+
)
18021818
endif()
18031819
)");
18041820
}
@@ -1871,9 +1887,9 @@ endif()
18711887
if (!d.flags[pfHeaderOnly])
18721888
{
18731889
ctx.increaseIndent(R"(if (WIN32)
1874-
target_link_libraries(${this}
1875-
PUBLIC Ws2_32
1876-
)
1890+
target_link_libraries(${this}
1891+
PUBLIC Ws2_32
1892+
)
18771893
else())");
18781894
auto add_unix_lib = [this, &ctx](const String &s)
18791895
{

0 commit comments

Comments
 (0)