mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9622334bf1 | |||
| 6ad29ef624 | |||
| 718c2c7527 | |||
| 8ea0c7396c | |||
| 34c12379c2 | |||
| 6395267e4b | |||
| 6d9b40bd15 | |||
| c4673d59e2 | |||
| 220dec6bbb | |||
| 4efa74f91f | |||
| fbd07c47bc | |||
| 17d4dc0555 | |||
| a6dfb2272d | |||
| 7fdafa4189 |
@@ -0,0 +1 @@
|
||||
CMakeLists.txt linguist-generated
|
||||
@@ -4,6 +4,8 @@ on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Skip building pull requests from the same repository
|
||||
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != '${{ github.repository }}'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -14,10 +16,18 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
|
||||
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} "-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install"
|
||||
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
|
||||
cmake --install build --config ${{ env.BUILD_TYPE }}
|
||||
|
||||
- name: Check if cmkr was run
|
||||
run: |
|
||||
./install/bin/cmkr gen
|
||||
git diff --exit-code
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
cd build/tests
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 0.1.4 - 2021-04-11
|
||||
- Use `GIT_SHALLOW ON` by default when getting git dependencies.
|
||||
- Add cmake.description field.
|
||||
- Change bin.defines to bin.definitions.
|
||||
|
||||
## 0.1.3 - 2020-11-27
|
||||
- Support building with C++11.
|
||||
- @mrexodia implemented CMake integration and bootstrapping.
|
||||
- Add dependency on ghc_filesystem and mpark_variant which are fetched automatically using FetchContent.
|
||||
|
||||
## 0.1.2 - 2020-11-20
|
||||
- Add support for target properties.
|
||||
- Add installs.
|
||||
- Require cmake >= 3.15.
|
||||
- Support settings and caching settings.
|
||||
- Support config when running cmkr build.
|
||||
- Add prompt prior to CMakeLists.txt generation if already existent in the current dir.
|
||||
|
||||
## 0.1.1 - 2020-11-19
|
||||
- Add support for globbing.
|
||||
- Add support for find_package components.
|
||||
- Add options.
|
||||
- Support aliases.
|
||||
- Support interface libs (header-only libs).
|
||||
- Support testing.
|
||||
Generated
+39
-52
@@ -1,5 +1,5 @@
|
||||
# This file is automatically generated from cmake.toml - DO NOT EDIT
|
||||
# See https://github.com/MoAlyousef/cmkr for more information
|
||||
# See https://github.com/build-cpp/cmkr for more information
|
||||
|
||||
cmake_minimum_required(VERSION 2.8...3.8)
|
||||
|
||||
@@ -23,10 +23,6 @@ if(CMKR_ROOT_PROJECT)
|
||||
configure_file(cmake.toml cmake.toml COPYONLY)
|
||||
endif()
|
||||
|
||||
# Hack to hide a warning during cmkr bootstrapping on Windows
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
|
||||
project(cmkr
|
||||
LANGUAGES
|
||||
CXX
|
||||
@@ -57,62 +53,40 @@ add_subdirectory(tests)
|
||||
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
|
||||
|
||||
|
||||
# Target cmkrlib
|
||||
unset(cmkrlib_SOURCES)
|
||||
|
||||
list(APPEND cmkrlib_SOURCES
|
||||
"src/cmkrlib/args.cpp"
|
||||
"src/cmkrlib/build.cpp"
|
||||
"src/cmkrlib/cmake.cpp"
|
||||
"src/cmkrlib/error.cpp"
|
||||
"src/cmkrlib/gen.cpp"
|
||||
"src/cmkrlib/help.cpp"
|
||||
"src/cmkrlib/cmake.hpp"
|
||||
"src/cmkrlib/enum_helper.hpp"
|
||||
"src/cmkrlib/fs.hpp"
|
||||
"include/args.h"
|
||||
"include/build.h"
|
||||
"include/error.h"
|
||||
"include/gen.h"
|
||||
"include/help.h"
|
||||
"include/literals.h"
|
||||
)
|
||||
|
||||
list(APPEND cmkrlib_SOURCES
|
||||
cmake.toml
|
||||
)
|
||||
|
||||
add_library(cmkrlib STATIC ${cmkrlib_SOURCES})
|
||||
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${cmkrlib_SOURCES})
|
||||
|
||||
target_compile_features(cmkrlib PUBLIC
|
||||
cxx_std_11
|
||||
)
|
||||
|
||||
target_include_directories(cmkrlib PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(cmkrlib PUBLIC
|
||||
toml11
|
||||
ghc_filesystem
|
||||
mpark_variant
|
||||
ordered_map
|
||||
)
|
||||
|
||||
# Target cmkr
|
||||
unset(cmkr_SOURCES)
|
||||
set(CMKR_TARGET cmkr)
|
||||
set(cmkr_SOURCES "")
|
||||
|
||||
list(APPEND cmkr_SOURCES
|
||||
"src/args.cpp"
|
||||
"src/build.cpp"
|
||||
"src/cmake.cpp"
|
||||
"src/error.cpp"
|
||||
"src/gen.cpp"
|
||||
"src/help.cpp"
|
||||
"src/main.cpp"
|
||||
"include/args.hpp"
|
||||
"include/build.hpp"
|
||||
"include/cmake.hpp"
|
||||
"include/enum_helper.hpp"
|
||||
"include/error.hpp"
|
||||
"include/fs.hpp"
|
||||
"include/gen.hpp"
|
||||
"include/help.hpp"
|
||||
"include/literals.hpp"
|
||||
)
|
||||
|
||||
list(APPEND cmkr_SOURCES
|
||||
cmake.toml
|
||||
)
|
||||
|
||||
add_executable(cmkr ${cmkr_SOURCES})
|
||||
set(CMKR_SOURCES ${cmkr_SOURCES})
|
||||
add_executable(cmkr)
|
||||
|
||||
if(cmkr_SOURCES)
|
||||
target_sources(cmkr PRIVATE ${cmkr_SOURCES})
|
||||
endif()
|
||||
|
||||
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
|
||||
if(NOT CMKR_VS_STARTUP_PROJECT)
|
||||
@@ -121,10 +95,23 @@ endif()
|
||||
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${cmkr_SOURCES})
|
||||
|
||||
target_link_libraries(cmkr PRIVATE
|
||||
cmkrlib
|
||||
target_compile_features(cmkr PRIVATE
|
||||
cxx_std_11
|
||||
)
|
||||
|
||||
target_include_directories(cmkr PRIVATE
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(cmkr PRIVATE
|
||||
toml11
|
||||
ghc_filesystem
|
||||
mpark_variant
|
||||
ordered_map
|
||||
)
|
||||
|
||||
unset(CMKR_TARGET)
|
||||
unset(CMKR_SOURCES)
|
||||
install(
|
||||
TARGETS
|
||||
cmkr
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
# cmkr
|
||||
|
||||
cmkr, pronounced "cmaker", is A CMakeLists.txt generator from TOML.
|
||||
cmkr, pronounced "cmaker", is a modern build system based on CMake and TOML. It was originally created by [Mohammed Alyousef](https://github.com/MoAlyousef).
|
||||
|
||||
See the [cmkr topic](https://github.com/topics/cmkr) for examples. Feel free to add the `cmkr` topic to your projects if you used cmkr!
|
||||
**NOTE**: The documentation is currently a work-in-progress due to breaking changes since `0.1.4`. For examples you can check the [cmkr GitHub topic](https://github.com/topics/cmkr) and the [tests](https://github.com/build-cpp/cmkr/tree/main/tests).
|
||||
|
||||
## Building
|
||||
## Getting started
|
||||
|
||||
cmkr requires a C++11 compiler, cmake >= 3.15.
|
||||
|
||||
```
|
||||
git clone https://github.com/moalyousef/cmkr
|
||||
cd cmkr
|
||||
cmake -Bbin
|
||||
cmake --build bin --parallel
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
cmkr parses cmake.toml files (using toml11 by Toru Niina) at the project directory. A basic hello world format with the minimum required fields:
|
||||
`cmkr` parses `cmake.toml` files and generates a modern, idomatic `CMakeLists.txt` for you. A basic hello world format with the minimum required fields:
|
||||
|
||||
```toml
|
||||
[cmake]
|
||||
@@ -32,9 +21,20 @@ type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
```
|
||||
|
||||
**NOTE**: The documentation is currently a work-in-progress due to breaking changes since `0.1.4`. For examples you can check the [cmkr topic](https://github.com/topics/cmkr).
|
||||
## Building
|
||||
|
||||
The cmkr executable can be run from the command-line:
|
||||
`cmkr` requires a C++11 compiler and CMake >= ~3.x (exact minimum version is not yet specified). C++11 was picked to allow the broadest possible set of compilers to bootstrap `cmkr`.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/moalyousef/cmkr
|
||||
cd cmkr
|
||||
cmake -Bbin
|
||||
cmake --build bin --parallel
|
||||
```
|
||||
|
||||
## Command line
|
||||
|
||||
The `cmkr` executable can be run from the command-line:
|
||||
|
||||
```
|
||||
Usage: cmkr [arguments]
|
||||
@@ -48,34 +48,8 @@ arguments:
|
||||
version Current cmkr version.
|
||||
```
|
||||
|
||||
The build command invokes cmake and the default build-system on your platform (unless a generator is specified), it also accepts extra cmake build arguments:
|
||||
The build command invokes `cmake` and the default build-system on your platform (unless a generator is specified), it also accepts extra build arguments:
|
||||
|
||||
```
|
||||
```sh
|
||||
cmkr build --config Release
|
||||
```
|
||||
|
||||
## Binary types
|
||||
|
||||
### executable
|
||||
|
||||
Executable binary. Equivalent to [add_executable(name)](https://cmake.org/cmake/help/latest/command/add_executable.html).
|
||||
|
||||
### library
|
||||
|
||||
Library, can be static or shared depending on the BUILD_SHARED_LIBS variable. Equivalent to [add_library()](https://cmake.org/cmake/help/latest/command/add_library.html).
|
||||
|
||||
### static
|
||||
|
||||
Static library/archive. Equivalent to [add_library(name STATIC)](https://cmake.org/cmake/help/latest/command/add_library.html).
|
||||
|
||||
### shared
|
||||
|
||||
Shared/dynamic library. Equivalent to [add_library(name SHARED)](https://cmake.org/cmake/help/latest/command/add_library.html).
|
||||
|
||||
### interface
|
||||
|
||||
Header-only library. Equivalent to [add_library(name INTERFACE)](https://cmake.org/cmake/help/latest/command/add_library.html).
|
||||
|
||||
## Roadmap
|
||||
|
||||
- Support more cmake fields.
|
||||
|
||||
+3
-13
@@ -2,29 +2,19 @@
|
||||
version = "2.8...3.8"
|
||||
|
||||
[project]
|
||||
cmake-before = """
|
||||
# Hack to hide a warning during cmkr bootstrapping on Windows
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
"""
|
||||
name = "cmkr"
|
||||
version = "0.1.4"
|
||||
description = "CMakeLists generator from TOML"
|
||||
languages = ["CXX"]
|
||||
subdirs = ["third_party", "tests"]
|
||||
|
||||
[target.cmkrlib]
|
||||
type = "static"
|
||||
sources = ["src/cmkrlib/*.cpp", "src/cmkrlib/*.hpp", "include/*.h"]
|
||||
[target.cmkr]
|
||||
type = "executable"
|
||||
sources = ["src/*.cpp", "include/*.hpp"]
|
||||
include-directories = ["include"]
|
||||
compile-features = ["cxx_std_11"]
|
||||
link-libraries = ["toml11", "ghc_filesystem", "mpark_variant", "ordered_map"]
|
||||
|
||||
[target.cmkr]
|
||||
type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
link-libraries = ["cmkrlib"]
|
||||
|
||||
[[install]]
|
||||
targets = ["cmkr"]
|
||||
destination = "${CMAKE_INSTALL_PREFIX}/bin"
|
||||
|
||||
+3
-2
@@ -1,8 +1,8 @@
|
||||
include_guard()
|
||||
|
||||
# Change these defaults to point to your infrastructure if desired
|
||||
set(CMKR_REPO "https://github.com/MoAlyousef/cmkr" CACHE STRING "cmkr git repository" FORCE)
|
||||
set(CMKR_TAG "archive_7b7b2603" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
|
||||
set(CMKR_TAG "archive_7cdf36f3" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
|
||||
# Set these from the command line to customize for development/debugging purposes
|
||||
set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")
|
||||
@@ -78,6 +78,7 @@ else()
|
||||
)
|
||||
message(STATUS "[cmkr] Building cmkr...")
|
||||
cmkr_exec("${CMAKE_COMMAND}"
|
||||
--no-warn-unused-cli
|
||||
"${CMKR_DIRECTORY}"
|
||||
"-B${CMKR_DIRECTORY}/build"
|
||||
"-DCMAKE_BUILD_TYPE=Release"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr {
|
||||
namespace args {
|
||||
|
||||
@@ -9,11 +8,4 @@ const char *handle_args(int argc, char **argv);
|
||||
} // namespace args
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *cmkr_args_handle_args(int, char **);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cmkr {
|
||||
namespace build {
|
||||
|
||||
@@ -13,15 +11,9 @@ int install();
|
||||
|
||||
} // namespace build
|
||||
} // namespace cmkr
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int cmkr_build_run(int argc, char **argv);
|
||||
|
||||
int cmkr_build_clean(void);
|
||||
int cmkr_build_clean();
|
||||
|
||||
int cmkr_build_install(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
int cmkr_build_install();
|
||||
@@ -98,7 +98,7 @@ struct CMake {
|
||||
std::string build_dir = "build";
|
||||
std::string generator;
|
||||
std::string config;
|
||||
std::vector<std::string> subdirs;
|
||||
Condition<std::vector<std::string>> subdirs;
|
||||
std::vector<std::string> cppflags;
|
||||
std::vector<std::string> cflags;
|
||||
std::vector<std::string> linkflags;
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr {
|
||||
namespace error {
|
||||
|
||||
@@ -25,11 +24,4 @@ struct Status {
|
||||
} // namespace error
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *cmkr_error_status_string(int);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr {
|
||||
namespace gen {
|
||||
|
||||
@@ -11,13 +10,6 @@ int generate_cmake(const char *path, bool root = true);
|
||||
} // namespace gen
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int cmkr_gen_generate_project(const char *typ);
|
||||
|
||||
int cmkr_gen_generate_cmake(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr {
|
||||
namespace help {
|
||||
|
||||
@@ -11,13 +10,6 @@ const char *message() noexcept;
|
||||
} // namespace help
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *cmkr_help_version(void);
|
||||
|
||||
const char *cmkr_help_message(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -30,8 +30,7 @@ version = "0.1.0"
|
||||
|
||||
# [options]
|
||||
|
||||
[[target]]
|
||||
name = "%s"
|
||||
[target.%s]
|
||||
type = "%s"
|
||||
sources = ["src/*.cpp"]
|
||||
include-directories = ["include"]
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "args.h"
|
||||
#include "build.h"
|
||||
#include "gen.h"
|
||||
#include "help.h"
|
||||
#include "args.hpp"
|
||||
#include "build.hpp"
|
||||
#include "gen.hpp"
|
||||
#include "help.hpp"
|
||||
|
||||
#include "fs.hpp"
|
||||
#include <exception>
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "build.h"
|
||||
#include "build.hpp"
|
||||
#include "cmake.hpp"
|
||||
#include "error.h"
|
||||
#include "gen.h"
|
||||
#include "error.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
#include "fs.hpp"
|
||||
#include <sstream>
|
||||
@@ -16,7 +16,7 @@ namespace build {
|
||||
int run(int argc, char **argv) {
|
||||
cmake::CMake cmake(".", true);
|
||||
if (argc > 2) {
|
||||
for (size_t i = 2; i < argc; ++i) {
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
cmake.build_args.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
@@ -259,10 +259,11 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
}
|
||||
|
||||
// Reasonable default conditions (you can override these if you desire)
|
||||
conditions["win32"] = conditions["windows"] = conditions["win"] = "WIN32";
|
||||
conditions["macos"] = conditions["macosx"] = conditions["osx"] = conditions["mac"] = R"cond("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")cond";
|
||||
conditions["unix"] = "UNIX";
|
||||
conditions["linux"] = R"cond("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")cond";
|
||||
conditions["windows"] = R"cmake(WIN32)cmake";
|
||||
conditions["macos"] = R"cmake("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")cmake";
|
||||
conditions["unix"] = R"cmake(UNIX)cmake";
|
||||
conditions["bsd"] = R"cmake("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")cmake";
|
||||
conditions["linux"] = conditions["lunix"] = R"cmake("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")cmake";
|
||||
|
||||
if (toml.contains("conditions")) {
|
||||
auto conds = toml::find<decltype(conditions)>(toml, "conditions");
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "error.h"
|
||||
#include "error.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "gen.h"
|
||||
#include "gen.hpp"
|
||||
#include "cmake.hpp"
|
||||
#include "error.h"
|
||||
#include "literals.h"
|
||||
#include "error.hpp"
|
||||
#include "literals.hpp"
|
||||
|
||||
#include "fs.hpp"
|
||||
#include <cassert>
|
||||
@@ -390,7 +390,9 @@ struct Generator {
|
||||
cmd("if")(RawArg(cmake.conditions[condition]));
|
||||
}
|
||||
|
||||
fn(condition, itr.second);
|
||||
if (!itr.second.empty()) {
|
||||
fn(condition, itr.second);
|
||||
}
|
||||
|
||||
if (!condition.empty()) {
|
||||
cmd("endif")();
|
||||
@@ -418,7 +420,7 @@ int generate_cmake(const char *path, bool root) {
|
||||
auto inject_cmake = [&gen](const std::string &cmake) { gen.inject_cmake(cmake); };
|
||||
|
||||
comment("This file is automatically generated from cmake.toml - DO NOT EDIT");
|
||||
comment("See https://github.com/MoAlyousef/cmkr for more information");
|
||||
comment("See https://github.com/build-cpp/cmkr for more information");
|
||||
endl();
|
||||
|
||||
if (root) {
|
||||
@@ -573,25 +575,30 @@ int generate_cmake(const char *path, bool root) {
|
||||
|
||||
// generate_cmake is called on the subdirectories recursively later
|
||||
if (!cmake.subdirs.empty()) {
|
||||
for (const auto &dir : cmake.subdirs) {
|
||||
// clang-format off
|
||||
comment(dir);
|
||||
cmd("set")("CMKR_CMAKE_FOLDER", "${CMAKE_FOLDER}");
|
||||
cmd("if")("CMAKE_FOLDER");
|
||||
cmd("set")("CMAKE_FOLDER", "${CMAKE_FOLDER}/" + dir);
|
||||
cmd("else")();
|
||||
cmd("set")("CMAKE_FOLDER", dir);
|
||||
cmd("endif")();
|
||||
// clang-format on
|
||||
cmd("add_subdirectory")(dir);
|
||||
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
||||
}
|
||||
gen.handle_condition(cmake.subdirs, [&](const std::string &, const std::vector<std::string> &subdirs) {
|
||||
for (const auto &dir : subdirs) {
|
||||
// clang-format off
|
||||
comment(dir);
|
||||
cmd("set")("CMKR_CMAKE_FOLDER", "${CMAKE_FOLDER}");
|
||||
cmd("if")("CMAKE_FOLDER");
|
||||
cmd("set")("CMAKE_FOLDER", "${CMAKE_FOLDER}/" + dir);
|
||||
cmd("else")();
|
||||
cmd("set")("CMAKE_FOLDER", dir);
|
||||
cmd("endif")();
|
||||
// clang-format on
|
||||
|
||||
cmd("add_subdirectory")(dir);
|
||||
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
||||
}
|
||||
});
|
||||
endl();
|
||||
}
|
||||
|
||||
if (!cmake.targets.empty()) {
|
||||
for (const auto &target : cmake.targets) {
|
||||
comment("Target " + target.name);
|
||||
cmd("set")("CMKR_TARGET", target.name);
|
||||
|
||||
gen.handle_condition(target.include_before,
|
||||
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
gen.handle_condition(target.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
@@ -599,7 +606,7 @@ int generate_cmake(const char *path, bool root) {
|
||||
auto sources_var = target.name + "_SOURCES";
|
||||
|
||||
bool added_toml = false;
|
||||
cmd("unset")(sources_var).endl();
|
||||
cmd("set")(sources_var, RawArg("\"\"")).endl();
|
||||
gen.handle_condition(target.sources, [&](const std::string &condition, const std::vector<std::string> &condition_sources) {
|
||||
auto sources = expand_cmake_paths(condition_sources, path);
|
||||
if (sources.empty()) {
|
||||
@@ -616,6 +623,7 @@ int generate_cmake(const char *path, bool root) {
|
||||
if (!added_toml && target.type != cmake::target_interface) {
|
||||
cmd("list")("APPEND", sources_var, std::vector<std::string>{"cmake.toml"}).endl();
|
||||
}
|
||||
cmd("set")("CMKR_SOURCES", "${" + sources_var + "}");
|
||||
|
||||
std::string add_command;
|
||||
std::string target_type;
|
||||
@@ -656,7 +664,13 @@ int generate_cmake(const char *path, bool root) {
|
||||
assert("Unimplemented enum value" && false);
|
||||
}
|
||||
|
||||
cmd(add_command)(target.name, target_type, "${" + target.name + "_SOURCES}").endl();
|
||||
cmd(add_command)(target.name, target_type).endl();
|
||||
|
||||
// clang-format off
|
||||
cmd("if")(sources_var);
|
||||
cmd("target_sources")(target.name, target.type == cmake::target_interface ? "INTERFACE" : "PRIVATE", "${" + sources_var + "}");
|
||||
cmd("endif")().endl();
|
||||
// clang-format on
|
||||
|
||||
// The first executable target will become the Visual Studio startup project
|
||||
if (target.type == cmake::target_executable) {
|
||||
@@ -696,6 +710,9 @@ int generate_cmake(const char *path, bool root) {
|
||||
gen.handle_condition(target.include_after,
|
||||
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
gen.handle_condition(target.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
|
||||
cmd("unset")("CMKR_TARGET");
|
||||
cmd("unset")("CMKR_SOURCES");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,10 +772,12 @@ int generate_cmake(const char *path, bool root) {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &sub : cmake.subdirs) {
|
||||
auto subpath = fs::path(path) / fs::path(sub);
|
||||
if (fs::exists(subpath / "cmake.toml"))
|
||||
generate_cmake(subpath.string().c_str(), false);
|
||||
for (const auto &itr : cmake.subdirs) {
|
||||
for (const auto &sub : itr.second) {
|
||||
auto subpath = fs::path(path) / fs::path(sub);
|
||||
if (fs::exists(subpath / "cmake.toml"))
|
||||
generate_cmake(subpath.string().c_str(), false);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "help.h"
|
||||
#include "help.hpp"
|
||||
|
||||
namespace cmkr {
|
||||
namespace help {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "args.h"
|
||||
#include "args.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
Generated
+11
-1
@@ -1,5 +1,5 @@
|
||||
# This file is automatically generated from cmake.toml - DO NOT EDIT
|
||||
# See https://github.com/MoAlyousef/cmkr for more information
|
||||
# See https://github.com/build-cpp/cmkr for more information
|
||||
|
||||
# Create a configure-time dependency on cmake.toml to improve IDE support
|
||||
if(CMKR_ROOT_PROJECT)
|
||||
@@ -28,3 +28,13 @@ add_test(
|
||||
build
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME
|
||||
interface
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_LIST_DIR}/interface"
|
||||
COMMAND
|
||||
$<TARGET_FILE:cmkr>
|
||||
build
|
||||
)
|
||||
|
||||
|
||||
@@ -8,4 +8,10 @@ arguments = ["build"]
|
||||
name = "conditions"
|
||||
command = "$<TARGET_FILE:cmkr>"
|
||||
working-directory = "${CMAKE_CURRENT_LIST_DIR}/conditions"
|
||||
arguments = ["build"]
|
||||
|
||||
[[test]]
|
||||
name = "interface"
|
||||
command = "$<TARGET_FILE:cmkr>"
|
||||
working-directory = "${CMAKE_CURRENT_LIST_DIR}/interface"
|
||||
arguments = ["build"]
|
||||
@@ -8,10 +8,10 @@ custom = "CUSTOM"
|
||||
[target.example]
|
||||
type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
win32.sources = ["src/win32.cpp"]
|
||||
windows.sources = ["src/windows_specific.cpp"]
|
||||
cmake-after = "message(STATUS cmake-after)"
|
||||
win32.cmake-after = "message(STATUS win32-after)"
|
||||
unix.cmake-after = "message(STATUS unix-after)"
|
||||
windows.cmake-after = "message(STATUS win32-after)"
|
||||
macos.cmake-after = "message(STATUS macos-after)"
|
||||
custom.cmake-after = "message(STATUS custom-after)"
|
||||
linux.cmake-after = "message(STATUS linux-after)"
|
||||
linux.cmake-after = "message(STATUS linux-after)"
|
||||
unix.cmake-after = "message(STATUS unix-after)"
|
||||
custom.cmake-after = "message(STATUS custom-after)"
|
||||
@@ -0,0 +1,11 @@
|
||||
[project]
|
||||
name = "interface"
|
||||
|
||||
[target.mylib]
|
||||
type = "interface"
|
||||
include-directories = ["include"]
|
||||
|
||||
[target.example]
|
||||
type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
link-libraries = ["mylib"]
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace mylib
|
||||
{
|
||||
static const char* version() { return "v1.0"; }
|
||||
} // namespace mylib
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "mylib/mylib.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("mylib version: %s\n", mylib::version())
|
||||
}
|
||||
Reference in New Issue
Block a user