From 1deaec2b41cf024ce72c8ac67ae564d759d2cb43 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 12 Jun 2023 18:20:42 +0200 Subject: [PATCH] Add .editorconfig and linting Closes #112 --- .clang-format | 2 +- .editorconfig | 24 +++ .github/workflows/build.yml | 4 +- .github/workflows/lint.yml | 14 +- cmake/bump_version.cmake | 154 +++++++++---------- cmake/generate_documentation.cmake | 10 +- cmake/resource.hpp.in | 12 +- docs/CNAME | 2 +- docs/cmake-toml.md | 2 +- docs/getting-started.html | 18 +-- include/fs.hpp | 2 +- include/project_parser.hpp | 2 +- tests/basic/cmake.toml | 2 +- tests/conditions/cmake.toml | 46 +++--- tests/conditions/src/main.cpp | 2 +- tests/conditions/src/windows_specific.cpp | 8 +- tests/cxx-standard/cmake.toml | 24 +-- tests/cxx-standard/src/main.cpp | 14 +- tests/fetch-content/cmake.toml | 2 +- tests/fetch-content/src/main.cpp | 2 +- tests/globbing/cmake.toml | 36 ++--- tests/globbing/example/src/main.cpp | 14 +- tests/globbing/mylib/include/mylib/mylib.hpp | 14 +- tests/globbing/mylib/src/mylib/mylib.cpp | 10 +- tests/interface/cmake.toml | 26 ++-- tests/interface/include/mylib/mylib.hpp | 10 +- tests/interface/src/main.cpp | 14 +- tests/msvc-runtime/cmake.toml | 2 +- tests/templates/cmake.toml | 2 +- tests/vcpkg/cmake.toml | 2 +- tests/vcpkg/src/main.cpp | 2 +- 31 files changed, 256 insertions(+), 222 deletions(-) create mode 100644 .editorconfig diff --git a/.clang-format b/.clang-format index f6341fd..09ec46b 100644 --- a/.clang-format +++ b/.clang-format @@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: true BinPackArguments: true BinPackParameters: true -BraceWrapping: +BraceWrapping: AfterClass: false AfterControlStatement: false AfterEnum: false diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..82fe4e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +root = true + +[*] +end_of_line = lf +trim_trailing_whitespace = true +charset = utf-8 + +[*.{c,h,cpp,hpp,toml}] +indent_style = space +insert_final_newline = true + +[{CMakeLists.txt, *.cmake}] +indent_style = tab +tab_width = 8 +insert_final_newline = true + +# Exclude the third_party folder +[/third_party/**] +charset = unset +end_of_line = unset +insert_final_newline = unset +trim_trailing_whitespace = unset +indent_style = unset +indent_size = unset diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29c5e61..9bb8e2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,9 @@ -name: CMake +name: build on: [push, pull_request] jobs: - build: + cmake: # Skip building pull requests from the same repository if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }} runs-on: ${{ matrix.os }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4815039..a222aa1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,7 +3,7 @@ name: lint on: [push] jobs: - lint: + clang-format: runs-on: ubuntu-latest steps: @@ -24,4 +24,14 @@ jobs: run: | # Instructions for fixing the formatting errors echo -e "\n\033[0;31mTo fix the formatting, run:\nclang-format -style=file -i \$(git ls-files \"*.c\" \"*.h\" \"*.cpp\" \"*.hpp\")\033[0m\n" - exit 1 \ No newline at end of file + exit 1 + + editorconfig: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run editorconfig-checker + uses: editorconfig-checker/action-editorconfig-checker@d4fca16fc71adef10fbe101903b654449fa9570c # master 2022-03-15 diff --git a/cmake/bump_version.cmake b/cmake/bump_version.cmake index 358a183..aad5d30 100644 --- a/cmake/bump_version.cmake +++ b/cmake/bump_version.cmake @@ -1,78 +1,78 @@ -cmake_minimum_required(VERSION 3.20) - -if(NOT CMAKE_SCRIPT_MODE_FILE) - message(FATAL_ERROR "Usage: cmake -P bump_version.cmake [1.2.3]") -endif() - -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml") - message(FATAL_ERROR "Cannot find cmake.toml") -endif() - -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake") - message(FATAL_ERROR "Cannot find cmkr.cmake") -endif() - -# Validate branch -find_package(Git REQUIRED) -execute_process(COMMAND "${GIT_EXECUTABLE}" branch --show-current OUTPUT_VARIABLE GIT_BRANCH) -string(STRIP "${GIT_BRANCH}" GIT_BRANCH) -if(NOT GIT_BRANCH STREQUAL "main") - message(FATAL_ERROR "You need to be on the main branch, you are on: ${GIT_BRANCH}") -endif() - -file(READ "${CMAKE_SOURCE_DIR}/cmake.toml" CMAKE_TOML) -string(FIND "${CMAKE_TOML}" "[project]" PROJECT_INDEX) -string(SUBSTRING "${CMAKE_TOML}" ${PROJECT_INDEX} -1 CMAKE_TOML_PROJECT) -set(SEMVER_REGEX "([0-9]+)\\.([0-9]+)\\.([0-9]+)") -set(VERSION_REGEX "version = \"${SEMVER_REGEX}\"") -if(CMAKE_TOML_PROJECT MATCHES "${VERSION_REGEX}") - set(MAJOR "${CMAKE_MATCH_1}") - set(MINOR "${CMAKE_MATCH_2}") - set(PATCH "${CMAKE_MATCH_3}") - set(OLDVERSION "${MAJOR}.${MINOR}.${PATCH}") -else() - message(FATAL_ERROR "Failed to match semantic version in cmake.toml") -endif() - -if(CMAKE_ARGV3) - if(NOT CMAKE_ARGV3 MATCHES "${SEMVER_REGEX}") - message(FATAL_ERROR "Invalid semantic version number '${CMAKE_ARGV3}'") - endif() - set(NEWVERSION "${CMAKE_ARGV3}") -else() - math(EXPR NEWPATCH "${PATCH} + 1") - set(NEWVERSION "${MAJOR}.${MINOR}.${NEWPATCH}") -endif() - -message(STATUS "Version ${OLDVERSION} -> ${NEWVERSION}") - -find_program(CMKR_EXECUTABLE "cmkr" PATHS "${CMAKE_SOURCE_DIR}/build" PATH_SUFFIXES Debug Release RelWithDebInfo MinSizeRel NO_CACHE REQUIRED) -message(STATUS "Found cmkr: ${CMKR_EXECUTABLE}") - -# Replace version in cmake.toml -string(REPLACE "version = \"${OLDVERSION}\"" "version = \"${NEWVERSION}\"" CMAKE_TOML "${CMAKE_TOML}") -file(CONFIGURE - OUTPUT "${CMAKE_SOURCE_DIR}/cmake.toml" - CONTENT "${CMAKE_TOML}" - @ONLY - NEWLINE_STYLE LF -) - -# Run cmkr gen -execute_process(COMMAND "${CMKR_EXECUTABLE}" gen RESULT_VARIABLE CMKR_EXEC_RESULT) -if(NOT CMKR_EXEC_RESULT EQUAL 0) - message(FATAL_ERROR "cmkr gen failed (exit code ${CMKR_EXEC_RESULT})") -endif() - -# Replace version in cmkr.cmake -file(READ "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" CMKR_CMAKE) -string(REGEX REPLACE "CMKR_TAG \"[^\"]+\"" "CMKR_TAG \"v${NEWVERSION}\"" CMKR_CMAKE "${CMKR_CMAKE}") -file(CONFIGURE - OUTPUT "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" - CONTENT "${CMKR_CMAKE}" - @ONLY - NEWLINE_STYLE LF -) - -# Print git commands +cmake_minimum_required(VERSION 3.20) + +if(NOT CMAKE_SCRIPT_MODE_FILE) + message(FATAL_ERROR "Usage: cmake -P bump_version.cmake [1.2.3]") +endif() + +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml") + message(FATAL_ERROR "Cannot find cmake.toml") +endif() + +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake") + message(FATAL_ERROR "Cannot find cmkr.cmake") +endif() + +# Validate branch +find_package(Git REQUIRED) +execute_process(COMMAND "${GIT_EXECUTABLE}" branch --show-current OUTPUT_VARIABLE GIT_BRANCH) +string(STRIP "${GIT_BRANCH}" GIT_BRANCH) +if(NOT GIT_BRANCH STREQUAL "main") + message(FATAL_ERROR "You need to be on the main branch, you are on: ${GIT_BRANCH}") +endif() + +file(READ "${CMAKE_SOURCE_DIR}/cmake.toml" CMAKE_TOML) +string(FIND "${CMAKE_TOML}" "[project]" PROJECT_INDEX) +string(SUBSTRING "${CMAKE_TOML}" ${PROJECT_INDEX} -1 CMAKE_TOML_PROJECT) +set(SEMVER_REGEX "([0-9]+)\\.([0-9]+)\\.([0-9]+)") +set(VERSION_REGEX "version = \"${SEMVER_REGEX}\"") +if(CMAKE_TOML_PROJECT MATCHES "${VERSION_REGEX}") + set(MAJOR "${CMAKE_MATCH_1}") + set(MINOR "${CMAKE_MATCH_2}") + set(PATCH "${CMAKE_MATCH_3}") + set(OLDVERSION "${MAJOR}.${MINOR}.${PATCH}") +else() + message(FATAL_ERROR "Failed to match semantic version in cmake.toml") +endif() + +if(CMAKE_ARGV3) + if(NOT CMAKE_ARGV3 MATCHES "${SEMVER_REGEX}") + message(FATAL_ERROR "Invalid semantic version number '${CMAKE_ARGV3}'") + endif() + set(NEWVERSION "${CMAKE_ARGV3}") +else() + math(EXPR NEWPATCH "${PATCH} + 1") + set(NEWVERSION "${MAJOR}.${MINOR}.${NEWPATCH}") +endif() + +message(STATUS "Version ${OLDVERSION} -> ${NEWVERSION}") + +find_program(CMKR_EXECUTABLE "cmkr" PATHS "${CMAKE_SOURCE_DIR}/build" PATH_SUFFIXES Debug Release RelWithDebInfo MinSizeRel NO_CACHE REQUIRED) +message(STATUS "Found cmkr: ${CMKR_EXECUTABLE}") + +# Replace version in cmake.toml +string(REPLACE "version = \"${OLDVERSION}\"" "version = \"${NEWVERSION}\"" CMAKE_TOML "${CMAKE_TOML}") +file(CONFIGURE + OUTPUT "${CMAKE_SOURCE_DIR}/cmake.toml" + CONTENT "${CMAKE_TOML}" + @ONLY + NEWLINE_STYLE LF +) + +# Run cmkr gen +execute_process(COMMAND "${CMKR_EXECUTABLE}" gen RESULT_VARIABLE CMKR_EXEC_RESULT) +if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "cmkr gen failed (exit code ${CMKR_EXEC_RESULT})") +endif() + +# Replace version in cmkr.cmake +file(READ "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" CMKR_CMAKE) +string(REGEX REPLACE "CMKR_TAG \"[^\"]+\"" "CMKR_TAG \"v${NEWVERSION}\"" CMKR_CMAKE "${CMKR_CMAKE}") +file(CONFIGURE + OUTPUT "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" + CONTENT "${CMKR_CMAKE}" + @ONLY + NEWLINE_STYLE LF +) + +# Print git commands message(STATUS "Git commands to create new version:\ngit commit -a -m \"Bump to ${NEWVERSION}\"\ngit tag v${NEWVERSION}\ngit push origin main v${NEWVERSION}") \ No newline at end of file diff --git a/cmake/generate_documentation.cmake b/cmake/generate_documentation.cmake index 50895dc..a1507a8 100644 --- a/cmake/generate_documentation.cmake +++ b/cmake/generate_documentation.cmake @@ -15,7 +15,7 @@ function(generate_documentation) message(FATAL_ERROR "This should not happen (wrong regex?)") endif() endforeach() - + # Delete previously generated examples set(example_folder "${PROJECT_SOURCE_DIR}/docs/examples") file(GLOB example_files "${example_folder}/*.md") @@ -41,21 +41,21 @@ function(generate_documentation) # Read cmake.toml file file(READ "${test_toml}" test_contents NO_HEX_CONVERSION) string(LENGTH "${test_contents}" toml_length) - + # Extract header text string(REGEX MATCH "^(\n*(#[^\n]+\n)+\n*)" EXAMPLE_HEADER "${test_contents}") string(LENGTH "${EXAMPLE_HEADER}" header_length) string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER) string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_HEADER "\n${EXAMPLE_HEADER}") string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER) - + # Extract footer text string(REGEX MATCH "(((#[^\n]+)(\n+|$))+)$" EXAMPLE_FOOTER "${test_contents}") string(LENGTH "${EXAMPLE_FOOTER}" footer_length) string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER) string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_FOOTER "\n${EXAMPLE_FOOTER}") string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER) - + # Extract toml body math(EXPR toml_length "${toml_length}-${header_length}-${footer_length}") string(SUBSTRING "${test_contents}" ${header_length} ${toml_length} EXAMPLE_TOML) @@ -64,7 +64,7 @@ function(generate_documentation) # Extract title from description if("${EXAMPLE_TOML}" MATCHES "description *= *\"([^\"]+)\"") set(EXAMPLE_TITLE "${CMAKE_MATCH_1}") - + # Generate documentation markdown page configure_file("${PROJECT_SOURCE_DIR}/cmake/example.md.in" "${example_folder}/${EXAMPLE_PERMALINK}.md" @ONLY NEWLINE_STYLE LF) else() diff --git a/cmake/resource.hpp.in b/cmake/resource.hpp.in index 70d8411..90b7b26 100644 --- a/cmake/resource.hpp.in +++ b/cmake/resource.hpp.in @@ -1,7 +1,7 @@ -namespace cmkr { -namespace resources { - -static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE"; - -} +namespace cmkr { +namespace resources { + +static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE"; + +} } \ No newline at end of file diff --git a/docs/CNAME b/docs/CNAME index 92635f0..be3e830 100644 --- a/docs/CNAME +++ b/docs/CNAME @@ -1 +1 @@ -cmkr.build \ No newline at end of file +cmkr.build diff --git a/docs/cmake-toml.md b/docs/cmake-toml.md index 00661ce..ce15d77 100644 --- a/docs/cmake-toml.md +++ b/docs/cmake-toml.md @@ -49,7 +49,7 @@ arch64 = "CMAKE_SIZEOF_VOID_P EQUAL 8" arch32 = "CMAKE_SIZEOF_VOID_P EQUAL 4" ``` -This will make the `arch64` and `arch32` conditions available with their respective CMake expressions. +This will make the `arch64` and `arch32` conditions available with their respective CMake expressions. You can also prefix most keys with `condition.` to represent a conditional: diff --git a/docs/getting-started.html b/docs/getting-started.html index b5b0607..d5b3856 100644 --- a/docs/getting-started.html +++ b/docs/getting-started.html @@ -1,10 +1,10 @@ ---- -layout: null -permalink: /getting-started/ ---- - - - - - +--- +layout: null +permalink: /getting-started/ +--- + + + + + \ No newline at end of file diff --git a/include/fs.hpp b/include/fs.hpp index 9b2c3e5..d8d863c 100644 --- a/include/fs.hpp +++ b/include/fs.hpp @@ -10,4 +10,4 @@ namespace fs = std::filesystem; #ifndef GHC_USE_STD_FS #include namespace fs = ghc::filesystem; -#endif \ No newline at end of file +#endif diff --git a/include/project_parser.hpp b/include/project_parser.hpp index 9c8842f..52ca8c2 100644 --- a/include/project_parser.hpp +++ b/include/project_parser.hpp @@ -212,4 +212,4 @@ struct Project { bool is_root_path(const std::string &path); } // namespace parser -} // namespace cmkr \ No newline at end of file +} // namespace cmkr diff --git a/tests/basic/cmake.toml b/tests/basic/cmake.toml index 75ae8a1..8e6f811 100644 --- a/tests/basic/cmake.toml +++ b/tests/basic/cmake.toml @@ -8,4 +8,4 @@ description = "Minimal example" type = "executable" sources = ["src/basic.cpp"] -# Declares an executable target called `basic` with `src/basic.cpp` as a source file. Equivalent to CMake's [add_executable](https://cmake.org/cmake/help/latest/command/add_executable.html)`(basic src/basic.cpp)`. \ No newline at end of file +# Declares an executable target called `basic` with `src/basic.cpp` as a source file. Equivalent to CMake's [add_executable](https://cmake.org/cmake/help/latest/command/add_executable.html)`(basic src/basic.cpp)`. diff --git a/tests/conditions/cmake.toml b/tests/conditions/cmake.toml index 007c7b8..2ceb54c 100644 --- a/tests/conditions/cmake.toml +++ b/tests/conditions/cmake.toml @@ -1,23 +1,23 @@ -[project] -name = "conditions" -cmake-after = "set(CUSTOM ON)" - -[conditions] -custom = "CUSTOM" - -[target.example] -type = "executable" -sources = ["src/main.cpp"] -windows.sources = ["src/windows_specific.cpp"] -cmake-after = "message(STATUS cmake-after)" -windows.cmake-after = "message(STATUS win32-after)" -macos.cmake-after = "message(STATUS macos-after)" -linux.cmake-after = "message(STATUS linux-after)" -unix.cmake-after = "message(STATUS unix-after)" -custom.cmake-after = "message(STATUS custom-after)" - -[target.example.properties] -AUTOMOC = false -custom.OUTPUT_NAME = "example2" -custom.AUTORCC = true -AUTOGEN = "ON" \ No newline at end of file +[project] +name = "conditions" +cmake-after = "set(CUSTOM ON)" + +[conditions] +custom = "CUSTOM" + +[target.example] +type = "executable" +sources = ["src/main.cpp"] +windows.sources = ["src/windows_specific.cpp"] +cmake-after = "message(STATUS cmake-after)" +windows.cmake-after = "message(STATUS win32-after)" +macos.cmake-after = "message(STATUS macos-after)" +linux.cmake-after = "message(STATUS linux-after)" +unix.cmake-after = "message(STATUS unix-after)" +custom.cmake-after = "message(STATUS custom-after)" + +[target.example.properties] +AUTOMOC = false +custom.OUTPUT_NAME = "example2" +custom.AUTORCC = true +AUTOGEN = "ON" diff --git a/tests/conditions/src/main.cpp b/tests/conditions/src/main.cpp index e1e8e9f..b2f9976 100644 --- a/tests/conditions/src/main.cpp +++ b/tests/conditions/src/main.cpp @@ -1,2 +1,2 @@ int main() { -} \ No newline at end of file +} diff --git a/tests/conditions/src/windows_specific.cpp b/tests/conditions/src/windows_specific.cpp index 354c05a..f67ca6f 100644 --- a/tests/conditions/src/windows_specific.cpp +++ b/tests/conditions/src/windows_specific.cpp @@ -1,4 +1,4 @@ -#include - -void foo() { -} \ No newline at end of file +#include + +void foo() { +} diff --git a/tests/cxx-standard/cmake.toml b/tests/cxx-standard/cmake.toml index 41250be..d44e950 100644 --- a/tests/cxx-standard/cmake.toml +++ b/tests/cxx-standard/cmake.toml @@ -1,12 +1,12 @@ -# Require a C++11 compiler for the target `example`. - -[project] -name = "cxx-standard" -description = "Changing C++ standard" - -[target.example] -type = "executable" -sources = ["src/main.cpp"] -compile-features = ["cxx_std_11"] - -# This is equivalent to CMake's [target_compile_features](https://cmake.org/cmake/help/latest/command/target_compile_features.html)`(example PRIVATE cxx_std_11)`. For more information on available C/C++ standards and features see [cmake-compile-features(7)](https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html). \ No newline at end of file +# Require a C++11 compiler for the target `example`. + +[project] +name = "cxx-standard" +description = "Changing C++ standard" + +[target.example] +type = "executable" +sources = ["src/main.cpp"] +compile-features = ["cxx_std_11"] + +# This is equivalent to CMake's [target_compile_features](https://cmake.org/cmake/help/latest/command/target_compile_features.html)`(example PRIVATE cxx_std_11)`. For more information on available C/C++ standards and features see [cmake-compile-features(7)](https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html). diff --git a/tests/cxx-standard/src/main.cpp b/tests/cxx-standard/src/main.cpp index 29e611f..7914697 100644 --- a/tests/cxx-standard/src/main.cpp +++ b/tests/cxx-standard/src/main.cpp @@ -1,7 +1,7 @@ -#include -#include - -int main() { - auto tpl = std::make_tuple(1, 2); - printf("Hello from C++11 %d\n", std::get<0>(tpl)); -} \ No newline at end of file +#include +#include + +int main() { + auto tpl = std::make_tuple(1, 2); + printf("Hello from C++11 %d\n", std::get<0>(tpl)); +} diff --git a/tests/fetch-content/cmake.toml b/tests/fetch-content/cmake.toml index ca5d912..6a99c1a 100644 --- a/tests/fetch-content/cmake.toml +++ b/tests/fetch-content/cmake.toml @@ -12,4 +12,4 @@ type = "executable" sources = ["src/main.cpp"] link-libraries = ["fmt::fmt"] -# This is equivalent to calling CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html). \ No newline at end of file +# This is equivalent to calling CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html). diff --git a/tests/fetch-content/src/main.cpp b/tests/fetch-content/src/main.cpp index f29bef6..e821d86 100644 --- a/tests/fetch-content/src/main.cpp +++ b/tests/fetch-content/src/main.cpp @@ -2,4 +2,4 @@ int main() { fmt::print("Hello, world!\n"); -} \ No newline at end of file +} diff --git a/tests/globbing/cmake.toml b/tests/globbing/cmake.toml index 4ec24bb..e174f84 100644 --- a/tests/globbing/cmake.toml +++ b/tests/globbing/cmake.toml @@ -1,18 +1,18 @@ -[project] -name = "globbing" -description = "Globbing sources" - -# Recursively glob in the mylib/ folder -[target.mylib] -type = "static" -alias = "mylib::mylib" -sources = ["mylib/**.hpp", "mylib/**.cpp"] -include-directories = ["mylib/include"] - -# Single-folder glob in example/src/ -[target.example] -type = "executable" -sources = ["example/src/*.cpp"] -link-libraries = ["mylib::mylib"] - -# As you can see in the example above you can use `**.ext` to glob recursively and `*.ext` to glob non-recursively. This **does not** generate `file(GLOB ...)` commands, but instead globs when cmkr is run. Files are sorted to give deterministic results regardless of the platform used. \ No newline at end of file +[project] +name = "globbing" +description = "Globbing sources" + +# Recursively glob in the mylib/ folder +[target.mylib] +type = "static" +alias = "mylib::mylib" +sources = ["mylib/**.hpp", "mylib/**.cpp"] +include-directories = ["mylib/include"] + +# Single-folder glob in example/src/ +[target.example] +type = "executable" +sources = ["example/src/*.cpp"] +link-libraries = ["mylib::mylib"] + +# As you can see in the example above you can use `**.ext` to glob recursively and `*.ext` to glob non-recursively. This **does not** generate `file(GLOB ...)` commands, but instead globs when cmkr is run. Files are sorted to give deterministic results regardless of the platform used. diff --git a/tests/globbing/example/src/main.cpp b/tests/globbing/example/src/main.cpp index a53ccc6..5000414 100644 --- a/tests/globbing/example/src/main.cpp +++ b/tests/globbing/example/src/main.cpp @@ -1,7 +1,7 @@ -#include -#include - -int main() { - std::cout << mylib::message() << std::endl; - return 0; -} +#include +#include + +int main() { + std::cout << mylib::message() << std::endl; + return 0; +} diff --git a/tests/globbing/mylib/include/mylib/mylib.hpp b/tests/globbing/mylib/include/mylib/mylib.hpp index e19482e..3774e8f 100644 --- a/tests/globbing/mylib/include/mylib/mylib.hpp +++ b/tests/globbing/mylib/include/mylib/mylib.hpp @@ -1,7 +1,7 @@ -#pragma once - -#include - -namespace mylib { -std::string message(); -} +#pragma once + +#include + +namespace mylib { +std::string message(); +} diff --git a/tests/globbing/mylib/src/mylib/mylib.cpp b/tests/globbing/mylib/src/mylib/mylib.cpp index 13f192c..6b701f9 100644 --- a/tests/globbing/mylib/src/mylib/mylib.cpp +++ b/tests/globbing/mylib/src/mylib/mylib.cpp @@ -1,5 +1,5 @@ -#include - -std::string mylib::message() { - return "cmkr is awesome!"; -} +#include + +std::string mylib::message() { + return "cmkr is awesome!"; +} diff --git a/tests/interface/cmake.toml b/tests/interface/cmake.toml index 44588c4..0c52fd6 100644 --- a/tests/interface/cmake.toml +++ b/tests/interface/cmake.toml @@ -1,13 +1,13 @@ -[project] -name = "interface" -description = "Header-only library" - -[target.mylib] -type = "interface" -include-directories = ["include"] -compile-features = ["cxx_std_11"] - -[target.example] -type = "executable" -sources = ["src/main.cpp"] -link-libraries = ["mylib"] \ No newline at end of file +[project] +name = "interface" +description = "Header-only library" + +[target.mylib] +type = "interface" +include-directories = ["include"] +compile-features = ["cxx_std_11"] + +[target.example] +type = "executable" +sources = ["src/main.cpp"] +link-libraries = ["mylib"] diff --git a/tests/interface/include/mylib/mylib.hpp b/tests/interface/include/mylib/mylib.hpp index 2738095..dea549f 100644 --- a/tests/interface/include/mylib/mylib.hpp +++ b/tests/interface/include/mylib/mylib.hpp @@ -1,5 +1,5 @@ -namespace mylib { -static const char *version() { - return "v1.0"; -} -} // namespace mylib \ No newline at end of file +namespace mylib { +static const char *version() { + return "v1.0"; +} +} // namespace mylib diff --git a/tests/interface/src/main.cpp b/tests/interface/src/main.cpp index 2b4d7ce..72050d7 100644 --- a/tests/interface/src/main.cpp +++ b/tests/interface/src/main.cpp @@ -1,7 +1,7 @@ -#include - -#include "mylib/mylib.hpp" - -int main() { - printf("mylib version: %s\n", mylib::version()); -} +#include + +#include "mylib/mylib.hpp" + +int main() { + printf("mylib version: %s\n", mylib::version()); +} diff --git a/tests/msvc-runtime/cmake.toml b/tests/msvc-runtime/cmake.toml index 61c7c08..0c1f719 100644 --- a/tests/msvc-runtime/cmake.toml +++ b/tests/msvc-runtime/cmake.toml @@ -12,4 +12,4 @@ sources = ["src/main.cpp"] [target.dynamic-runtime] type = "executable" sources = ["src/main.cpp"] -msvc-runtime = "dynamic" \ No newline at end of file +msvc-runtime = "dynamic" diff --git a/tests/templates/cmake.toml b/tests/templates/cmake.toml index 9fce97f..31bb2c6 100644 --- a/tests/templates/cmake.toml +++ b/tests/templates/cmake.toml @@ -22,4 +22,4 @@ compile-definitions = ["APP_A"] type = "app" compile-definitions = ["APP_B"] -# **Note**: In most cases you probably want to use an [interface](/examples/interface) target instead. \ No newline at end of file +# **Note**: In most cases you probably want to use an [interface](/examples/interface) target instead. diff --git a/tests/vcpkg/cmake.toml b/tests/vcpkg/cmake.toml index 66a34f3..44a29ae 100644 --- a/tests/vcpkg/cmake.toml +++ b/tests/vcpkg/cmake.toml @@ -19,4 +19,4 @@ sources = ["src/main.cpp"] link-libraries = ["fmt::fmt"] # The bootstrapping of vcpkg is fully automated and no user interaction is necessary. You can disable vcpkg by setting `CMKR_DISABLE_VCPKG=ON`. -# To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. \ No newline at end of file +# To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. diff --git a/tests/vcpkg/src/main.cpp b/tests/vcpkg/src/main.cpp index f29bef6..e821d86 100644 --- a/tests/vcpkg/src/main.cpp +++ b/tests/vcpkg/src/main.cpp @@ -2,4 +2,4 @@ int main() { fmt::print("Hello, world!\n"); -} \ No newline at end of file +}