Support more target_xxx commands

toml-checker
Duncan Ogilvie 4 years ago
parent a7bdb93830
commit b6d629b9f4

4
.gitignore vendored

@ -5,4 +5,6 @@ compile_commands.json
temp.*
.vs
.cache
build*/
build*/
.idea/
cmake-build*/

@ -38,6 +38,10 @@ add_library(cmkrlib STATIC ${cmkrlib_SOURCES})
source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${cmkrlib_SOURCES})
target_compile_features(cmkrlib PUBLIC
cxx_std_11
)
target_include_directories(cmkrlib PUBLIC
include
)
@ -49,10 +53,6 @@ target_link_libraries(cmkrlib PUBLIC
ordered_map
)
target_compile_features(cmkrlib PUBLIC
cxx_std_11
)
set(cmkr_SOURCES
src/main.cpp
cmake.toml

@ -196,21 +196,20 @@ CMake::CMake(const std::string &path, bool build) {
#undef renamed
if (t.contains("include-directories")) {
target.include_directories = detail::to_string_vec(toml::find(t, "include-directories").as_array());
}
if (t.contains("link-libraries")) {
target.link_libraries = detail::to_string_vec(toml::find(t, "link-libraries").as_array());
}
if (t.contains("compile-features")) {
target.compile_features = detail::to_string_vec(toml::find(t, "compile-features").as_array());
}
if (t.contains("compile-definitions")) {
target.compile_definitions = detail::to_string_vec(toml::find(t, "compile-definitions").as_array());
}
auto optional_array = [&t](const toml::key &k, std::vector<std::string> &v) {
if (t.contains(k)) {
v = detail::to_string_vec(toml::find(t, k).as_array());
}
};
optional_array("compile-definitions", target.compile_definitions);
optional_array("compile-features", target.compile_features);
optional_array("compile-options", target.compile_options);
optional_array("include-directories", target.include_directories);
optional_array("link-directories", target.link_directories);
optional_array("link-libraries", target.link_libraries);
optional_array("link-options", target.link_options);
optional_array("precompile-headers", target.precompile_headers);
if (t.contains("alias")) {
target.alias = toml::find(t, "alias").as_string();

@ -34,11 +34,18 @@ struct Package {
struct Target {
std::string name;
std::string type;
std::vector<std::string> sources;
std::vector<std::string> include_directories;
std::vector<std::string> compile_features;
// https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#project-commands
std::vector<std::string> compile_definitions;
std::vector<std::string> compile_features;
std::vector<std::string> compile_options;
std::vector<std::string> include_directories;
std::vector<std::string> link_directories;
std::vector<std::string> link_libraries;
std::vector<std::string> link_options;
std::vector<std::string> precompile_headers;
std::vector<std::string> sources;
std::string alias;
std::map<std::string, std::string> properties;
};

@ -436,21 +436,19 @@ int generate_cmake(const char *path) {
cmd("add_library")(target.alias, "ALIAS", target.name);
}
if (!target.include_directories.empty()) {
cmd("target_include_directories")(target.name, target_scope, target.include_directories).endl();
}
if (!target.link_libraries.empty()) {
cmd("target_link_libraries")(target.name, target_scope, target.link_libraries).endl();
}
if (!target.compile_features.empty()) {
cmd("target_compile_features")(target.name, target_scope, target.compile_features).endl();
}
if (!target.compile_definitions.empty()) {
cmd("target_compile_definitions")(target.name, target_scope, target.compile_definitions).endl();
}
auto target_cmd = [&](const char* command, const std::vector<std::string>& args) {
if(!args.empty()) {
cmd(command)(target.name, target_scope, args).endl();
}
};
target_cmd("target_compile_definitions", target.compile_definitions);
target_cmd("target_compile_features", target.compile_features);
target_cmd("target_compile_options", target.compile_options);
target_cmd("target_include_directories", target.include_directories);
target_cmd("target_link_directories", target.link_directories);
target_cmd("target_link_libraries", target.link_libraries);
target_cmd("target_precompile_headers", target.precompile_headers);
if (!target.properties.empty()) {
cmd("set_target_properties")(target.name, "PROPERTIES", target.properties).endl();

Loading…
Cancel
Save