Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cppship/cmake/bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class CmakeBin {
BinDesc mDesc;
};

}
}
6 changes: 3 additions & 3 deletions include/cppship/cmake/dep.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include "cppship/core/dependency.h"

#include <string>
#include <vector>

#include "cppship/core/dependency.h"

namespace cppship::cmake {

struct Dep {
Expand All @@ -16,4 +16,4 @@ struct Dep {
std::vector<Dep> resolve_deps(
const std::vector<DeclaredDependency>& declared_deps, const ResolvedDependencies& resolved);

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmake/dependency_injector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class CmakeDependencyInjector : public DependencyInjector {
ResolvedDependencies mAllDeps;
};

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmake/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ class CmakeGenerator {
std::set<std::string> mTestTargets;
};

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmake/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ class CmakeLib {
std::vector<std::string> mDefinitions;
};

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmake/msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ namespace cppship::msvc {
// msvc generator has different binary path, fix it
fs::path fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_view bin);

}
}
6 changes: 3 additions & 3 deletions include/cppship/cmake/package_configurer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "cppship/core/dependency.h"

#include <functional>

#include "cppship/core/dependency.h"

namespace cppship::cmake {

struct ConfigOptions {
Expand All @@ -17,4 +17,4 @@ struct ConfigOptions {
void config_packages(
const ResolvedDependencies& cppship_deps, const ResolvedDependencies& all_deps, const ConfigOptions& options);

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmd/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ void cmake_setup(const BuildContext& ctx);

int cmake_build(const BuildContext& ctx, const BuildOptions& options);

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmd/cmake.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ struct CmakeOptions { };

int run_cmake(const CmakeOptions& options);

}
}
2 changes: 1 addition & 1 deletion include/cppship/cmd/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ struct InitOptions {

int run_init(const InitOptions& options);

}
}
3 changes: 2 additions & 1 deletion include/cppship/cmd/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace cppship::cmd {

struct InstallOptions {
Profile profile = Profile::debug;
std::string root;
};

int run_install(const InstallOptions& options);

}
}
2 changes: 1 addition & 1 deletion include/cppship/core/dependency.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <map>
#include <string>
#include <string_view>
#include <toml/value.hpp>
#include <variant>
#include <vector>

#include <fmt/core.h>
#include <range/v3/view/map.hpp>
#include <toml.hpp>
#include <toml/value.hpp>

#include "cppship/util/assert.h"
#include "cppship/util/fs.h"
Expand Down
2 changes: 1 addition & 1 deletion include/cppship/core/manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ class Manifest {

void generate_manifest(std::string_view name, CxxStd std, const fs::path& dir);

}
}
2 changes: 1 addition & 1 deletion include/cppship/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ struct ProfileOptions {
std::vector<ConditionConfig> conditional_configs;
};

}
}
11 changes: 6 additions & 5 deletions include/cppship/core/resolver.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once

#include "cppship/core/dependency.h"
#include "cppship/core/manifest.h"

#include <functional>
#include <gsl/pointers>
#include <queue>
#include <set>
#include <vector>

#include <gsl/pointers>

#include "cppship/core/dependency.h"
#include "cppship/core/manifest.h"

namespace cppship {

struct ResolveResult {
Expand Down Expand Up @@ -45,4 +46,4 @@ class Resolver {
std::set<std::string> mPackageSeen;
};

}
}
2 changes: 1 addition & 1 deletion include/cppship/util/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ inline void enforce(bool expr, std::string_view msg)
}
}

}
}
12 changes: 4 additions & 8 deletions include/cppship/util/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ class ScopedCurrentDir {
fs::path mPrevCwd;
};

inline void create_if_not_exist(const fs::path& path)
{
if (fs::exists(path)) {
return;
}
void create_if_not_exist(const fs::path& path);

fs::create_directory(path);
}
inline constexpr std::string_view kCppShipDirName = ".cppship";
fs::path get_cppship_dir();

}
}
2 changes: 1 addition & 1 deletion include/cppship/util/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ std::string read_as_string(const fs::path& file);

std::string read_as_string(std::istream& iss);

}
}
19 changes: 10 additions & 9 deletions lib/cmake/generator.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#include "cppship/cmake/generator.h"
#include "cppship/cmake/bin.h"
#include "cppship/cmake/cfg_predicate.h"
#include "cppship/cmake/dep.h"
#include "cppship/cmake/group.h"
#include "cppship/cmake/lib.h"
#include "cppship/cmake/naming.h"
#include "cppship/core/manifest.h"
#include "cppship/exception.h"

#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand All @@ -19,6 +11,15 @@
#include <range/v3/view/concat.hpp>
#include <range/v3/view/transform.hpp>

#include "cppship/cmake/bin.h"
#include "cppship/cmake/cfg_predicate.h"
#include "cppship/cmake/dep.h"
#include "cppship/cmake/group.h"
#include "cppship/cmake/lib.h"
#include "cppship/cmake/naming.h"
#include "cppship/core/manifest.h"
#include "cppship/exception.h"

using namespace ranges::views;

using namespace cppship;
Expand Down Expand Up @@ -460,4 +461,4 @@ void CmakeGenerator::fill_profile_(Profile profile)
appender.output(profile_str, config, "\t");
mOut << "endif()\n\n";
}
}
}
5 changes: 3 additions & 2 deletions lib/cmake/msvc.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "cppship/cmake/msvc.h"
#include "cppship/util/io.h"

#include <boost/algorithm/string.hpp>

#include "cppship/util/io.h"

using namespace cppship;

fs::path msvc::fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_view bin)
Expand All @@ -13,4 +14,4 @@ fs::path msvc::fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_v
}

return bin;
}
}
13 changes: 8 additions & 5 deletions lib/cmake/package_configurer.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "cppship/cmake/package_configurer.h"

#include <fmt/core.h>
#include <fmt/format.h>

#include "cppship/cmake/lib.h"
#include "cppship/core/layout.h"
#include "cppship/core/manifest.h"
#include "cppship/util/io.h"
#include "cppship/util/repo.h"

#include <fmt/core.h>
#include <fmt/format.h>

using namespace cppship;
using namespace fmt::literals;

Expand All @@ -27,7 +28,9 @@ void cmake::config_packages(
add_library({target} INTERFACE IMPORTED)
target_include_directories({target} INTERFACE {cmake_deps_dir}/{package}/include)
)",
"target"_a = cmake_target, "package"_a = dep.package, "cmake_deps_dir"_a = options.cmake_deps_dir));
"target"_a = cmake_target,
"package"_a = dep.package,
"cmake_deps_dir"_a = options.cmake_deps_dir));

continue;
}
Expand Down Expand Up @@ -56,4 +59,4 @@ target_include_directories({target} INTERFACE {cmake_deps_dir}/{package}/include

write(package_cmake_config_file, content);
}
}
}
5 changes: 3 additions & 2 deletions lib/cmd/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "cppship/cmd/bench.h"

#include <cstdlib>

#include <boost/process/system.hpp>
Expand All @@ -8,7 +10,6 @@

#include "cppship/cmake/msvc.h"
#include "cppship/cmake/naming.h"
#include "cppship/cmd/bench.h"
#include "cppship/cmd/build.h"
#include "cppship/core/manifest.h"
#include "cppship/util/fs.h"
Expand Down Expand Up @@ -64,4 +65,4 @@ int cmd::run_bench(const BenchOptions& options)
}

return result;
}
}
45 changes: 27 additions & 18 deletions lib/cmd/build.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
#include "cppship/cmd/build.h"
#include "cppship/cmake/generator.h"
#include "cppship/cmake/group.h"
#include "cppship/cmake/package_configurer.h"
#include "cppship/core/compiler.h"
#include "cppship/core/dependency.h"
#include "cppship/core/resolver.h"
#include "cppship/exception.h"
#include "cppship/util/cmd.h"
#include "cppship/util/fs.h"
#include "cppship/util/git.h"
#include "cppship/util/io.h"
#include "cppship/util/log.h"

#include <fstream>
#include <sstream>
Expand All @@ -29,6 +17,19 @@
#include <spdlog/spdlog.h>
#include <toml.hpp>

#include "cppship/cmake/generator.h"
#include "cppship/cmake/group.h"
#include "cppship/cmake/package_configurer.h"
#include "cppship/core/compiler.h"
#include "cppship/core/dependency.h"
#include "cppship/core/resolver.h"
#include "cppship/exception.h"
#include "cppship/util/cmd.h"
#include "cppship/util/fs.h"
#include "cppship/util/git.h"
#include "cppship/util/io.h"
#include "cppship/util/log.h"

using namespace cppship;
using namespace boost::process;
using namespace fmt::literals;
Expand Down Expand Up @@ -181,8 +182,10 @@ void cmd::conan_install(const BuildContext& ctx)
return;
}

const auto cmd = fmt::format("conan install {} -of {}/conan -pr {} --build=missing", ctx.build_dir.string(),
ctx.profile_dir.string(), ctx.conan_profile_path.string());
const auto cmd = fmt::format("conan install {} -of {}/conan -pr {} --build=missing",
ctx.build_dir.string(),
ctx.profile_dir.string(),
ctx.conan_profile_path.string());

status("dependency", "install dependencies: {}", cmd);
int res = run_cmd(cmd);
Expand Down Expand Up @@ -233,7 +236,8 @@ void cmd::cmake_setup(const BuildContext& ctx)
const auto result = std::move(resolver).resolve();

ResolvedDependencies deps = toml::get<ResolvedDependencies>(toml::parse(ctx.dependency_file));
CmakeGenerator gen(&ctx.layout, ctx.manifest,
CmakeGenerator gen(&ctx.layout,
ctx.manifest,
GeneratorOptions {
.deps = cmake::resolve_deps(result.dependencies, deps),
.dev_deps = cmake::resolve_deps(result.dev_dependencies, deps),
Expand All @@ -242,7 +246,10 @@ void cmd::cmake_setup(const BuildContext& ctx)

const std::string cmd = fmt::format("cmake -B {} -S build -DCMAKE_BUILD_TYPE={} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "
"-DCONAN_GENERATORS_FOLDER={} -DCPPSHIP_DEPS_DIR={}",
ctx.profile_dir.string(), ctx.profile, (ctx.profile_dir / "conan").string(), ctx.deps_dir.string());
ctx.profile_dir.string(),
ctx.profile,
(ctx.profile_dir / "conan").string(),
ctx.deps_dir.string());

status("config", "config cmake: {}", cmd);
const int res = run_cmd(cmd);
Expand Down Expand Up @@ -291,7 +298,9 @@ std::string_view to_cmake_group(cmd::BuildGroup group, const std::string_view li

int cmd::cmake_build(const BuildContext& ctx, const BuildOptions& options)
{
auto cmd = fmt::format("cmake --build {} -j {} --config {}", ctx.profile_dir.string(), options.max_concurrency,
auto cmd = fmt::format("cmake --build {} -j {} --config {}",
ctx.profile_dir.string(),
options.max_concurrency,
to_string(options.profile));
if (options.target) {
cmd += fmt::format(" --target {}", *options.target);
Expand All @@ -305,4 +314,4 @@ int cmd::cmake_build(const BuildContext& ctx, const BuildOptions& options)

status("build", "{}", cmd);
return run_cmd(cmd);
}
}
Loading