Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ongoing development #6

Merged
merged 47 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
eaa5e62
Rename various options to match CMake's naming better and refactor
mrexodia Nov 30, 2020
f929cf5
Recursively iterate directories
mrexodia Mar 5, 2021
173c5e0
Restructure project
mrexodia Mar 5, 2021
00969ee
WIP DSL for generating cmake
mrexodia Mar 12, 2021
0e2cddc
Add support for include-before and include-after
mrexodia Mar 16, 2021
f4ef95e
Add inject-before and inject-after
mrexodia Mar 16, 2021
bd36e67
Change to vendored dependencies instead of using FetchContent
mrexodia Mar 16, 2021
f905440
Preserve ordering and switch target syntax to use tables
mrexodia Mar 16, 2021
ad3869d
Emit add_subdirectory calls after the project but before the targets
mrexodia Mar 16, 2021
a7bdb93
Require a lower CMake version for compatibility with slow distros
mrexodia Mar 16, 2021
b6d629b
Support more target_xxx commands
mrexodia Mar 18, 2021
fdd9a3d
Improve CMakeLists.txt generation to not touch the file when there ar…
mrexodia Mar 19, 2021
7828461
Minor improvements to property ordering
mrexodia Mar 25, 2021
f9de5c6
Differentiate between root and subdirectory generation
mrexodia Mar 25, 2021
db4e710
Fix source_group with subdirectories and move add_subdirectory calls …
mrexodia Mar 25, 2021
f32ea49
Support inject and include for targets
mrexodia Mar 30, 2021
6000629
Properly quote CMake command arguments with the wrapper
mrexodia Mar 30, 2021
028e202
Rename inject-after/before to cmake-after/before
mrexodia Mar 31, 2021
7f34921
Automatically generate folder names for subdirs
mrexodia Mar 31, 2021
1e8b756
Move target type handling to an enum for refactor
mrexodia Mar 31, 2021
461f26d
Bugfixes
mrexodia Mar 31, 2021
d89baa4
Fix custom target support
mrexodia Mar 31, 2021
206c658
Simplify toml deserialization a lot
mrexodia Mar 31, 2021
105e0aa
Add support for project.description and project.languages
mrexodia Mar 31, 2021
5c7f6c9
Clean up command generation
mrexodia Mar 31, 2021
1af0b5f
Add supporrt for cmkr-include
mrexodia Mar 31, 2021
f2dbd1f
Refactor cmake generation
mrexodia Mar 31, 2021
82338cd
Fix compilation on Ubuntu
mrexodia Mar 31, 2021
fd307df
Fix weird compilation bug on latest CMake and Windows
mrexodia Mar 31, 2021
af0c42b
Allow putting cmkr.cmake in a subfolder
mrexodia Mar 31, 2021
868d991
Fix path expansion for subdirectories
mrexodia Apr 2, 2021
c51f9cd
Fix typo in target type enum
mrexodia Apr 3, 2021
6e48ec7
Generate configure_file for every cmake.toml file
mrexodia Apr 3, 2021
555c2d0
Make the first executable the startup project in Visual Studio
mrexodia Apr 3, 2021
8e16352
Add error checking for " at the end of injected cmake blocks
mrexodia Apr 3, 2021
67ac9a4
Add a hack to hide a warning while bootstrapping on Windows
mrexodia Apr 4, 2021
84f6b39
Clean up cmkr bootstrapping
mrexodia Apr 4, 2021
5c94259
Recursively bootstrap cmkr.cmake
mrexodia Apr 4, 2021
b5752b7
Breaking change, rename 'cmake.minimum' to 'cmake.version' and make i…
mrexodia Apr 5, 2021
5a20c0f
Initial vcpkg support
mrexodia Apr 5, 2021
6162e86
Respect default members while building
mrexodia Apr 5, 2021
5312b44
Fix warnings on AppleClang 12
mrexodia Apr 6, 2021
783f343
Run GitHub Actions on a bigger matrix
mrexodia Apr 6, 2021
d62dff2
Implement stronger type checking for optional values
mrexodia Apr 6, 2021
598c9b9
Sort globbed files alphabetically for consistent cross-OS generation
mrexodia Apr 6, 2021
3266470
Initial attempt at adding tests
mrexodia Apr 6, 2021
747bc8b
Merge remote-tracking branch 'origin/master' into develop
mrexodia Apr 19, 2021
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 .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakStringLiterals: true
ColumnLimit: 100
ColumnLimit: 150
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ name: CMake

on: [push, pull_request]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-10.15, ubuntu-18.04]

os: [windows-2016, windows-2019, macos-10.15, ubuntu-16.04, ubuntu-18.04, ubuntu-20.04]
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: cmake -S. -Bbin -DCMAKE_BUILD_TYPE=$BUILD_TYPE && cmake --build bin --parallel --config $BUILD_TYPE
run: |
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
- name: Test
run: |
cd build/tests
ctest -C ${{ env.BUILD_TYPE }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ compile_commands.json
temp.*
.vs
.cache
build*/
build*/
.idea/
cmake-build*/
CMakeLists.txt.user
164 changes: 101 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,87 +1,125 @@
# This file was generated automatically by cmkr.

# Regenerate CMakeLists.txt file when necessary
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
cmake_minimum_required(VERSION 2.8...3.8)

if(CMKR_INCLUDE_RESULT)
cmkr()
endif()

cmake_minimum_required(VERSION 3.15)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(cmkr
VERSION 0.1.4
LANGUAGES C CXX
DESCRIPTION "CMakeLists generator from TOML"
)

include(FetchContent)

FetchContent_Declare(
filesystem
GIT_REPOSITORY https://github.com/gulrak/filesystem
GIT_SHALLOW ON
)
# Regenerate CMakeLists.txt automatically in the root project
set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMKR_ROOT_PROJECT ON)

FetchContent_MakeAvailable(filesystem)
# Bootstrap cmkr
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
if(CMKR_INCLUDE_RESULT)
cmkr()
endif()

FetchContent_Declare(
mpark_variant
URL https://github.com/mpark/variant/archive/v1.4.0.tar.gz
)
# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

FetchContent_MakeAvailable(mpark_variant)
# Create a configure-time dependency on cmake.toml to improve IDE support
if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()

FetchContent_Declare(
toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11
GIT_SHALLOW ON
)
# Hack to hide a warning during cmkr bootstrapping on Windows
if(CMAKE_BUILD_TYPE)
endif()

FetchContent_MakeAvailable(toml11)

set(CMKRLIB_SOURCES
src/cmake.cpp
src/gen.cpp
src/help.cpp
src/build.cpp
src/error.cpp
)
project(cmkr
LANGUAGES
CXX
VERSION
0.1.3
DESCRIPTION
"CMakeLists generator from TOML"
)

# third_party
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/third_party")
else()
set(CMAKE_FOLDER third_party)
endif()
add_subdirectory(third_party)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})

# tests
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/tests")
else()
set(CMAKE_FOLDER tests)
endif()
add_subdirectory(tests)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})


# Target cmkrlib
set(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"
cmake.toml
)

add_library(cmkrlib STATIC ${cmkrlib_SOURCES})

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${cmkrlib_SOURCES})

add_library(cmkrlib STATIC ${CMKRLIB_SOURCES})
target_compile_features(cmkrlib PUBLIC
cxx_std_11
)

target_include_directories(cmkrlib PUBLIC
include
)
)

target_link_libraries(cmkrlib PUBLIC
toml11::toml11
toml11
ghc_filesystem
mpark_variant
)
ordered_map
)

target_compile_features(cmkrlib PUBLIC
cxx_std_11
)
# Target cmkr
set(cmkr_SOURCES
"src/main.cpp"
cmake.toml
)

add_executable(cmkr ${cmkr_SOURCES})

set(CMKR_SOURCES
src/main.cpp
src/args.cpp
)
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT cmkr)
endif()

add_executable(cmkr ${CMKR_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${cmkr_SOURCES})

target_link_libraries(cmkr PUBLIC
target_link_libraries(cmkr PRIVATE
cmkrlib
)
)

install(
TARGETS cmkr
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
COMPONENT cmkr
)



TARGETS
cmkr
DESTINATION
"${CMAKE_INSTALL_PREFIX}/bin"
COMPONENT
cmkr
)
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ minimum = "3.15"
name = "app"
version = "0.1.0"

[[bin]]
[[target]]
name = "app"
type = "exe"
type = "executable"
sources = ["src/main.cpp"]
```

Expand All @@ -43,19 +43,19 @@ toml11 = { git = "https://github.com/ToruNiina/toml11" }
filesystem = { git = "https://github.com/gulrak/filesystem" }
mpark_variant = { url = "https://github.com/mpark/variant/archive/v1.4.0.tar.gz" }

[[bin]]
[[target]]
name = "cmkrlib"
type = "static"
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
include-dirs = ["include"]
features = ["cxx_std_11"]
link-libs = ["toml11::toml11", "ghc_filesystem"]
include-directories = ["include"]
compile-features = ["cxx_std_11"]
link-libraries = ["toml11::toml11", "ghc_filesystem"]

[[bin]]
[[target]]
name = "cmkr"
type = "exe"
type = "executable"
sources = ["src/main.cpp", "src/args.cpp"]
link-libs = ["cmkrlib"]
link-libraries = ["cmkrlib"]

[[install]]
targets = ["cmkr"]
Expand All @@ -68,7 +68,7 @@ Currently supported fields:
minimum = "3.15" # required
description = "" # optional
subdirs = [] # optional
bin-dir = "bin" # optional
build-dir = "build" # optional
cpp-flags = [] # optional
c-flags = [] # optional
link-flags = [] # optional
Expand Down Expand Up @@ -97,15 +97,15 @@ toml11 = { git = "https://github.com/ToruNiina/toml11", tag = "v3.5.0" } # optio
APP_BUILD_STUFF = false # optional
APP_OTHER_STUFF = { comment = "does other stuff", value = false } # optional

[[bin]] # required, can define several binaries
[[target]] # required, can define several binaries
name = "app" # required
type = "exe" # required (exe || lib || shared || static || interface)
type = "executable" # required (executable || library || shared || static || interface)
sources = ["src/*.cpp"] # required, supports globbing
include-dirs = ["include"] # optional
include-directories = ["include"] # optional
alias = "" # optional
features = [] # optional
definitions = [] # optional
link-libs = [] # optional
compile-features = [] # optional
compile-definitions = [] # optional
link-libraries = [] # optional
properties = { PROPERTY1 = "property1", ... } # optional

[[test]] # optional, can define several
Expand All @@ -125,13 +125,13 @@ The cmkr executable can be run from the command-line:
```
Usage: cmkr [arguments]
arguments:
init [exe|lib|shared|static|interface] Starts a new project in the same directory.
gen Generates CMakeLists.txt file.
build <extra cmake args> Run cmake and build.
install Run cmake --install. Needs admin privileges.
clean Clean the build directory.
help Show help.
version Current cmkr version.
init [executable|library|shared|static|interface] Starts a new project in the same directory.
gen Generates CMakeLists.txt file.
build <extra cmake args> Run cmake and build.
install Run cmake --install. Needs admin privileges.
clean Clean the build directory.
help Show help.
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:
```
Expand All @@ -140,20 +140,20 @@ cmkr build --config Release

## Binary types

### exe
Executable binary.
### executable
Executable binary. Equivalent to [add_executable(name)](https://cmake.org/cmake/help/latest/command/add_executable.html).

### lib
Library, can be static or shared depending on the BUILD_SHARED_LIBS variable.
### 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.
Static library/archive. Equivalent to [add_library(name STATIC)](https://cmake.org/cmake/help/latest/command/add_library.html).

### shared
Shared/dynamic library.
Shared/dynamic library. Equivalent to [add_library(name SHARED)](https://cmake.org/cmake/help/latest/command/add_library.html).

### interface
Header-only library.
Header-only library. Equivalent to [add_library(name INTERFACE)](https://cmake.org/cmake/help/latest/command/add_library.html).

## Roadmap
- Support more cmake fields.
Expand Down
Loading