Skip to content

Commit 123ceb6

Browse files
committed
Initial installation of deps. Switch to inline cppan deps. Initial simulation of installing of local packages. Some cmake functions cleanups.
1 parent 2a3c41a commit 123ceb6

9 files changed

Lines changed: 362 additions & 286 deletions

File tree

CMakeLists.txt

Lines changed: 252 additions & 218 deletions
Large diffs are not rendered by default.

cppan.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,6 @@ local_settings:
66
generator: Visual Studio 15 2017
77
configuration: Debug
88

9-
dependencies:
10-
pvt.cppan.demo.boost.program_options: 1
11-
pvt.cppan.demo.boost.property_tree: 1
12-
pvt.cppan.demo.boost.stacktrace: 1
13-
pvt.cppan.demo.sqlite3: 3
14-
pvt.cppan.demo.yhirose.cpp_linenoise: master
15-
pvt.cppan.demo.fmt: 4
16-
17-
pvt.egorpugin.primitives.command: master
18-
pvt.egorpugin.primitives.string: master
19-
pvt.egorpugin.primitives.filesystem: master
20-
pvt.egorpugin.primitives.context: master
21-
pvt.egorpugin.primitives.date_time: master
22-
pvt.egorpugin.primitives.executor: master
23-
pvt.egorpugin.primitives.hash: master
24-
pvt.egorpugin.primitives.http: master
25-
pvt.egorpugin.primitives.lock: master
26-
pvt.egorpugin.primitives.log: master
27-
pvt.egorpugin.primitives.pack: master
28-
pvt.egorpugin.primitives.yaml: master
29-
30-
pvt.cppan.demo.imageworks.pystring: 1
31-
pvt.cppan.demo.giovannidicanio.winreg: master
32-
33-
pvt.cppan.demo.philsquared.catch: 1
34-
359
root_project: pvt.cppan.client
3610

3711
common_settings:

src/common/package_store.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,10 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
528528
Package pkg;
529529
pkg.ppath = ppath;
530530
if (!project.name.empty())
531-
pkg.ppath.push_back(project.name);
531+
{
532+
//pkg.ppath.push_back(project.name);
533+
pkg.ppath /= ProjectPath(project.name);
534+
}
532535
pkg.version = Version(LOCAL_VERSION_NAME);
533536
pkg.flags.set(pfLocalProject);
534537
pkg.flags.set(pfDirectDependency, direct_dependency);
@@ -545,11 +548,11 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
545548
auto f = e.push([&c, &p, &cpp_fn, &ppath]()
546549
{
547550
auto &project = c.getDefaultProject();
548-
auto root_directory = fs::is_regular_file(p) ? p.parent_path() : p;
549-
if (project.root_directory.is_absolute())
550-
root_directory = project.root_directory;
551-
else
552-
root_directory /= project.root_directory;
551+
auto root_directory = fs::is_regular_file(p) ? p.parent_path() : p;
552+
if (project.root_directory.is_absolute())
553+
root_directory = project.root_directory;
554+
else
555+
root_directory /= project.root_directory;
553556

554557
// sources
555558
if (!cpp_fn.empty() && !project.files_loaded)
@@ -563,7 +566,7 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
563566
project.findSources(root_directory);
564567
// maybe remove? let user see cppan.yml in local project
565568
project.files.erase(current_thread_path() / CPPAN_FILENAME);
566-
project.files.erase(CPPAN_FILENAME);
569+
project.files.erase(CPPAN_FILENAME);
567570
// patch if any
568571
project.patchSources();
569572

@@ -573,6 +576,23 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
573576
project.applyFlags(project.pkg.flags);
574577
c.setPackage(project.pkg);
575578

579+
if (Settings::get_local_settings().install_local_packages)
580+
{
581+
// copy files to project's dir
582+
decltype(project.files) files;
583+
for (auto &f : project.files)
584+
{
585+
auto r = project.pkg.getDirSrc() / f.lexically_relative(root_directory);
586+
create_directories(r.parent_path());
587+
fs::copy_file(f, r, fs::copy_option::overwrite_if_exists);
588+
files.insert(r);
589+
}
590+
project.files = files;
591+
592+
// set non local
593+
//project.pkg.flags.set(pfLocalProject, false);
594+
}
595+
576596
// check if project's deps are relative
577597
// this means that there's a local dependency
578598
auto deps = project.dependencies;

src/common/project.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ ProjectPath Project::relative_name_to_absolute(const String &name)
804804
return ld.value();
805805
if (allow_relative_project_names)
806806
{
807-
ppath.push_back(name);
807+
//ppath.push_back(name);
808+
ppath = name;
808809
return ppath;
809810
}
810811
if (root_project.empty())

src/common/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void Settings::load_main(const yaml &root, const SettingsType type)
148148
YAML_EXTRACT_AUTO(disable_update_checks);
149149
YAML_EXTRACT_AUTO(max_download_threads);
150150
YAML_EXTRACT_AUTO(debug_generated_cmake_configs);
151+
YAML_EXTRACT_AUTO(install_local_packages);
151152
YAML_EXTRACT(storage_dir, String);
152153
YAML_EXTRACT(build_dir, String);
153154
YAML_EXTRACT(cppan_dir, String);

src/common/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct Settings
7777
bool disable_update_checks = false;
7878
int max_download_threads = get_max_threads(8);
7979
bool debug_generated_cmake_configs = false;
80+
bool install_local_packages = false;
8081

8182
// build settings
8283
String c_compiler;

src/inserts/functions.cmake

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function(add_variable array variable)
486486
list(REMOVE_AT ${array}_VALUES ${found})
487487
list(INSERT ${array}_VALUES ${found} "${${variable}}")
488488
#message(STATUS "New array: ${${array}_VALUES}")
489-
set(${array}_VALUES ${${array}_VALUES} PARENT_SCOPE)
489+
set(${array}_VALUES ${${array}_VALUES} CACHE STRING "Chached array." FORCE)
490490
endif()
491491

492492
return()
@@ -500,23 +500,19 @@ function(add_variable array variable)
500500
list(APPEND ${array}_VALUES "${${variable}}")
501501
endif()
502502

503-
set(${array}_TYPES ${${array}_TYPES} PARENT_SCOPE)
504-
set(${array}_KEYS ${${array}_KEYS} PARENT_SCOPE)
505-
set(${array}_VALUES ${${array}_VALUES} PARENT_SCOPE)
503+
set(${array}_TYPES ${${array}_TYPES} CACHE STRING "Chached array." FORCE)
504+
set(${array}_KEYS ${${array}_KEYS} CACHE STRING "Chached array." FORCE)
505+
set(${array}_VALUES ${${array}_VALUES} CACHE STRING "Chached array." FORCE)
506506
endfunction(add_variable)
507507

508508
########################################
509509
# FUNCTION clear_variables
510510
########################################
511511

512512
function(clear_variables array)
513-
set(${array}_TYPES)
514-
set(${array}_KEYS)
515-
set(${array}_VALUES)
516-
517-
set(${array}_TYPES ${${array}_TYPES} PARENT_SCOPE)
518-
set(${array}_KEYS ${${array}_KEYS} PARENT_SCOPE)
519-
set(${array}_VALUES ${${array}_VALUES} PARENT_SCOPE)
513+
unset(${array}_TYPES CACHE)
514+
unset(${array}_KEYS CACHE)
515+
unset(${array}_VALUES CACHE)
520516
endfunction(clear_variables)
521517

522518
########################################
@@ -557,9 +553,9 @@ function(read_variables_file array f)
557553
add_variable(${array} ${k})
558554
endforeach()
559555

560-
set(${array}_TYPES ${${array}_TYPES} PARENT_SCOPE)
561-
set(${array}_KEYS ${${array}_KEYS} PARENT_SCOPE)
562-
set(${array}_VALUES ${${array}_VALUES} PARENT_SCOPE)
556+
set(${array}_TYPES ${${array}_TYPES} CACHE STRING "Chached array." FORCE)
557+
set(${array}_KEYS ${${array}_KEYS} CACHE STRING "Chached array." FORCE)
558+
set(${array}_VALUES ${${array}_VALUES} CACHE STRING "Chached array." FORCE)
563559
endfunction(read_variables_file)
564560

565561
########################################
@@ -597,11 +593,6 @@ endfunction(write_variables_file)
597593

598594
function(add_check_variable v)
599595
add_variable(CPPAN_VARIABLES ${v})
600-
601-
set(CPPAN_VARIABLES_TYPES ${CPPAN_VARIABLES_TYPES} PARENT_SCOPE)
602-
set(CPPAN_VARIABLES_KEYS ${CPPAN_VARIABLES_KEYS} PARENT_SCOPE)
603-
set(CPPAN_VARIABLES_VALUES ${CPPAN_VARIABLES_VALUES} PARENT_SCOPE)
604-
605596
set(CPPAN_NEW_VARIABLE_ADDED 1 PARENT_SCOPE)
606597
endfunction(add_check_variable)
607598

@@ -610,16 +601,7 @@ endfunction(add_check_variable)
610601
########################################
611602

612603
function(read_check_variables_file f)
613-
#if (NOT EXISTS ${f})
614-
#message(STATUS "Check variables file does not exist: ${f}")
615-
#return()
616-
#endif()
617-
618604
read_variables_file(CPPAN_VARIABLES ${f})
619-
620-
set(CPPAN_VARIABLES_TYPES ${CPPAN_VARIABLES_TYPES} PARENT_SCOPE)
621-
set(CPPAN_VARIABLES_KEYS ${CPPAN_VARIABLES_KEYS} PARENT_SCOPE)
622-
set(CPPAN_VARIABLES_VALUES ${CPPAN_VARIABLES_VALUES} PARENT_SCOPE)
623605
endfunction(read_check_variables_file)
624606

625607
########################################
@@ -947,4 +929,29 @@ function(set_cache_var variable value)
947929
set(${variable} ${value} CACHE STRING "" FORCE)
948930
endfunction()
949931

932+
########################################
933+
# FUNCTION clear_once_variables
934+
########################################
935+
936+
function(clear_once_variables)
937+
#message(STATUS "clear_once_variables - ${CPPAN_ONCE_VARIABLES}")
938+
if (NOT CPPAN_ONCE_VARIABLES)
939+
return()
940+
endif()
941+
942+
foreach(v ${CPPAN_ONCE_VARIABLES})
943+
#message(STATUS "unsetting ${v}")
944+
unset(${v} CACHE)
945+
endforeach()
946+
endfunction()
947+
948+
########################################
949+
# FUNCTION set_once_var
950+
########################################
951+
952+
function(set_once_var variable)
953+
set_cache_var(${variable} 1)
954+
set(CPPAN_ONCE_VARIABLES ${CPPAN_ONCE_VARIABLES} ${variable} CACHE STRING "" FORCE)
955+
endfunction()
956+
950957
################################################################################

src/inserts/generate.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ if (NOT EXISTS ${import} OR
191191
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
192192
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
193193
-G \"${generator}\"
194-
-DVARIABLES_FILE=${variables_file}"
195-
${sysver}
194+
-DVARIABLES_FILE=${variables_file}
195+
${sysver}"
196196
)
197197
execute_process(
198198
COMMAND ${CMAKE_COMMAND}
@@ -210,8 +210,8 @@ if (NOT EXISTS ${import} OR
210210
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
211211
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
212212
-G \"${generator}\"
213-
-DVARIABLES_FILE=${variables_file}"
214-
${sysver}
213+
-DVARIABLES_FILE=${variables_file}
214+
${sysver}"
215215
)
216216
execute_process(
217217
COMMAND ${CMAKE_COMMAND}

src/printers/cmake.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,8 @@ void CMakePrinter::print_obj_config_file(const path &fn) const
24472447
config_section_title(ctx, "macros & functions");
24482448
ctx.addLine("include(" + normalize_path(directories.get_static_files_dir() / cmake_functions_filename) + ")");
24492449
ctx.addLine();
2450+
ctx.addLine("clear_once_variables()");
2451+
ctx.addLine();
24502452
//if (!d.flags[pfLocalProject])
24512453
{
24522454
config_section_title(ctx, "read passed variables");
@@ -2749,6 +2751,8 @@ void CMakePrinter::print_meta_config_file(const path &fn) const
27492751
print_sdir_bdir(ctx, d);
27502752

27512753
config_section_title(ctx, "variables");
2754+
ctx.addLine("clear_once_variables()");
2755+
ctx.addLine();
27522756
ctx.addLine("set(CPPAN_BUILD 1 CACHE STRING \"CPPAN is turned on\")");
27532757
ctx.addLine();
27542758
print_storage_dirs(ctx);
@@ -2870,6 +2874,29 @@ add_dependencies()" + old_cppan_target + R"( run-cppan)
28702874
ctx.addLine("set_target_properties(" + dep.second.target_name_hash + " PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CPPAN_BUILD_OUTPUT_DIR})");
28712875
}
28722876
}
2877+
2878+
// install deps
2879+
config_section_title(ctx, "install");
2880+
Packages copy_deps;
2881+
gather_copy_deps(rd[d].dependencies, copy_deps);
2882+
for (auto &dp : copy_deps)
2883+
{
2884+
auto &p = dp.second;
2885+
2886+
if (p.flags[pfExecutable])
2887+
continue;
2888+
2889+
ScopedDependencyCondition sdc(ctx, p);
2890+
2891+
ctx.addLine("get_target_property(type " + p.target_name + " TYPE)");
2892+
ctx.if_("\"${type}\" STREQUAL STATIC_LIBRARY");
2893+
ctx.addLine("install(FILES $<TARGET_FILE:" + p.target_name + "> DESTINATION lib)");
2894+
ctx.else_();
2895+
ctx.addLine("install(FILES $<TARGET_FILE:" + p.target_name + "> DESTINATION bin)");
2896+
ctx.addLine("install(FILES $<TARGET_LINKER_FILE:" + p.target_name + "> DESTINATION lib)");
2897+
ctx.endif();
2898+
ctx.emptyLines();
2899+
}
28732900
}
28742901

28752902
file_footer(ctx, d);
@@ -2998,8 +3025,15 @@ endif()
29983025
ctx.addLine("set(vars_file \"${vars_dir}/${config}.cmake\")");
29993026
// helper will show match between config with gen and just config
30003027
ctx.addLine("set(vars_file_helper \"${vars_dir}//${config}.${config_dir}.cmake\")");
3001-
if (!d.flags[pfLocalProject])
3028+
// conditions actually are needed anymore with protection of once vars
3029+
if (!d.flags[pfLocalProject] || Settings::get_local_settings().install_local_packages)
3030+
{
3031+
ctx.if_("NOT CPPAN_READ_CHECK_VARS_FILE_ONCE");
3032+
//ctx.addLine("message(STATUS \"reading vars from ${vars_file}\")");
3033+
ctx.addLine("set_once_var(CPPAN_READ_CHECK_VARS_FILE_ONCE)");
30023034
ctx.addLine("read_check_variables_file(${vars_file})");
3035+
ctx.endif();
3036+
}
30033037
ctx.addLine();
30043038

30053039
ctx.if_("NOT DEFINED WORDS_BIGENDIAN");
@@ -3056,11 +3090,15 @@ endif()
30563090
p.checks.write_checks(ctx, p.checks_prefixes);
30573091

30583092
// write vars file
3059-
if (!d.flags[pfLocalProject])
3093+
// conditions actually are needed anymore with protection of once vars
3094+
if (!d.flags[pfLocalProject] || Settings::get_local_settings().install_local_packages)
30603095
{
30613096
ctx.if_("CPPAN_NEW_VARIABLE_ADDED");
3097+
//ctx.addLine("message(STATUS \"writing vars to ${vars_file}\")");
30623098
ctx.addLine("write_check_variables_file(${vars_file})");
30633099
ctx.addLine("file(WRITE ${vars_file_helper} \"\")");
3100+
ctx.addLine("set(CPPAN_NEW_VARIABLE_ADDED 0)");
3101+
//ctx.addLine("message(STATUS \"end of writing vars to ${vars_file}\")");
30643102
ctx.endif();
30653103
}
30663104

0 commit comments

Comments
 (0)