diff --git a/docs/cmake-toml.md b/docs/cmake-toml.md index 1c32d4f..607d11b 100644 --- a/docs/cmake-toml.md +++ b/docs/cmake-toml.md @@ -109,6 +109,13 @@ clang-any = "CMAKE_CXX_COMPILER_ID MATCHES \"Clang\" OR CMAKE_C_COMPILER_ID MATC root = "CMKR_ROOT_PROJECT" x64 = "CMAKE_SIZEOF_VOID_P EQUAL 8" x32 = "CMAKE_SIZEOF_VOID_P EQUAL 4" +android = "ANDROID" +apple = "APPLE" +bsd = "BSD" +cygwin = "CYGWIN" +ios = "IOS" +xcode = "XCODE" +wince = "WINCE" ``` ## Subdirectories diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index c086ecd..1918133 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -577,7 +577,7 @@ struct Generator { } cmd("if", "NOTE: unnamed condition")(RawArg(cmake_condition(condition))); } else { - cmd("if", condition)(RawArg(found->second)); + cmd("if", condition)(RawArg(cmake_condition(found->second))); } return true; } diff --git a/src/project_parser.cpp b/src/project_parser.cpp index 217252f..2e3d01b 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -274,6 +274,13 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p conditions["root"] = R"cmake(CMKR_ROOT_PROJECT)cmake"; conditions["x64"] = R"cmake(CMAKE_SIZEOF_VOID_P EQUAL 8)cmake"; conditions["x32"] = R"cmake(CMAKE_SIZEOF_VOID_P EQUAL 4)cmake"; + conditions["android"] = R"cmake(ANDROID)cmake"; + conditions["apple"] = R"cmake(APPLE)cmake"; + conditions["bsd"] = R"cmake(BSD)cmake"; + conditions["cygwin"] = R"cmake(CYGWIN)cmake"; + conditions["ios"] = R"cmake(IOS)cmake"; + conditions["xcode"] = R"cmake(XCODE)cmake"; + conditions["wince"] = R"cmake(WINCE)cmake"; } else { conditions = parent->conditions; templates = parent->templates; @@ -432,6 +439,9 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p } options.push_back(o); + // Add a condition matching the option name + conditions.emplace(o.name, o.name); + // Add an implicit condition for the option auto ncondition = normalize(o.name); if (ncondition.find(nproject_prefix) == 0) { @@ -870,9 +880,8 @@ bool Project::cmake_minimum_version(int major, int minor) const { } bool Project::is_condition_name(const std::string &name) { - auto is_named_condition = true; for (auto ch : name) { - if (!(ch == '-' || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z'))) { + if (!std::isalnum(ch) && ch != '-' && ch != '_') { return false; } }