From 4fff7e19bce26dfe55ad6b7a0f0e25c4c5f4b9b3 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 22:00:21 +0200 Subject: [PATCH 001/139] fix: add checks for target_disable_static_analysis --- src/StaticAnalyzers.cmake | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/StaticAnalyzers.cmake b/src/StaticAnalyzers.cmake index c43123a5..1f9f8103 100644 --- a/src/StaticAnalyzers.cmake +++ b/src/StaticAnalyzers.cmake @@ -162,14 +162,20 @@ endmacro() # Disable clang-tidy for target macro(target_disable_clang_tidy TARGET) - set_target_properties(${TARGET} PROPERTIES C_CLANG_TIDY "") - set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY "") + find_program(CLANGTIDY clang-tidy) + if(CLANGTIDY) + set_target_properties(${TARGET} PROPERTIES C_CLANG_TIDY "") + set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY "") + endif() endmacro() # Disable cppcheck for target macro(target_disable_cpp_check TARGET) - set_target_properties(${TARGET} PROPERTIES C_CPPCHECK "") - set_target_properties(${TARGET} PROPERTIES CXX_CPPCHECK "") + find_program(CPPCHECK cppcheck) + if(CPPCHECK) + set_target_properties(${TARGET} PROPERTIES C_CPPCHECK "") + set_target_properties(${TARGET} PROPERTIES CXX_CPPCHECK "") + endif() endmacro() # Disable vs analysis for target @@ -187,7 +193,9 @@ endmacro() # Disable static analysis for target macro(target_disable_static_analysis TARGET) - target_disable_clang_tidy(${TARGET}) - target_disable_cpp_check(${TARGET}) + if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") + target_disable_clang_tidy(${TARGET}) + target_disable_cpp_check(${TARGET}) + endif() target_disable_vs_analysis(${TARGET}) endmacro() From 6a386ecba716de17acac36c87654b62b9e7401d3 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 22:29:54 +0200 Subject: [PATCH 002/139] fix: add new test lib (#133) --- test/CMakeLists.txt | 7 ++++++- test/libs/CMakeLists.txt | 4 ++++ test/libs/mythirdpartylib/CMakeLists.txt | 8 ++++++++ test/libs/mythirdpartylib/include/Foo.hpp | 24 +++++++++++++++++++++++ test/libs/mythirdpartylib/src/Foo.cpp | 24 +++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/libs/CMakeLists.txt create mode 100644 test/libs/mythirdpartylib/CMakeLists.txt create mode 100644 test/libs/mythirdpartylib/include/Foo.hpp create mode 100644 test/libs/mythirdpartylib/src/Foo.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 124368e3..c43767dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -81,7 +81,6 @@ set(DEPENDENCIES_CONFIGURED fmt Eigen3 docopt) foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) find_package(${DEPENDENCY} CONFIG REQUIRED) endforeach() -target_disable_static_analysis(Eigen3::Eigen) target_link_system_libraries( main @@ -89,6 +88,8 @@ target_link_system_libraries( fmt::fmt Eigen3::Eigen) +add_subdirectory(libs) + ## tests enable_testing() add_test(NAME main COMMAND main) @@ -116,6 +117,10 @@ target_link_system_libraries( PRIVATE fmt::fmt Eigen3::Eigen) +target_link_system_libraries( + lib2 + PRIVATE + mythirdpartylib) # package everything automatically package_project( diff --git a/test/libs/CMakeLists.txt b/test/libs/CMakeLists.txt new file mode 100644 index 00000000..26b66ab0 --- /dev/null +++ b/test/libs/CMakeLists.txt @@ -0,0 +1,4 @@ +include(GenerateExportHeader) + +add_subdirectory(mythirdpartylib) +target_disable_static_analysis(mythirdpartylib) diff --git a/test/libs/mythirdpartylib/CMakeLists.txt b/test/libs/mythirdpartylib/CMakeLists.txt new file mode 100644 index 00000000..87fc6f69 --- /dev/null +++ b/test/libs/mythirdpartylib/CMakeLists.txt @@ -0,0 +1,8 @@ + +add_library(mythirdpartylib STATIC src/Foo.cpp) +generate_export_header(mythirdpartylib) + +target_include_directories(mythirdpartylib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src + PUBLIC "$" "$" +) diff --git a/test/libs/mythirdpartylib/include/Foo.hpp b/test/libs/mythirdpartylib/include/Foo.hpp new file mode 100644 index 00000000..185f02e1 --- /dev/null +++ b/test/libs/mythirdpartylib/include/Foo.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "mythirdpartylib_export.h" + +namespace mythirdpartylib { + +class MYTHIRDPARTYLIB_EXPORT Foo { +public: + Foo() = default; + + /*implicit*/ Foo(int a) m_a(a) {} + + int a() const { return m_a; } + + void update(bool b, bool c, bool d); + void bad(std::vector& v); + +private: + int m_a; +}; + +} \ No newline at end of file diff --git a/test/libs/mythirdpartylib/src/Foo.cpp b/test/libs/mythirdpartylib/src/Foo.cpp new file mode 100644 index 00000000..c0397565 --- /dev/null +++ b/test/libs/mythirdpartylib/src/Foo.cpp @@ -0,0 +1,24 @@ +#include "Foo.h" + +namespace mythirdpartylib { + +void Foo::update(bool b, bool c, bool d) { + int e = b + d; + m_a = e; +} + +void Foo::bad(std::vector& v) { + std::string val = "hello"; + int index = -1; // bad, plus should use gsl::index + for (int i = 0; i < v.size(); ++i) { + if (v[i] == val) { + index = i; + break; + } + } +} + +static Foo foo (5); +static Foo bar = 42; + +} \ No newline at end of file From 72ecd99cab9e28d4bc2ba633c9c948cedc8ef3cd Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 22:56:44 +0200 Subject: [PATCH 003/139] fix: build for mythirdpartylib --- test/libs/mythirdpartylib/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/libs/mythirdpartylib/CMakeLists.txt b/test/libs/mythirdpartylib/CMakeLists.txt index 87fc6f69..ddc7e17b 100644 --- a/test/libs/mythirdpartylib/CMakeLists.txt +++ b/test/libs/mythirdpartylib/CMakeLists.txt @@ -3,6 +3,9 @@ add_library(mythirdpartylib STATIC src/Foo.cpp) generate_export_header(mythirdpartylib) target_include_directories(mythirdpartylib - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src - PUBLIC "$" "$" + PUBLIC $ + $ ) +target_include_directories(mythirdpartylib + PUBLIC $ +) \ No newline at end of file From 216a39b863bca38a184d5011b1b7bc41ec1d7729 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 23:15:03 +0200 Subject: [PATCH 004/139] fix: build for mythirdpartylib --- test/libs/mythirdpartylib/src/Foo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libs/mythirdpartylib/src/Foo.cpp b/test/libs/mythirdpartylib/src/Foo.cpp index c0397565..304c7c77 100644 --- a/test/libs/mythirdpartylib/src/Foo.cpp +++ b/test/libs/mythirdpartylib/src/Foo.cpp @@ -1,4 +1,4 @@ -#include "Foo.h" +#include "Foo.hpp" namespace mythirdpartylib { From 74f66cb9ff3503319c8bf2391ca61c25b0f96e62 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 23:21:47 +0200 Subject: [PATCH 005/139] fix: build for mythirdpartylib --- test/libs/mythirdpartylib/include/Foo.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/libs/mythirdpartylib/include/Foo.hpp b/test/libs/mythirdpartylib/include/Foo.hpp index 185f02e1..f6e34f04 100644 --- a/test/libs/mythirdpartylib/include/Foo.hpp +++ b/test/libs/mythirdpartylib/include/Foo.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "mythirdpartylib_export.h" @@ -15,7 +16,7 @@ class MYTHIRDPARTYLIB_EXPORT Foo { int a() const { return m_a; } void update(bool b, bool c, bool d); - void bad(std::vector& v); + void bad(std::vector& v); private: int m_a; From b908f192c46c1e7de854de0888d8ad2e87f40a2f Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 23:31:45 +0200 Subject: [PATCH 006/139] fix: build for mythirdpartylib --- test/libs/mythirdpartylib/include/Foo.hpp | 2 +- test/libs/mythirdpartylib/src/Foo.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/libs/mythirdpartylib/include/Foo.hpp b/test/libs/mythirdpartylib/include/Foo.hpp index f6e34f04..24621a36 100644 --- a/test/libs/mythirdpartylib/include/Foo.hpp +++ b/test/libs/mythirdpartylib/include/Foo.hpp @@ -11,7 +11,7 @@ class MYTHIRDPARTYLIB_EXPORT Foo { public: Foo() = default; - /*implicit*/ Foo(int a) m_a(a) {} + /*implicit*/ Foo(int a) : m_a(a) {} int a() const { return m_a; } diff --git a/test/libs/mythirdpartylib/src/Foo.cpp b/test/libs/mythirdpartylib/src/Foo.cpp index 304c7c77..f83ced37 100644 --- a/test/libs/mythirdpartylib/src/Foo.cpp +++ b/test/libs/mythirdpartylib/src/Foo.cpp @@ -7,7 +7,7 @@ void Foo::update(bool b, bool c, bool d) { m_a = e; } -void Foo::bad(std::vector& v) { +void Foo::bad(std::vector& v) { std::string val = "hello"; int index = -1; // bad, plus should use gsl::index for (int i = 0; i < v.size(); ++i) { From 26fd568eaea84f3adbcea7579bd3aeebffe38e8c Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 28 Dec 2022 12:03:34 +0100 Subject: [PATCH 007/139] feat: add disable_exceptions and disable_rtti --- src/DynamicProjectOptions.cmake | 4 ++++ src/Index.cmake | 9 +++++++++ src/Optimization.cmake | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 81641a27..a31938e9 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -78,6 +78,8 @@ macro(dynamic_project_options) "ENABLE_CPPCHECK\;OFF\;${MAKEFILE_OR_NINJA}\;Enable cppcheck analysis during compilation" "ENABLE_INTERPROCEDURAL_OPTIMIZATION\;OFF\;OFF\;Enable whole-program optimization (e.g. LTO)" "ENABLE_NATIVE_OPTIMIZATION\;OFF\;OFF\;Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.)." + "DISABLE_EXCEPTIONS\;OFF\;OFF\;Disable Exceptions (no-exceptions flag)" + "DISABLE_RTTI\;OFF\;OFF\;Disable RTTI (no-rtti flag)" "ENABLE_INCLUDE_WHAT_YOU_USE\;OFF\;OFF\;Enable include-what-you-use analysis during compilation" "ENABLE_PCH\;OFF\;OFF\;Enable pre-compiled-headers support" "ENABLE_DOXYGEN\;OFF\;OFF\;Build documentation with Doxygen" @@ -153,6 +155,8 @@ macro(dynamic_project_options) ${ENABLE_COVERAGE_VALUE} ${ENABLE_INTERPROCEDURAL_OPTIMIZATION_VALUE} ${ENABLE_NATIVE_OPTIMIZATION_VALUE} + ${DISABLE_EXCEPTIONS_VALUE} + ${DISABLE_RTTI_VALUE} ${ENABLE_INCLUDE_WHAT_YOU_USE_VALUE} ${ENABLE_PCH_VALUE} ${ENABLE_DOXYGEN_VALUE} diff --git a/src/Index.cmake b/src/Index.cmake index 42e0baa9..9e0a3229 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -85,6 +85,8 @@ macro(project_options) ENABLE_DOXYGEN ENABLE_INTERPROCEDURAL_OPTIMIZATION ENABLE_NATIVE_OPTIMIZATION + DISABLE_EXCPETIONS + DISABLE_RTTI ENABLE_USER_LINKER ENABLE_BUILD_WITH_TIME_TRACE ENABLE_UNITY @@ -163,6 +165,13 @@ macro(project_options) enable_native_optimization(${_options_target}) endif() + if(${ProjectOptions_DISABLE_EXCPETIONS}) + disable_exceptions(${_options_target}) + endif() + if(${ProjectOptions_DISABLE_RTTI}) + disable_rtti(${_options_target}) + endif() + if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") if(ProjectOptions_ENABLE_BUILD_WITH_TIME_TRACE) target_compile_options(${_options_target} INTERFACE -ftime-trace) diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 7b3991cf..d9d15cc6 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -32,3 +32,13 @@ macro(enable_native_optimization project_name) endif() endif() endmacro() + +macro(disable_exceptions project_name) + target_compile_options(${project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) + target_compile_options(${project_name} INTERFACE $<$>:-fno-exceptions>) +endmacro() + +macro(disable_rtti project_name) + target_compile_options(${project_name} INTERFACE $<$:/GR->) + target_compile_options(${project_name} INTERFACE $<$>:-fno-rtti>) +endmacro() \ No newline at end of file From b6957721109d7f8a10a7f04f28615727f3fd84bd Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 28 Dec 2022 12:17:02 +0100 Subject: [PATCH 008/139] fix: fmt header in test_minimal project --- test_minimal/CMakeLists.txt | 2 ++ test_minimal/main.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test_minimal/CMakeLists.txt b/test_minimal/CMakeLists.txt index 89094b73..ac178908 100644 --- a/test_minimal/CMakeLists.txt +++ b/test_minimal/CMakeLists.txt @@ -76,6 +76,8 @@ project_options( ${ENABLE_COVERAGE} ${ENABLE_SANITIZER_ADDRESS} ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + # DISABLE_EXCEPTIONS + # DISABLE_RTTI # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors PCH_HEADERS # This is a list of headers to pre-compile, here are some common ones diff --git a/test_minimal/main.cpp b/test_minimal/main.cpp index ec6aeeff..115ff095 100644 --- a/test_minimal/main.cpp +++ b/test_minimal/main.cpp @@ -1,4 +1,4 @@ -#include +#include int main() { fmt::print("Hello World!"); From 9f473b4f61e059edf2b5f3e1cb5094446d2f110e Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 29 Dec 2022 16:56:04 +0100 Subject: [PATCH 009/139] fix: EXCEPTIONS typo --- src/Index.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Index.cmake b/src/Index.cmake index 9e0a3229..531ccd5d 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -85,7 +85,7 @@ macro(project_options) ENABLE_DOXYGEN ENABLE_INTERPROCEDURAL_OPTIMIZATION ENABLE_NATIVE_OPTIMIZATION - DISABLE_EXCPETIONS + DISABLE_EXCEPTIONS DISABLE_RTTI ENABLE_USER_LINKER ENABLE_BUILD_WITH_TIME_TRACE @@ -165,7 +165,7 @@ macro(project_options) enable_native_optimization(${_options_target}) endif() - if(${ProjectOptions_DISABLE_EXCPETIONS}) + if(${ProjectOptions_DISABLE_EXCEPTIONS}) disable_exceptions(${_options_target}) endif() if(${ProjectOptions_DISABLE_RTTI}) From 19f7d5acc92396bf18f7fe918c6d9f9463cc969c Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 29 Dec 2022 17:14:26 +0100 Subject: [PATCH 010/139] feat: add no-unwind-tables flag --- src/DynamicProjectOptions.cmake | 2 +- src/Optimization.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index a31938e9..8e5f4386 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -78,7 +78,7 @@ macro(dynamic_project_options) "ENABLE_CPPCHECK\;OFF\;${MAKEFILE_OR_NINJA}\;Enable cppcheck analysis during compilation" "ENABLE_INTERPROCEDURAL_OPTIMIZATION\;OFF\;OFF\;Enable whole-program optimization (e.g. LTO)" "ENABLE_NATIVE_OPTIMIZATION\;OFF\;OFF\;Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.)." - "DISABLE_EXCEPTIONS\;OFF\;OFF\;Disable Exceptions (no-exceptions flag)" + "DISABLE_EXCEPTIONS\;OFF\;OFF\;Disable Exceptions (no-exceptions and no-unwind-tables flag)" "DISABLE_RTTI\;OFF\;OFF\;Disable RTTI (no-rtti flag)" "ENABLE_INCLUDE_WHAT_YOU_USE\;OFF\;OFF\;Enable include-what-you-use analysis during compilation" "ENABLE_PCH\;OFF\;OFF\;Enable pre-compiled-headers support" diff --git a/src/Optimization.cmake b/src/Optimization.cmake index d9d15cc6..4d2b299f 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -35,7 +35,7 @@ endmacro() macro(disable_exceptions project_name) target_compile_options(${project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) - target_compile_options(${project_name} INTERFACE $<$>:-fno-exceptions>) + target_compile_options(${project_name} INTERFACE $<$>:-fno-exceptions -fno-unwind-tables>) endmacro() macro(disable_rtti project_name) From f0a9521c5295f2cd63103b804031d15e8868d84f Mon Sep 17 00:00:00 2001 From: abeimler Date: Fri, 30 Dec 2022 02:12:44 +0100 Subject: [PATCH 011/139] wip: move test_... into tests --- Taskfile.yml | 133 +-- Taskfile_windows.yml | 12 + docker/Dockerfile | 13 +- docker/Dockerfile.emscripten | 2 +- docker/Dockerfile.mingw | 8 +- docker/Taskfile.yml | 24 + tests/.gitignore | 767 ++++++++++++++++++ {test => tests/emscripten}/.dockerignore | 0 .../emscripten}/CMakeLists.txt | 0 tests/emscripten/Taskfile.yml | 10 + .../emscripten}/main.cpp | 0 .../emscripten}/vcpkg.json | 0 .../install}/.dockerignore | 0 tests/install/.gitignore | 2 + .../install}/CMakeLists.txt | 0 tests/install/Taskfile.yml | 31 + tests/install/Taskfile_windows.yml | 5 + {test => tests/install}/conanfile.txt | 0 .../install}/css/my_custom_theme.css | 0 .../install}/css/my_custom_theme_extra.css | 0 .../install}/src/another_main.cpp | 0 {test_install => tests/install}/vcpkg.json | 0 {test_install => tests/main}/.dockerignore | 0 {test => tests/main}/CMakeLists.txt | 0 tests/main/Taskfile.yml | 33 + tests/main/Taskfile_windows.yml | 5 + {test_install => tests/main}/conanfile.txt | 0 {test => tests/main}/include/mylib/lib.hpp | 0 {test => tests/main}/include/mylib2/lib.hpp | 0 {test => tests/main}/libs/CMakeLists.txt | 0 .../main}/libs/mythirdpartylib/CMakeLists.txt | 0 .../libs/mythirdpartylib/include/Foo.hpp | 0 .../main}/libs/mythirdpartylib/src/Foo.cpp | 0 {test => tests/main}/src/main/main.cpp | 0 {test => tests/main}/src/mylib2/lib.cpp | 0 {test => tests/main}/vcpkg.json | 0 {test_minimal => tests/minimal}/.dockerignore | 0 .../minimal}/CMakeLists.txt | 0 tests/minimal/Taskfile.yml | 34 + {test_minimal => tests/minimal}/main.cpp | 0 {test_minimal => tests/minimal}/vcpkg.json | 0 41 files changed, 956 insertions(+), 123 deletions(-) create mode 100644 Taskfile_windows.yml create mode 100644 docker/Taskfile.yml create mode 100644 tests/.gitignore rename {test => tests/emscripten}/.dockerignore (100%) rename {test_emscripten => tests/emscripten}/CMakeLists.txt (100%) create mode 100644 tests/emscripten/Taskfile.yml rename {test_emscripten => tests/emscripten}/main.cpp (100%) rename {test_emscripten => tests/emscripten}/vcpkg.json (100%) rename {test_emscripten => tests/install}/.dockerignore (100%) create mode 100644 tests/install/.gitignore rename {test_install => tests/install}/CMakeLists.txt (100%) create mode 100644 tests/install/Taskfile.yml create mode 100644 tests/install/Taskfile_windows.yml rename {test => tests/install}/conanfile.txt (100%) rename {test_install => tests/install}/css/my_custom_theme.css (100%) rename {test_install => tests/install}/css/my_custom_theme_extra.css (100%) rename {test_install => tests/install}/src/another_main.cpp (100%) rename {test_install => tests/install}/vcpkg.json (100%) rename {test_install => tests/main}/.dockerignore (100%) rename {test => tests/main}/CMakeLists.txt (100%) create mode 100644 tests/main/Taskfile.yml create mode 100644 tests/main/Taskfile_windows.yml rename {test_install => tests/main}/conanfile.txt (100%) rename {test => tests/main}/include/mylib/lib.hpp (100%) rename {test => tests/main}/include/mylib2/lib.hpp (100%) rename {test => tests/main}/libs/CMakeLists.txt (100%) rename {test => tests/main}/libs/mythirdpartylib/CMakeLists.txt (100%) rename {test => tests/main}/libs/mythirdpartylib/include/Foo.hpp (100%) rename {test => tests/main}/libs/mythirdpartylib/src/Foo.cpp (100%) rename {test => tests/main}/src/main/main.cpp (100%) rename {test => tests/main}/src/mylib2/lib.cpp (100%) rename {test => tests/main}/vcpkg.json (100%) rename {test_minimal => tests/minimal}/.dockerignore (100%) rename {test_minimal => tests/minimal}/CMakeLists.txt (100%) create mode 100644 tests/minimal/Taskfile.yml rename {test_minimal => tests/minimal}/main.cpp (100%) rename {test_minimal => tests/minimal}/vcpkg.json (100%) diff --git a/Taskfile.yml b/Taskfile.yml index a270dadb..a5cc9ee3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,113 +1,32 @@ -# https://taskfile.dev/#/installation +# https://taskfile.dev/#6/installation version: 3 -tasks: - build: - - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - - cmake --build ./test/build --config Debug - - build_release: - - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - - cmake --build ./test/build --config Release - - build_minimal: - - cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - - cmake --build ./test_minimal/build --config Debug - - test: - - task: build - - cd ./test/build && ctest -C Debug --verbose - - test_release: - - task: build_release - - cd ./test/build && ctest -C Release --verbose - - test_install: - cmds: - - task: test_release - - cmake --install ./test/build --config Release --prefix ./install - - cmake ./test_install -B ./test_install/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; - - cmake --build ./test_install/build --config Release - - cd ./test_install/build && ctest -C Release --verbose - vars: - CWD: - sh: git rev-parse --show-toplevel - - build_mingw: - cmds: - - task: build - vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} - - build_emscripten: - cmds: - - cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=wasm32-emscripten - - cmake --build ./test_emscripten/build --config Debug - - # For Testing - build_minimal_mingw: - cmds: - - task: build_minimal - vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} - - build_minimal_mingw_from_env: - env: - CC: x86_64-w64-mingw32-gcc - CXX: x86_64-w64-mingw32-g++ - cmds: - - task: build_minimal - vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON - - build_minimal_mingw_from_triplet: - cmds: - - task: build_minimal - vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic - - test_docker: - - docker-compose up --build build-gcc - - docker-compose up --build test-gcc - - docker-compose down build-gcc test-gcc - - test_docker_llvm: - - docker-compose up --build build-llvm - - docker-compose up --build test-llvm - - docker-compose down build-llvm test-llvm - - test_docker_mingw: - - docker-compose up --build minimal-build-mingw-x64 - - docker-compose up --build minimal-build-mingw-x64-from-env - - docker-compose up --build minimal-build-mingw-x64-from-triplet - - docker-compose up --build build-mingw-x64 - - docker-compose up --build build-mingw-x86 - - docker-compose down minimal-build-mingw-x64 minimal-build-mingw-x64-from-triplet minimal-build-mingw-x64-from-env build-mingw-x64 build-mingw-x86 - - test_docker_emscripten: - - docker-compose up --build build-emscripten - - docker-compose down build-emscripten +includes: + windows: ./Taskfile_windows.yml + docker: ./docker/Taskfile.yml + main: + taskfile: ./tests/main/Taskfile.yml + dir: ./tests/main + install: + taskfile: ./tests/install/Taskfile.yml + dir: ./tests/install + minimal: + taskfile: ./tests/minimal/Taskfile.yml + dir: ./tests/minimal + emscripten: + taskfile: ./tests/emscripten/Taskfile.yml + dir: ./tests/emscripten +tasks: lint: - - | - {{if eq OS "windows"}} - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' - {{else}} - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file - {{end}} - - | - {{if eq OS "windows"}} - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }' - {{else}} - git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations - {{end}} - - - ~/vcpkg/vcpkg format-manifest ./test/vcpkg.json ./test_install/vcpkg.json + - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file + - git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations + - task: main:lint + - task: install:lint + - task: minimal:lint + - task: emscripten:lint - npx -y cspell lint --no-progress --show-suggestions - clean: | - {{if eq OS "windows"}} - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./test/build; rmrf ./test_install/build/; rmrf ./install' - {{else}} - rm -rf ./test/build ./test_install/build/ ./install - {{end}} + clean: + - task: main:clean + - task: install:clean diff --git a/Taskfile_windows.yml b/Taskfile_windows.yml new file mode 100644 index 00000000..ea8a59cc --- /dev/null +++ b/Taskfile_windows.yml @@ -0,0 +1,12 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + lint: + - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' + - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }' + - ~/vcpkg/vcpkg format-manifest ./test/vcpkg.json ./test_install/vcpkg.json + - npx -y cspell lint --no-progress --show-suggestions + + clean: + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./test/build; rmrf ./test_install/build/; rmrf ./install' diff --git a/docker/Dockerfile b/docker/Dockerfile index 612437e1..4690d053 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,20 +21,11 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_minimal"] +CMD ["/bin/bash", "-c", "task minimal:build"] FROM setup AS test COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task test"] +CMD ["/bin/bash", "-c", "task main:test"] - -#FROM setup AS build_release -#COPY . /home/project_options -#WORKDIR /home/project_options -#CMD ["task build_release"] -#FROM gcr.io/distroless/cc AS runner -#COPY --from=build_release /home/project_options/test/build/Release/ /home/app/ -#WORKDIR /home/app/ -#ENTRYPOINT ["./build/main"] diff --git a/docker/Dockerfile.emscripten b/docker/Dockerfile.emscripten index f9d409bb..578c6c40 100644 --- a/docker/Dockerfile.emscripten +++ b/docker/Dockerfile.emscripten @@ -33,4 +33,4 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_emscripten"] +CMD ["/bin/bash", "-c", "task emscripten:build"] diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index 44b50fec..57522c46 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -26,22 +26,22 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_mingw"] +CMD ["/bin/bash", "-c", "task main:build:mingw"] FROM setup AS build-minimal COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_minimal_mingw"] +CMD ["/bin/bash", "-c", "task minimal:build:mingw"] FROM setup AS build-minimal-from-env COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_minimal_mingw_from_env"] +CMD ["/bin/bash", "-c", "task minimal:build:mingw-from-env"] FROM setup AS build-minimal-from-triplet COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task build_minimal_mingw_from_triplet"] +CMD ["/bin/bash", "-c", "task minimal:build:mingw:from-triplet"] diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml new file mode 100644 index 00000000..78a0f278 --- /dev/null +++ b/docker/Taskfile.yml @@ -0,0 +1,24 @@ +version: 3 + +tasks: + gcc: + - docker-compose up --build build-gcc + - docker-compose up --build test-gcc + - docker-compose down build-gcc test-gcc + + llvm: + - docker-compose up --build build-llvm + - docker-compose up --build test-llvm + - docker-compose down build-llvm test-llvm + + mingw: + - docker-compose up --build minimal-build-mingw-x64 + - docker-compose up --build minimal-build-mingw-x64-from-env + - docker-compose up --build minimal-build-mingw-x64-from-triplet + - docker-compose up --build build-mingw-x64 + - docker-compose up --build build-mingw-x86 + - docker-compose down minimal-build-mingw-x64 minimal-build-mingw-x64-from-triplet minimal-build-mingw-x64-from-env build-mingw-x64 build-mingw-x86 + + emscripten: + - docker-compose up --build build-emscripten + - docker-compose down build-emscripten \ No newline at end of file diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..2eb463c9 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,767 @@ +!install/ + +# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### OSX ### +# General + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +*.code-workspace + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs + +# JetBrains Rider +*.sln.iml + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node \ No newline at end of file diff --git a/test/.dockerignore b/tests/emscripten/.dockerignore similarity index 100% rename from test/.dockerignore rename to tests/emscripten/.dockerignore diff --git a/test_emscripten/CMakeLists.txt b/tests/emscripten/CMakeLists.txt similarity index 100% rename from test_emscripten/CMakeLists.txt rename to tests/emscripten/CMakeLists.txt diff --git a/tests/emscripten/Taskfile.yml b/tests/emscripten/Taskfile.yml new file mode 100644 index 00000000..6a81e2af --- /dev/null +++ b/tests/emscripten/Taskfile.yml @@ -0,0 +1,10 @@ +version: 3 + +tasks: + build: + cmds: + - cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=wasm32-emscripten + - cmake --build ./test_emscripten/build --config Debug + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/test_emscripten/main.cpp b/tests/emscripten/main.cpp similarity index 100% rename from test_emscripten/main.cpp rename to tests/emscripten/main.cpp diff --git a/test_emscripten/vcpkg.json b/tests/emscripten/vcpkg.json similarity index 100% rename from test_emscripten/vcpkg.json rename to tests/emscripten/vcpkg.json diff --git a/test_emscripten/.dockerignore b/tests/install/.dockerignore similarity index 100% rename from test_emscripten/.dockerignore rename to tests/install/.dockerignore diff --git a/tests/install/.gitignore b/tests/install/.gitignore new file mode 100644 index 00000000..f3962a15 --- /dev/null +++ b/tests/install/.gitignore @@ -0,0 +1,2 @@ +build/ +install/ \ No newline at end of file diff --git a/test_install/CMakeLists.txt b/tests/install/CMakeLists.txt similarity index 100% rename from test_install/CMakeLists.txt rename to tests/install/CMakeLists.txt diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml new file mode 100644 index 00000000..463984dd --- /dev/null +++ b/tests/install/Taskfile.yml @@ -0,0 +1,31 @@ +# https://taskfile.dev/#6/installation +version: 3 + +includes: + windows: ./Taskfile_windows.yml + +tasks: + build:release: + - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release + + test:release: + - task: build:release + - cd ./build && ctest -C Release --verbose + + install: + cmds: + - task: test:release + - cmake --install ./build --config Release --prefix ./install + - cmake ./test_install -B ./test_install/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; + - cmake --build ./test_install/build --config Release + - cd ./build && ctest -C Release --verbose + vars: + CWD: + sh: git rev-parse --show-toplevel + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json + + clean: + - rm -rf ./build diff --git a/tests/install/Taskfile_windows.yml b/tests/install/Taskfile_windows.yml new file mode 100644 index 00000000..4332414f --- /dev/null +++ b/tests/install/Taskfile_windows.yml @@ -0,0 +1,5 @@ +version: 3 + +tasks: + clean: + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build/; rmrf ./install' diff --git a/test/conanfile.txt b/tests/install/conanfile.txt similarity index 100% rename from test/conanfile.txt rename to tests/install/conanfile.txt diff --git a/test_install/css/my_custom_theme.css b/tests/install/css/my_custom_theme.css similarity index 100% rename from test_install/css/my_custom_theme.css rename to tests/install/css/my_custom_theme.css diff --git a/test_install/css/my_custom_theme_extra.css b/tests/install/css/my_custom_theme_extra.css similarity index 100% rename from test_install/css/my_custom_theme_extra.css rename to tests/install/css/my_custom_theme_extra.css diff --git a/test_install/src/another_main.cpp b/tests/install/src/another_main.cpp similarity index 100% rename from test_install/src/another_main.cpp rename to tests/install/src/another_main.cpp diff --git a/test_install/vcpkg.json b/tests/install/vcpkg.json similarity index 100% rename from test_install/vcpkg.json rename to tests/install/vcpkg.json diff --git a/test_install/.dockerignore b/tests/main/.dockerignore similarity index 100% rename from test_install/.dockerignore rename to tests/main/.dockerignore diff --git a/test/CMakeLists.txt b/tests/main/CMakeLists.txt similarity index 100% rename from test/CMakeLists.txt rename to tests/main/CMakeLists.txt diff --git a/tests/main/Taskfile.yml b/tests/main/Taskfile.yml new file mode 100644 index 00000000..0c98d948 --- /dev/null +++ b/tests/main/Taskfile.yml @@ -0,0 +1,33 @@ +version: 3 + +includes: + windows: ./Taskfile_windows.yml + +tasks: + build: + - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Debug + + build:release: + - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release + + test: + - task: build + - cd ./build && ctest -C Debug --verbose + + test:release: + - task: build:release + - cd ./build && ctest -C Release --verbose + + build:mingw: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json + + clean: + - rm -rf ./build diff --git a/tests/main/Taskfile_windows.yml b/tests/main/Taskfile_windows.yml new file mode 100644 index 00000000..34c950c3 --- /dev/null +++ b/tests/main/Taskfile_windows.yml @@ -0,0 +1,5 @@ +version: 3 + +tasks: + clean: + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' diff --git a/test_install/conanfile.txt b/tests/main/conanfile.txt similarity index 100% rename from test_install/conanfile.txt rename to tests/main/conanfile.txt diff --git a/test/include/mylib/lib.hpp b/tests/main/include/mylib/lib.hpp similarity index 100% rename from test/include/mylib/lib.hpp rename to tests/main/include/mylib/lib.hpp diff --git a/test/include/mylib2/lib.hpp b/tests/main/include/mylib2/lib.hpp similarity index 100% rename from test/include/mylib2/lib.hpp rename to tests/main/include/mylib2/lib.hpp diff --git a/test/libs/CMakeLists.txt b/tests/main/libs/CMakeLists.txt similarity index 100% rename from test/libs/CMakeLists.txt rename to tests/main/libs/CMakeLists.txt diff --git a/test/libs/mythirdpartylib/CMakeLists.txt b/tests/main/libs/mythirdpartylib/CMakeLists.txt similarity index 100% rename from test/libs/mythirdpartylib/CMakeLists.txt rename to tests/main/libs/mythirdpartylib/CMakeLists.txt diff --git a/test/libs/mythirdpartylib/include/Foo.hpp b/tests/main/libs/mythirdpartylib/include/Foo.hpp similarity index 100% rename from test/libs/mythirdpartylib/include/Foo.hpp rename to tests/main/libs/mythirdpartylib/include/Foo.hpp diff --git a/test/libs/mythirdpartylib/src/Foo.cpp b/tests/main/libs/mythirdpartylib/src/Foo.cpp similarity index 100% rename from test/libs/mythirdpartylib/src/Foo.cpp rename to tests/main/libs/mythirdpartylib/src/Foo.cpp diff --git a/test/src/main/main.cpp b/tests/main/src/main/main.cpp similarity index 100% rename from test/src/main/main.cpp rename to tests/main/src/main/main.cpp diff --git a/test/src/mylib2/lib.cpp b/tests/main/src/mylib2/lib.cpp similarity index 100% rename from test/src/mylib2/lib.cpp rename to tests/main/src/mylib2/lib.cpp diff --git a/test/vcpkg.json b/tests/main/vcpkg.json similarity index 100% rename from test/vcpkg.json rename to tests/main/vcpkg.json diff --git a/test_minimal/.dockerignore b/tests/minimal/.dockerignore similarity index 100% rename from test_minimal/.dockerignore rename to tests/minimal/.dockerignore diff --git a/test_minimal/CMakeLists.txt b/tests/minimal/CMakeLists.txt similarity index 100% rename from test_minimal/CMakeLists.txt rename to tests/minimal/CMakeLists.txt diff --git a/tests/minimal/Taskfile.yml b/tests/minimal/Taskfile.yml new file mode 100644 index 00000000..984a5110 --- /dev/null +++ b/tests/minimal/Taskfile.yml @@ -0,0 +1,34 @@ +# https://taskfile.dev/#6/installation +version: 3 + +includes: + windows: ./Taskfile_windows.yml + +tasks: + build: + - cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./test_minimal/build --config Debug + + build:mingw: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} + + build:mingw:from-env: + env: + CC: x86_64-w64-mingw32-gcc + CXX: x86_64-w64-mingw32-g++ + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON + + build:mingw:from-triplet: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/test_minimal/main.cpp b/tests/minimal/main.cpp similarity index 100% rename from test_minimal/main.cpp rename to tests/minimal/main.cpp diff --git a/test_minimal/vcpkg.json b/tests/minimal/vcpkg.json similarity index 100% rename from test_minimal/vcpkg.json rename to tests/minimal/vcpkg.json From 0968e44beea1405562673909d030e8a2f524aa27 Mon Sep 17 00:00:00 2001 From: abeimler Date: Fri, 30 Dec 2022 03:09:00 +0100 Subject: [PATCH 012/139] wip: fix task builds --- .github/workflows/ci.emscripten.yml | 2 +- .github/workflows/ci.mingw.yml | 2 +- .github/workflows/ci.yml | 6 +++--- Taskfile.yml | 4 ++++ docker/Dockerfile.mingw | 2 +- tests/emscripten/CMakeLists.txt | 2 +- tests/emscripten/Taskfile.yml | 4 ++-- tests/install/CMakeLists.txt | 2 +- tests/install/Taskfile.yml | 9 +++------ tests/main/CMakeLists.txt | 2 +- tests/main/Taskfile.yml | 4 ++-- tests/minimal/CMakeLists.txt | 2 +- tests/minimal/Taskfile.yml | 4 ++-- tests/minimal/Taskfile_windows.yml | 5 +++++ 14 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 tests/minimal/Taskfile_windows.yml diff --git a/.github/workflows/ci.emscripten.yml b/.github/workflows/ci.emscripten.yml index a6e9c0ba..658fb84d 100644 --- a/.github/workflows/ci.emscripten.yml +++ b/.github/workflows/ci.emscripten.yml @@ -50,6 +50,6 @@ jobs: - name: Build run: | - task build_emscripten + task emscripten:build env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.mingw.yml index fd9271cb..0503bd18 100644 --- a/.github/workflows/ci.mingw.yml +++ b/.github/workflows/ci.mingw.yml @@ -63,7 +63,7 @@ jobs: - name: Build (Minimal) run: | - task build_minimal_mingw + task minimal:build:mingw env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} CROSS_CC: ${{ matrix.cross_cc }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b13ccebe..af834266 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,9 +82,9 @@ jobs: - name: Test run: | - task test - task test_release - task test_install + task main:test + task main:test:release + task install:test env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/Taskfile.yml b/Taskfile.yml index a5cc9ee3..7d3596b7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -17,6 +17,10 @@ includes: taskfile: ./tests/emscripten/Taskfile.yml dir: ./tests/emscripten +vars: + CWD: + sh: git rev-parse --show-toplevel + tasks: lint: - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index 57522c46..263a13fd 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -38,7 +38,7 @@ CMD ["/bin/bash", "-c", "task minimal:build:mingw"] FROM setup AS build-minimal-from-env COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task minimal:build:mingw-from-env"] +CMD ["/bin/bash", "-c", "task minimal:build:mingw:from-env"] FROM setup AS build-minimal-from-triplet diff --git a/tests/emscripten/CMakeLists.txt b/tests/emscripten/CMakeLists.txt index 0eb398ff..6ad782f2 100644 --- a/tests/emscripten/CMakeLists.txt +++ b/tests/emscripten/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_C_STANDARD 99) # FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) # FetchContent_MakeAvailable(_project_options) # include(${_project_options_SOURCE_DIR}/Index.cmake) -include(../src/Index.cmake) +include(../../src/Index.cmake) # opt-in cross-compiling option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) diff --git a/tests/emscripten/Taskfile.yml b/tests/emscripten/Taskfile.yml index 6a81e2af..8a13928d 100644 --- a/tests/emscripten/Taskfile.yml +++ b/tests/emscripten/Taskfile.yml @@ -3,8 +3,8 @@ version: 3 tasks: build: cmds: - - cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=wasm32-emscripten - - cmake --build ./test_emscripten/build --config Debug + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=wasm32-emscripten + - cmake --build ./build --config Debug lint: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/install/CMakeLists.txt b/tests/install/CMakeLists.txt index cad2b825..e3f72443 100644 --- a/tests/install/CMakeLists.txt +++ b/tests/install/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16...3.21) ### Add project_options -include(../src/Index.cmake) +include(../../src/Index.cmake) run_vcpkg() diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml index 463984dd..c8a45ed6 100644 --- a/tests/install/Taskfile.yml +++ b/tests/install/Taskfile.yml @@ -6,7 +6,7 @@ includes: tasks: build:release: - - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Release test:release: @@ -17,12 +17,9 @@ tasks: cmds: - task: test:release - cmake --install ./build --config Release --prefix ./install - - cmake ./test_install -B ./test_install/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; - - cmake --build ./test_install/build --config Release + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; + - cmake --build ./build --config Release - cd ./build && ctest -C Release --verbose - vars: - CWD: - sh: git rev-parse --show-toplevel lint: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index 958871ba..d439ba2f 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD 20) # FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) # FetchContent_MakeAvailable(_project_options) # include(${_project_options_SOURCE_DIR}/Index.cmake) -include(../src/Index.cmake) +include(../../src/Index.cmake) # opt-in cross-compiling option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) diff --git a/tests/main/Taskfile.yml b/tests/main/Taskfile.yml index 0c98d948..8ba3d9f0 100644 --- a/tests/main/Taskfile.yml +++ b/tests/main/Taskfile.yml @@ -5,11 +5,11 @@ includes: tasks: build: - - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Debug build:release: - - cmake ./test -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Release test: diff --git a/tests/minimal/CMakeLists.txt b/tests/minimal/CMakeLists.txt index 89094b73..6cd1e80d 100644 --- a/tests/minimal/CMakeLists.txt +++ b/tests/minimal/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_C_STANDARD 99) # FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) # FetchContent_MakeAvailable(_project_options) # include(${_project_options_SOURCE_DIR}/Index.cmake) -include(../src/Index.cmake) +include(../../src/Index.cmake) # opt-in cross-compiling option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) diff --git a/tests/minimal/Taskfile.yml b/tests/minimal/Taskfile.yml index 984a5110..0d19cf93 100644 --- a/tests/minimal/Taskfile.yml +++ b/tests/minimal/Taskfile.yml @@ -6,8 +6,8 @@ includes: tasks: build: - - cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - - cmake --build ./test_minimal/build --config Debug + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Debug build:mingw: cmds: diff --git a/tests/minimal/Taskfile_windows.yml b/tests/minimal/Taskfile_windows.yml new file mode 100644 index 00000000..34c950c3 --- /dev/null +++ b/tests/minimal/Taskfile_windows.yml @@ -0,0 +1,5 @@ +version: 3 + +tasks: + clean: + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' From 0fb0f87016e2c7029e8b4ceb06bc60640ce8ee65 Mon Sep 17 00:00:00 2001 From: abeimler Date: Fri, 30 Dec 2022 03:18:37 +0100 Subject: [PATCH 013/139] feat: add example cpp_vcpkg_project --- .gitmodules | 3 +++ Taskfile.yml | 1 + examples/Taskfile.yml | 8 ++++++++ examples/cpp_vcpkg_project | 1 + 4 files changed, 13 insertions(+) create mode 100644 .gitmodules create mode 100644 examples/Taskfile.yml create mode 160000 examples/cpp_vcpkg_project diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..bce76249 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "examples/cpp_vcpkg_project"] + path = examples/cpp_vcpkg_project + url = https://github.com/aminya/cpp_vcpkg_project diff --git a/Taskfile.yml b/Taskfile.yml index 7d3596b7..d639d5a1 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,6 +4,7 @@ version: 3 includes: windows: ./Taskfile_windows.yml docker: ./docker/Taskfile.yml + examples: ./examples/Taskfile.yml main: taskfile: ./tests/main/Taskfile.yml dir: ./tests/main diff --git a/examples/Taskfile.yml b/examples/Taskfile.yml new file mode 100644 index 00000000..08cf88bd --- /dev/null +++ b/examples/Taskfile.yml @@ -0,0 +1,8 @@ +version: 3 + +includes: + cpp_vcpkg_project: + taskfile: ./cpp_vcpkg_project/Taskfile.yml + dir: ./cpp_vcpkg_project + vars: + CMAKE_GENERATOR: "Ninja Multi-Config" \ No newline at end of file diff --git a/examples/cpp_vcpkg_project b/examples/cpp_vcpkg_project new file mode 160000 index 00000000..82cc30eb --- /dev/null +++ b/examples/cpp_vcpkg_project @@ -0,0 +1 @@ +Subproject commit 82cc30eb0f6b7fa2925c53aca42149309cbf05bb From 4be1373d481d4a6f68a09cfcef57e8e0eb048766 Mon Sep 17 00:00:00 2001 From: abeimler Date: Fri, 30 Dec 2022 11:31:57 +0100 Subject: [PATCH 014/139] fix: add submodules in CI * update checkout to v3 --- .github/workflows/ci.emscripten.yml | 6 +- .github/workflows/ci.mingw.yml | 8 +- .github/workflows/ci.yml | 4 +- tests/.gitignore | 767 +--------------------------- 4 files changed, 13 insertions(+), 772 deletions(-) diff --git a/.github/workflows/ci.emscripten.yml b/.github/workflows/ci.emscripten.yml index 658fb84d..1ac9b7dd 100644 --- a/.github/workflows/ci.emscripten.yml +++ b/.github/workflows/ci.emscripten.yml @@ -18,9 +18,11 @@ jobs: cmake: - true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + submodules: true - name: Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/vcpkg diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.mingw.yml index 0503bd18..5a83e507 100644 --- a/.github/workflows/ci.mingw.yml +++ b/.github/workflows/ci.mingw.yml @@ -28,9 +28,11 @@ jobs: cross_cc: i686-w64-mingw32-gcc cross_cxx: i686-w64-mingw32-g++ steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + submodules: true - name: Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/vcpkg @@ -39,7 +41,7 @@ jobs: ${{ env.XDG_CACHE_HOME }}/vcpkg/archives ${{ env.LOCALAPPDATA }}\vcpkg\archives ${{ env.APPDATA }}\vcpkg\archives - key: ${{ runner.os }}-mingw-${{ matrix.platform }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} + key: ${{ runner.os }}-mingw-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} restore-keys: | ${{ runner.os }}-${{ env.BUILD_TYPE }}- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af834266..32fbc94c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,8 +50,10 @@ jobs: compiler: "gcc" cmake: true vcvarsall: true - steps: + steps: - uses: actions/checkout@v3 + with: + submodules: true - name: Cache uses: actions/cache@v3 with: diff --git a/tests/.gitignore b/tests/.gitignore index 2eb463c9..c893ed3c 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,767 +1,2 @@ !install/ - -# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node -# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node - -### CLion ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### CLion Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -# https://plugins.jetbrains.com/plugin/7973-sonarlint -.idea/**/sonarlint/ - -# SonarQube Plugin -# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin -.idea/**/sonarIssues.xml - -# Markdown Navigator plugin -# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced -.idea/**/markdown-navigator.xml -.idea/**/markdown-navigator-enh.xml -.idea/**/markdown-navigator/ - -# Cache file creation bug -# See https://youtrack.jetbrains.com/issue/JBR-2257 -.idea/$CACHE_FILE$ - -# CodeStream plugin -# https://plugins.jetbrains.com/plugin/12206-codestream -.idea/codestream.xml - -# Azure Toolkit for IntelliJ plugin -# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij -.idea/**/azureSettings.xml - -### CMake ### -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -### CMake Patch ### -# External projects -*-prefix/ - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### macOS ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### macOS Patch ### -# iCloud generated files -*.icloud - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -### Node Patch ### -# Serverless Webpack directories -.webpack/ - -# Optional stylelint cache - -# SvelteKit build / generate output -.svelte-kit - -### OSX ### -# General - -# Icon must end with two \r - -# Thumbnails - -# Files that might appear in the root of a volume - -# Directories potentially created on remote AFP share - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets - -# Local History for Visual Studio Code -.history/ - -# Built Visual Studio Code Extensions -*.vsix - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history -.ionide - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -### VisualStudio ### -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -*.code-workspace - -# Local History for Visual Studio Code - -# Windows Installer files from build outputs - -# JetBrains Rider -*.sln.iml - -### VisualStudio Patch ### -# Additional files built by Visual Studio - -# End of https://www.toptal.com/developers/gitignore/api/windows,macos,osx,linux,cmake,visualstudio,visualstudiocode,clion,node \ No newline at end of file +build/ \ No newline at end of file From 2e787c3a0ed464dfd82f562cd3928b087db0374b Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 5 Jan 2023 06:14:43 +0100 Subject: [PATCH 015/139] fix: CI task typo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32fbc94c..4c96a6a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: run: | task main:test task main:test:release - task install:test + task install env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} From cd9720635dcad1c8b26140b99531de8fb5d4e14b Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 5 Jan 2023 07:51:20 +0100 Subject: [PATCH 016/139] fix: task install myproj --- .github/workflows/ci.yml | 4 +- .gitignore | 3 +- Taskfile.yml | 11 +++-- tests/install/Taskfile.yml | 14 +++++-- tests/main/Taskfile.yml | 33 --------------- tests/{main => myproj}/.dockerignore | 0 tests/{main => myproj}/CMakeLists.txt | 0 tests/myproj/Taskfile.yml | 42 +++++++++++++++++++ tests/{main => myproj}/Taskfile_windows.yml | 0 tests/{main => myproj}/conanfile.txt | 0 tests/{main => myproj}/include/mylib/lib.hpp | 0 tests/{main => myproj}/include/mylib2/lib.hpp | 0 tests/{main => myproj}/libs/CMakeLists.txt | 0 .../libs/mythirdpartylib/CMakeLists.txt | 0 .../libs/mythirdpartylib/include/Foo.hpp | 0 .../libs/mythirdpartylib/src/Foo.cpp | 0 tests/{main => myproj}/src/main/main.cpp | 0 tests/{main => myproj}/src/mylib2/lib.cpp | 0 tests/{main => myproj}/vcpkg.json | 0 19 files changed, 64 insertions(+), 43 deletions(-) delete mode 100644 tests/main/Taskfile.yml rename tests/{main => myproj}/.dockerignore (100%) rename tests/{main => myproj}/CMakeLists.txt (100%) create mode 100644 tests/myproj/Taskfile.yml rename tests/{main => myproj}/Taskfile_windows.yml (100%) rename tests/{main => myproj}/conanfile.txt (100%) rename tests/{main => myproj}/include/mylib/lib.hpp (100%) rename tests/{main => myproj}/include/mylib2/lib.hpp (100%) rename tests/{main => myproj}/libs/CMakeLists.txt (100%) rename tests/{main => myproj}/libs/mythirdpartylib/CMakeLists.txt (100%) rename tests/{main => myproj}/libs/mythirdpartylib/include/Foo.hpp (100%) rename tests/{main => myproj}/libs/mythirdpartylib/src/Foo.cpp (100%) rename tests/{main => myproj}/src/main/main.cpp (100%) rename tests/{main => myproj}/src/mylib2/lib.cpp (100%) rename tests/{main => myproj}/vcpkg.json (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c96a6a8..e5367107 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,9 +84,7 @@ jobs: - name: Test run: | - task main:test - task main:test:release - task install + task ci:test env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/.gitignore b/.gitignore index e8869e30..04536277 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .cache/ test/build/ install/ -test_install/build/ \ No newline at end of file +test_install/build/ +build/ \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index d639d5a1..6cc29913 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,9 +5,9 @@ includes: windows: ./Taskfile_windows.yml docker: ./docker/Taskfile.yml examples: ./examples/Taskfile.yml - main: - taskfile: ./tests/main/Taskfile.yml - dir: ./tests/main + myproj: + taskfile: ./tests/myproj/Taskfile.yml + dir: ./tests/myproj install: taskfile: ./tests/install/Taskfile.yml dir: ./tests/install @@ -23,6 +23,11 @@ vars: sh: git rev-parse --show-toplevel tasks: + ci:test: + - task: myproj:test + - task: myproj:test:release + - task: install + lint: - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file - git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml index c8a45ed6..e83692e8 100644 --- a/tests/install/Taskfile.yml +++ b/tests/install/Taskfile.yml @@ -3,6 +3,9 @@ version: 3 includes: windows: ./Taskfile_windows.yml + myproj: + taskfile: ../myproj/Taskfile.yml + dir: ../myproj tasks: build:release: @@ -13,10 +16,15 @@ tasks: - task: build:release - cd ./build && ctest -C Release --verbose - install: + install:myproj: + dir: ../myproj cmds: - - task: test:release - - cmake --install ./build --config Release --prefix ./install + - task: myproj:test:release + - cmake --install ./build --config Release --prefix {{.CWD}}/install + + default: + cmds: + - task: install:myproj - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; - cmake --build ./build --config Release - cd ./build && ctest -C Release --verbose diff --git a/tests/main/Taskfile.yml b/tests/main/Taskfile.yml deleted file mode 100644 index 8ba3d9f0..00000000 --- a/tests/main/Taskfile.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: 3 - -includes: - windows: ./Taskfile_windows.yml - -tasks: - build: - - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - - cmake --build ./build --config Debug - - build:release: - - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - - cmake --build ./build --config Release - - test: - - task: build - - cd ./build && ctest -C Debug --verbose - - test:release: - - task: build:release - - cd ./build && ctest -C Release --verbose - - build:mingw: - cmds: - - task: build - vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} - - lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json - - clean: - - rm -rf ./build diff --git a/tests/main/.dockerignore b/tests/myproj/.dockerignore similarity index 100% rename from tests/main/.dockerignore rename to tests/myproj/.dockerignore diff --git a/tests/main/CMakeLists.txt b/tests/myproj/CMakeLists.txt similarity index 100% rename from tests/main/CMakeLists.txt rename to tests/myproj/CMakeLists.txt diff --git a/tests/myproj/Taskfile.yml b/tests/myproj/Taskfile.yml new file mode 100644 index 00000000..5c697b3b --- /dev/null +++ b/tests/myproj/Taskfile.yml @@ -0,0 +1,42 @@ +version: 3 + +includes: + windows: ./Taskfile_windows.yml + +vars: + PROJECT_DIR: '{{.PROJECT_DIR | default "."}}' + +tasks: + build: + - cmake {{.PROJECT_DIR}} -B {{.PROJECT_DIR}}/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build {{.PROJECT_DIR}}/build --config Debug + + build:release: + - cmake {{.PROJECT_DIR}} -B {{.PROJECT_DIR}}/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build {{.PROJECT_DIR}}/build --config Release + + test: + - task: build + - cd {{.PROJECT_DIR}}/build && ctest -C Debug --verbose + + test:release: + - task: build:release + - cd {{.PROJECT_DIR}}/build && ctest -C Release --verbose + + build:mingw: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} + + build:mingw:release: + cmds: + - task: build:release + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json + + clean: + - rm -rf ./build diff --git a/tests/main/Taskfile_windows.yml b/tests/myproj/Taskfile_windows.yml similarity index 100% rename from tests/main/Taskfile_windows.yml rename to tests/myproj/Taskfile_windows.yml diff --git a/tests/main/conanfile.txt b/tests/myproj/conanfile.txt similarity index 100% rename from tests/main/conanfile.txt rename to tests/myproj/conanfile.txt diff --git a/tests/main/include/mylib/lib.hpp b/tests/myproj/include/mylib/lib.hpp similarity index 100% rename from tests/main/include/mylib/lib.hpp rename to tests/myproj/include/mylib/lib.hpp diff --git a/tests/main/include/mylib2/lib.hpp b/tests/myproj/include/mylib2/lib.hpp similarity index 100% rename from tests/main/include/mylib2/lib.hpp rename to tests/myproj/include/mylib2/lib.hpp diff --git a/tests/main/libs/CMakeLists.txt b/tests/myproj/libs/CMakeLists.txt similarity index 100% rename from tests/main/libs/CMakeLists.txt rename to tests/myproj/libs/CMakeLists.txt diff --git a/tests/main/libs/mythirdpartylib/CMakeLists.txt b/tests/myproj/libs/mythirdpartylib/CMakeLists.txt similarity index 100% rename from tests/main/libs/mythirdpartylib/CMakeLists.txt rename to tests/myproj/libs/mythirdpartylib/CMakeLists.txt diff --git a/tests/main/libs/mythirdpartylib/include/Foo.hpp b/tests/myproj/libs/mythirdpartylib/include/Foo.hpp similarity index 100% rename from tests/main/libs/mythirdpartylib/include/Foo.hpp rename to tests/myproj/libs/mythirdpartylib/include/Foo.hpp diff --git a/tests/main/libs/mythirdpartylib/src/Foo.cpp b/tests/myproj/libs/mythirdpartylib/src/Foo.cpp similarity index 100% rename from tests/main/libs/mythirdpartylib/src/Foo.cpp rename to tests/myproj/libs/mythirdpartylib/src/Foo.cpp diff --git a/tests/main/src/main/main.cpp b/tests/myproj/src/main/main.cpp similarity index 100% rename from tests/main/src/main/main.cpp rename to tests/myproj/src/main/main.cpp diff --git a/tests/main/src/mylib2/lib.cpp b/tests/myproj/src/mylib2/lib.cpp similarity index 100% rename from tests/main/src/mylib2/lib.cpp rename to tests/myproj/src/mylib2/lib.cpp diff --git a/tests/main/vcpkg.json b/tests/myproj/vcpkg.json similarity index 100% rename from tests/main/vcpkg.json rename to tests/myproj/vcpkg.json From 9caf698f4ba7dcd11e60661ea6ef0b7c24a280f8 Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 5 Jan 2023 08:08:07 +0100 Subject: [PATCH 017/139] fix: lint tasks --- Taskfile.yml | 5 +++-- Taskfile_windows.yml | 4 ++-- tests/emscripten/vcpkg.json | 2 +- tests/install/Taskfile_windows.yml | 2 +- tests/minimal/vcpkg.json | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 6cc29913..22ee5714 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -31,12 +31,13 @@ tasks: lint: - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file - git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations - - task: main:lint + - task: myproj:lint - task: install:lint - task: minimal:lint - task: emscripten:lint - npx -y cspell lint --no-progress --show-suggestions clean: - - task: main:clean + - task: myproj:clean - task: install:clean + - rm -rf {{.CWD}}/install diff --git a/Taskfile_windows.yml b/Taskfile_windows.yml index ea8a59cc..ca914fa7 100644 --- a/Taskfile_windows.yml +++ b/Taskfile_windows.yml @@ -5,8 +5,8 @@ tasks: lint: - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }' - - ~/vcpkg/vcpkg format-manifest ./test/vcpkg.json ./test_install/vcpkg.json + - ~/vcpkg/vcpkg format-manifest ./tests/emscripten/vcpkg.json ./tests/install/vcpkg.json ./tests/minimal/vcpkg.json ./tests/myproj/vcpkg.json - npx -y cspell lint --no-progress --show-suggestions clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./test/build; rmrf ./test_install/build/; rmrf ./install' + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./tests/myproj/build; rmrf ./tests/install/build; rmrf ./install' diff --git a/tests/emscripten/vcpkg.json b/tests/emscripten/vcpkg.json index 4b34b7c7..10ae29c1 100644 --- a/tests/emscripten/vcpkg.json +++ b/tests/emscripten/vcpkg.json @@ -5,4 +5,4 @@ "magic-enum", "ms-gsl" ] -} \ No newline at end of file +} diff --git a/tests/install/Taskfile_windows.yml b/tests/install/Taskfile_windows.yml index 4332414f..34c950c3 100644 --- a/tests/install/Taskfile_windows.yml +++ b/tests/install/Taskfile_windows.yml @@ -2,4 +2,4 @@ version: 3 tasks: clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build/; rmrf ./install' + - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' diff --git a/tests/minimal/vcpkg.json b/tests/minimal/vcpkg.json index 871859ff..5aa0e59b 100644 --- a/tests/minimal/vcpkg.json +++ b/tests/minimal/vcpkg.json @@ -2,7 +2,7 @@ "name": "example", "version-string": "0.1.0", "dependencies": [ - "ms-gsl", - "fmt" + "fmt", + "ms-gsl" ] -} \ No newline at end of file +} From bbb367cee55be155ddb13970ae7ef77a14b8032c Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Thu, 5 Jan 2023 15:54:21 +0100 Subject: [PATCH 018/139] Fix #185 - make conancenter's remote name to match conan's default --- src/Conan.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Conan.cmake b/src/Conan.cmake index b27200b0..029bc214 100644 --- a/src/Conan.cmake +++ b/src/Conan.cmake @@ -19,10 +19,10 @@ macro(run_conan) include(${CMAKE_BINARY_DIR}/conan.cmake) # Add (or remove) remotes as needed - # conan_add_remote(NAME conan-center URL https://conan.bintray.com) + # conan_add_remote(NAME conan-center URL https://center.conan.io) conan_add_remote( NAME - cci + conancenter URL https://center.conan.io INDEX From f07ffcbdf57ef9622febce29d72ee3988317ee74 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 8 Jan 2023 10:35:51 +0100 Subject: [PATCH 019/139] fix: Taskfile style --- .github/workflows/ci.mingw.yml | 2 +- .github/workflows/ci.yml | 2 +- Taskfile.yml | 4 ++-- tests/install/Taskfile.yml | 12 ++++++------ tests/minimal/Taskfile.yml | 6 +++--- tests/myproj/Taskfile.yml | 12 ++++++------ 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.mingw.yml index 5a83e507..2dee7493 100644 --- a/.github/workflows/ci.mingw.yml +++ b/.github/workflows/ci.mingw.yml @@ -65,7 +65,7 @@ jobs: - name: Build (Minimal) run: | - task minimal:build:mingw + task minimal:build.mingw env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} CROSS_CC: ${{ matrix.cross_cc }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5367107..be081b5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: - name: Test run: | - task ci:test + task ci.test env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/Taskfile.yml b/Taskfile.yml index 22ee5714..9c9af0dd 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -23,9 +23,9 @@ vars: sh: git rev-parse --show-toplevel tasks: - ci:test: + ci.test: - task: myproj:test - - task: myproj:test:release + - task: myproj:test.release - task: install lint: diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml index e83692e8..2c66e944 100644 --- a/tests/install/Taskfile.yml +++ b/tests/install/Taskfile.yml @@ -8,23 +8,23 @@ includes: dir: ../myproj tasks: - build:release: + build.release: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Release - test:release: - - task: build:release + test.release: + - task: build.release - cd ./build && ctest -C Release --verbose - install:myproj: + install.myproj: dir: ../myproj cmds: - - task: myproj:test:release + - task: myproj:test.release - cmake --install ./build --config Release --prefix {{.CWD}}/install default: cmds: - - task: install:myproj + - task: install.myproj - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_PREFIX_PATH:STRING={{.CWD}}/install; - cmake --build ./build --config Release - cd ./build && ctest -C Release --verbose diff --git a/tests/minimal/Taskfile.yml b/tests/minimal/Taskfile.yml index 0d19cf93..c9ceb00a 100644 --- a/tests/minimal/Taskfile.yml +++ b/tests/minimal/Taskfile.yml @@ -9,13 +9,13 @@ tasks: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Debug - build:mingw: + build.mingw: cmds: - task: build vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} - build:mingw:from-env: + build.mingw.from-env: env: CC: x86_64-w64-mingw32-gcc CXX: x86_64-w64-mingw32-g++ @@ -24,7 +24,7 @@ tasks: vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON - build:mingw:from-triplet: + build.mingw.from-triplet: cmds: - task: build vars: diff --git a/tests/myproj/Taskfile.yml b/tests/myproj/Taskfile.yml index 5c697b3b..4818f367 100644 --- a/tests/myproj/Taskfile.yml +++ b/tests/myproj/Taskfile.yml @@ -11,7 +11,7 @@ tasks: - cmake {{.PROJECT_DIR}} -B {{.PROJECT_DIR}}/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build {{.PROJECT_DIR}}/build --config Debug - build:release: + build.release: - cmake {{.PROJECT_DIR}} -B {{.PROJECT_DIR}}/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build {{.PROJECT_DIR}}/build --config Release @@ -19,19 +19,19 @@ tasks: - task: build - cd {{.PROJECT_DIR}}/build && ctest -C Debug --verbose - test:release: - - task: build:release + test.release: + - task: build.release - cd {{.PROJECT_DIR}}/build && ctest -C Release --verbose - build:mingw: + build.mingw: cmds: - task: build vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} - build:mingw:release: + build.mingw.release: cmds: - - task: build:release + - task: build.release vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} From 0e68e4dbbb4934bf7f7a20dbc3ee3dc581bc6b1d Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 9 Jan 2023 15:39:50 +0100 Subject: [PATCH 020/139] fix: CI mingw typo --- .github/workflows/ci.mingw.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.mingw.yml index 2dee7493..846d2a89 100644 --- a/.github/workflows/ci.mingw.yml +++ b/.github/workflows/ci.mingw.yml @@ -41,7 +41,7 @@ jobs: ${{ env.XDG_CACHE_HOME }}/vcpkg/archives ${{ env.LOCALAPPDATA }}\vcpkg\archives ${{ env.APPDATA }}\vcpkg\archives - key: ${{ runner.os }}-mingw-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} + key: ${{ runner.os }}-mingw-${{ matrix.platform }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} restore-keys: | ${{ runner.os }}-${{ env.BUILD_TYPE }}- @@ -61,7 +61,7 @@ jobs: - name: Setup MinGW uses: egor-tensin/setup-mingw@v2 with: - platform: ${{ matrix.cmake }} + platform: ${{ matrix.platform }} - name: Build (Minimal) run: | From dbf13191ecd229cb7a7e2878f4ab4a6888a75312 Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 9 Jan 2023 15:41:09 +0100 Subject: [PATCH 021/139] fix: Docker tasks --- docker-compose.yml | 10 +++++++++- docker/Dockerfile | 10 +++++----- docker/Dockerfile.emscripten | 4 ++-- docker/Dockerfile.mingw | 12 ++++++------ docker/Taskfile.yml | 11 +++++------ 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e038e50e..623cbb7d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,4 +70,12 @@ services: build: context: . dockerfile: ./docker/Dockerfile.mingw - target: build-minimal-from-triplet \ No newline at end of file + target: build-minimal-from-triplet + minimal-build-mingw-x86: + build: + context: . + dockerfile: ./docker/Dockerfile.mingw + target: build-minimal + environment: + - CROSS_CC=i686-w64-mingw32-gcc + - CROSS_CXX=i686-w64-mingw32-g++ \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 4690d053..a8dd7dfe 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,8 +1,8 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.0" +ARG setup_cpp_linux_version="0.24.1" -# add setup_cpp +# add setup_cpp https://github.com/aminya/setup-cpp ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux RUN chmod +x /setup_cpp_linux @@ -11,7 +11,7 @@ FROM base AS setup ARG compiler="gcc" # install cmake, ninja, and ccache -RUN /setup_cpp_linux --compiler $compiler --llvm true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true +RUN /setup_cpp_linux --compiler $compiler --llvm true --cmake true --doxygen true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true COPY ./docker/entrypoint.sh /docker-entrypoint.sh @@ -21,11 +21,11 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task minimal:build"] +CMD ["/bin/bash", "-c", "task myproj:build"] FROM setup AS test COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task main:test"] +CMD ["/bin/bash", "-c", "task myproj:test"] diff --git a/docker/Dockerfile.emscripten b/docker/Dockerfile.emscripten index 578c6c40..27f19412 100644 --- a/docker/Dockerfile.emscripten +++ b/docker/Dockerfile.emscripten @@ -1,8 +1,8 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.0" +ARG setup_cpp_linux_version="0.24.1" -# add setup_cpp +# add setup_cpp https://github.com/aminya/setup-cpp ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux RUN chmod +x /setup_cpp_linux diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index 263a13fd..f3c91859 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -1,8 +1,8 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.0" +ARG setup_cpp_linux_version="0.24.1" -# add setup_cpp +# add setup_cpp https://github.com/aminya/setup-cpp ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux RUN chmod +x /setup_cpp_linux @@ -26,22 +26,22 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task main:build:mingw"] +CMD ["/bin/bash", "-c", "task myproj:build.mingw"] FROM setup AS build-minimal COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task minimal:build:mingw"] +CMD ["/bin/bash", "-c", "task minimal:build.mingw"] FROM setup AS build-minimal-from-env COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task minimal:build:mingw:from-env"] +CMD ["/bin/bash", "-c", "task minimal:build.mingw.from-env"] FROM setup AS build-minimal-from-triplet COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task minimal:build:mingw:from-triplet"] +CMD ["/bin/bash", "-c", "task minimal:build.mingw.from-triplet"] diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 78a0f278..19dd8d3d 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -4,21 +4,20 @@ tasks: gcc: - docker-compose up --build build-gcc - docker-compose up --build test-gcc - - docker-compose down build-gcc test-gcc + - docker-compose down llvm: - docker-compose up --build build-llvm - docker-compose up --build test-llvm - - docker-compose down build-llvm test-llvm + - docker-compose down mingw: - docker-compose up --build minimal-build-mingw-x64 - docker-compose up --build minimal-build-mingw-x64-from-env - docker-compose up --build minimal-build-mingw-x64-from-triplet - - docker-compose up --build build-mingw-x64 - - docker-compose up --build build-mingw-x86 - - docker-compose down minimal-build-mingw-x64 minimal-build-mingw-x64-from-triplet minimal-build-mingw-x64-from-env build-mingw-x64 build-mingw-x86 + - docker-compose up --build minimal-build-mingw-x86 + - docker-compose down emscripten: - docker-compose up --build build-emscripten - - docker-compose down build-emscripten \ No newline at end of file + - docker-compose down \ No newline at end of file From 239fbd41f55381e6525d3e0eae8bd8260f79bca2 Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 11 Jan 2023 08:32:18 +0100 Subject: [PATCH 022/139] feat: add arm triplets in enable_cross_compiler --- src/CrossCompiler.cmake | 52 ++++++++++++++++++- src/toolchains/aarch64.toolchain.cmake | 30 +++++++++++ src/toolchains/arm.toolchain.cmake | 30 +++++++++++ src/toolchains/arm64.toolchain.cmake | 30 +++++++++++ .../i686-w64-mingw32.toolchain.cmake | 9 ++-- .../x86_64-w64-mingw32.toolchain.cmake | 9 ++-- 6 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 src/toolchains/aarch64.toolchain.cmake create mode 100644 src/toolchains/arm.toolchain.cmake create mode 100644 src/toolchains/arm64.toolchain.cmake diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index c2a4f6b0..23608557 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -31,6 +31,10 @@ macro(enable_cross_compiler) set(_cc "emcc") set(_cxx "em++") set(TARGET_ARCHITECTURE "wasm32-emscripten") + elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux") + set(TARGET_ARCHITECTURE "arm-linux") + elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") + set(TARGET_ARCHITECTURE "arm64-linux") endif() if("${TARGET_ARCHITECTURE}" STREQUAL "") @@ -48,6 +52,7 @@ macro(enable_cross_compiler) set(TARGET_ARCHITECTURE "wasm32-emscripten") else() # TODO: check for arm compiler + message(WARNING "if you are using arm cross-compiler, please set DEFAULT_TRIPLET") set(TARGET_ARCHITECTURE ${_arch}) endif() endif() @@ -64,11 +69,20 @@ macro(enable_cross_compiler) set(USE_CROSSCOMPILER_MINGW) set(USE_CROSSCOMPILER_EMSCRIPTEN) + set(USE_CROSSCOMPILER_ARM) + set(USE_CROSSCOMPILER_ARM64) + set(USE_CROSSCOMPILER_AARCH64) if(_cc MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?") set(MINGW TRUE) set(USE_CROSSCOMPILER_MINGW TRUE) elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em\\+\\+") set(USE_CROSSCOMPILER_EMSCRIPTEN TRUE) + elseif(_cc MATCHES "aarch64-linux-gnu-gcc" OR _cxx MATCHES "aarch64-linux-gnu-g\\+\\+") + set(USE_CROSSCOMPILER_AARCH64 TRUE) + elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux") + set(USE_CROSSCOMPILER_ARM TRUE) + elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") + set(USE_CROSSCOMPILER_ARM64 TRUE) endif() set(LIBRARY_LINKAGE) @@ -92,6 +106,26 @@ macro(enable_cross_compiler) set(CROSS_ROOT "/usr/x86_64-w64-mingw32") elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") set(CROSS_ROOT "/usr/i686-w64-mingw32") + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?") + set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabi") + if(NOT DEFINED CROSS_TRIPLET) + set(CROSS_TRIPLET "arm-linux-gnueabi") + endif() + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?") + set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabihf") + if(NOT DEFINED CROSS_TRIPLET) + set(CROSS_TRIPLET "arm-linux-gnueabihf") + endif() + elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?") + set(CROSS_ROOT "/usr/gcc-arm-none-eabi") + if(NOT DEFINED CROSS_TRIPLET) + set(CROSS_TRIPLET "arm-none-eabi") + endif() + elseif(_cc MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?") + set(CROSS_ROOT "/usr/gcc-aarch64-linux-gnu") + if(NOT DEFINED CROSS_TRIPLET) + set(CROSS_TRIPLET "gcc-aarch64-linux-gnu") + endif() endif() # TODO: check if path is right, check for header files or something endif() @@ -133,7 +167,9 @@ macro(enable_cross_compiler) set(_toolchain_file) get_toolchain_file(_toolchain_file) - set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) + endif() set(CROSSCOMPILING TRUE) message(STATUS "enable cross-compiling") @@ -183,5 +219,19 @@ function(get_toolchain_file value) else() message(ERROR "EMSCRIPTEN_ROOT is not set, please define EMSCRIPTEN_ROOT (emscripten repo)") endif() + elseif(USE_CROSSCOMPILER_AARCH64) + set(${value} + ${ProjectOptions_SRC_DIR}/toolchains/aarch64.toolchain.cmake + PARENT_SCOPE) + elseif(USE_CROSSCOMPILER_ARM) + set(${value} + ${ProjectOptions_SRC_DIR}/toolchains/arm.toolchain.cmake + PARENT_SCOPE) + elseif(USE_CROSSCOMPILER_ARM64) + set(${value} + ${ProjectOptions_SRC_DIR}/toolchains/arm64.toolchain.cmake + PARENT_SCOPE) + elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux" OR "${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") + message(STATUS "Don't forget to provide an cmake-toolchain file (for ${DEFAULT_TRIPLET})") endif() endfunction() diff --git a/src/toolchains/aarch64.toolchain.cmake b/src/toolchains/aarch64.toolchain.cmake new file mode 100644 index 00000000..9035cb5d --- /dev/null +++ b/src/toolchains/aarch64.toolchain.cmake @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +if(CROSS_ROOT) + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) +elseif("${CMAKE_SYSROOT}" STREQUAL "") + #set(CMAKE_SYSROOT /usr/aarch64-linux-gnu) + set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) +endif() + +if(CROSS_C) + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +endif() +if(CROSS_CXX) + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/src/toolchains/arm.toolchain.cmake b/src/toolchains/arm.toolchain.cmake new file mode 100644 index 00000000..a2238f0b --- /dev/null +++ b/src/toolchains/arm.toolchain.cmake @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +if(CROSS_ROOT) + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) +elseif("${CMAKE_SYSROOT}" STREQUAL "") + set(CMAKE_SYSROOT /usr/${CROSS_TRIPLET}) + #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) +endif() + +if(CROSS_C) + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) +endif() +if(CROSS_CXX) + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file diff --git a/src/toolchains/arm64.toolchain.cmake b/src/toolchains/arm64.toolchain.cmake new file mode 100644 index 00000000..396366d7 --- /dev/null +++ b/src/toolchains/arm64.toolchain.cmake @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm64) + +if(CROSS_ROOT) + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) +elseif("${CMAKE_SYSROOT}" STREQUAL "") + set(CMAKE_SYSROOT /usr/${CROSS_TRIPLET}) + #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) +endif() + +if(CROSS_C) + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) +endif() +if(CROSS_CXX) + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file diff --git a/src/toolchains/i686-w64-mingw32.toolchain.cmake b/src/toolchains/i686-w64-mingw32.toolchain.cmake index 61f6d207..0ba729fd 100644 --- a/src/toolchains/i686-w64-mingw32.toolchain.cmake +++ b/src/toolchains/i686-w64-mingw32.toolchain.cmake @@ -3,12 +3,9 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "i686") -if(NOT - "$ENV{CROSS_ROOT}" - STREQUAL - "") - set(CMAKE_SYSROOT $ENV{CROSS_ROOT}) - #set(CMAKE_FIND_ROOT_PATH $ENV{CROSS_ROOT}) +if(CROSS_ROOT) + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") set(CMAKE_SYSROOT /usr/i686-w64-mingw32) #set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) diff --git a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake index c2a1b6eb..ad234935 100644 --- a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake +++ b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake @@ -3,12 +3,9 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "x64") -if(NOT - "$ENV{CROSS_ROOT}" - STREQUAL - "") - set(CMAKE_SYSROOT $ENV{CROSS_ROOT}) - #set(CMAKE_FIND_ROOT_PATH $ENV{CROSS_ROOT}) +if(CROSS_ROOT) + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") set(CMAKE_SYSROOT /usr/x86_64-w64-mingw32) #set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) From 65afa0a6fc1fbedca5cc40a50c192442212d0def Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 11 Jan 2023 08:36:45 +0100 Subject: [PATCH 023/139] feat: add arm docker tests --- Taskfile.yml | 13 +++ docker-compose.yml | 42 +++++++- docker/Dockerfile.aarch64 | 52 ++++++++++ docker/Dockerfile.arm | 33 ++++++ docker/Dockerfile.pico | 37 +++++++ docker/Taskfile.yml | 32 ++++++ tests/pico/.dockerignore | 8 ++ tests/pico/.gitignore | 7 ++ tests/pico/CMakeLists.txt | 119 +++++++++++++++++++++ tests/pico/LICENSE.TXT | 21 ++++ tests/pico/Taskfile.yml | 10 ++ tests/pico/hello_world.c | 8 ++ tests/pico/pico_sdk_import.cmake | 73 +++++++++++++ tests/pico/vcpkg.json | 8 ++ tests/rpi3/.dockerignore | 1 + tests/rpi3/CMakeLists.txt | 120 +++++++++++++++++++++ tests/rpi3/Taskfile.yml | 26 +++++ tests/rpi3/main.c | 6 ++ tests/rpi3/main.cpp | 6 ++ tests/rpi3/vcpkg.json | 8 ++ tests/rpi4-vcpkg/.dockerignore | 1 + tests/rpi4-vcpkg/CMakeLists.txt | 121 ++++++++++++++++++++++ tests/rpi4-vcpkg/Taskfile.yml | 16 +++ tests/rpi4-vcpkg/cmake/my-toolchain.cmake | 15 +++ tests/rpi4-vcpkg/main.cpp | 6 ++ tests/rpi4-vcpkg/vcpkg.json | 8 ++ tests/rpi4/.dockerignore | 1 + tests/rpi4/CMakeLists.txt | 112 ++++++++++++++++++++ tests/rpi4/Taskfile.yml | 32 ++++++ tests/rpi4/cmake/my-toolchain.cmake | 15 +++ tests/rpi4/main.cpp | 6 ++ tests/rpi4/vcpkg.json | 8 ++ 32 files changed, 970 insertions(+), 1 deletion(-) create mode 100644 docker/Dockerfile.aarch64 create mode 100644 docker/Dockerfile.arm create mode 100644 docker/Dockerfile.pico create mode 100644 tests/pico/.dockerignore create mode 100644 tests/pico/.gitignore create mode 100644 tests/pico/CMakeLists.txt create mode 100644 tests/pico/LICENSE.TXT create mode 100644 tests/pico/Taskfile.yml create mode 100644 tests/pico/hello_world.c create mode 100644 tests/pico/pico_sdk_import.cmake create mode 100644 tests/pico/vcpkg.json create mode 100644 tests/rpi3/.dockerignore create mode 100644 tests/rpi3/CMakeLists.txt create mode 100644 tests/rpi3/Taskfile.yml create mode 100644 tests/rpi3/main.c create mode 100644 tests/rpi3/main.cpp create mode 100644 tests/rpi3/vcpkg.json create mode 100644 tests/rpi4-vcpkg/.dockerignore create mode 100644 tests/rpi4-vcpkg/CMakeLists.txt create mode 100644 tests/rpi4-vcpkg/Taskfile.yml create mode 100644 tests/rpi4-vcpkg/cmake/my-toolchain.cmake create mode 100644 tests/rpi4-vcpkg/main.cpp create mode 100644 tests/rpi4-vcpkg/vcpkg.json create mode 100644 tests/rpi4/.dockerignore create mode 100644 tests/rpi4/CMakeLists.txt create mode 100644 tests/rpi4/Taskfile.yml create mode 100644 tests/rpi4/cmake/my-toolchain.cmake create mode 100644 tests/rpi4/main.cpp create mode 100644 tests/rpi4/vcpkg.json diff --git a/Taskfile.yml b/Taskfile.yml index 9c9af0dd..dc241b02 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -17,6 +17,18 @@ includes: emscripten: taskfile: ./tests/emscripten/Taskfile.yml dir: ./tests/emscripten + rpi3: + taskfile: ./tests/rpi3/Taskfile.yml + dir: ./tests/rpi3 + rpi4: + taskfile: ./tests/rpi4/Taskfile.yml + dir: ./tests/rpi4 + rpi4-vcpkg: + taskfile: ./tests/rpi4-vcpkg/Taskfile.yml + dir: ./tests/rpi4-vcpkg + pico: + taskfile: ./tests/pico/Taskfile.yml + dir: ./tests/pico vars: CWD: @@ -35,6 +47,7 @@ tasks: - task: install:lint - task: minimal:lint - task: emscripten:lint + - task: rpi:lint - npx -y cspell lint --no-progress --show-suggestions clean: diff --git a/docker-compose.yml b/docker-compose.yml index 623cbb7d..27f88a16 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -78,4 +78,44 @@ services: target: build-minimal environment: - CROSS_CC=i686-w64-mingw32-gcc - - CROSS_CXX=i686-w64-mingw32-g++ \ No newline at end of file + - CROSS_CXX=i686-w64-mingw32-g++ + build-rpi3: + build: + context: . + dockerfile: ./docker/Dockerfile.arm + target: build + build-rpi3-release: + build: + context: . + dockerfile: ./docker/Dockerfile.arm + target: build-release + build-rpi4: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build + build-rpi4-release: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build-release + test-rpi4: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: test + build-rpi4-vcpkg: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build-vcpkg + build-rpi4-custom: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build-custom + build-pico: + build: + context: . + dockerfile: ./docker/Dockerfile.pico + target: build \ No newline at end of file diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 new file mode 100644 index 00000000..46f7bcec --- /dev/null +++ b/docker/Dockerfile.aarch64 @@ -0,0 +1,52 @@ +FROM ubuntu:22.04 AS base + +ARG setup_cpp_linux_version="0.24.1" + +# add setup_cpp https://github.com/aminya/setup-cpp +ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux +RUN chmod +x /setup_cpp_linux + + + +FROM base AS setup + +# install cmake, ninja, and ccache +RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true + +RUN apt-get update && apt-get install -y \ + g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \ + && rm -rf /var/lib/apt/lists/* + +COPY ./docker/entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] + + +FROM setup AS build +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi4:build.cross"] + +FROM setup AS build-release +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi4:build.cross.release"] + +FROM setup AS build-vcpkg +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi4-vcpkg:build.cross"] + +FROM setup AS build-custom +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi4:build.cross.custom-toolchain"] + + +FROM setup AS test +RUN apt-get update && apt-get install -y \ + qemu-user \ + && rm -rf /var/lib/apt/lists/* +COPY . /home/project_options +WORKDIR /home/project_options +ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu +CMD ["/bin/bash", "-c", "task rpi4:build.cross.release && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm new file mode 100644 index 00000000..2e581801 --- /dev/null +++ b/docker/Dockerfile.arm @@ -0,0 +1,33 @@ +FROM ubuntu:22.04 AS base + +ARG setup_cpp_linux_version="0.24.1" + +# add setup_cpp https://github.com/aminya/setup-cpp +ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux +RUN chmod +x /setup_cpp_linux + + + +FROM base AS setup + +# install cmake, ninja, and ccache +RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true + +RUN apt-get update && apt-get install -y \ + gcc-arm-none-eabi binutils-arm-none-eabi \ + && rm -rf /var/lib/apt/lists/* + +COPY ./docker/entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] + + +FROM setup AS build +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi3:build.cross"] + + +FROM setup AS build-release +COPY . /home/project_options +WORKDIR /home/project_options +CMD ["/bin/bash", "-c", "task rpi3:build.cross.release"] \ No newline at end of file diff --git a/docker/Dockerfile.pico b/docker/Dockerfile.pico new file mode 100644 index 00000000..a140c263 --- /dev/null +++ b/docker/Dockerfile.pico @@ -0,0 +1,37 @@ +FROM ubuntu:22.04 AS base + +ARG setup_cpp_linux_version="0.24.1" + +# add setup_cpp https://github.com/aminya/setup-cpp +ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux +RUN chmod +x /setup_cpp_linux + + + +FROM base AS setup + +# install cmake, ninja, and ccache +RUN /setup_cpp_linux --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true + +RUN apt-get update && apt-get install -y \ + gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \ + && rm -rf /var/lib/apt/lists/* + +# https://github.com/raspberrypi/pico-sdk +RUN git clone https://github.com/raspberrypi/pico-sdk /home/pico-sdk +ENV PICO_SDK_PATH /home/pico-sdk +WORKDIR /home/pico-sdk +RUN git submodule update --init +WORKDIR / + +COPY ./docker/entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] + + +FROM setup AS build +COPY . /home/project_options +RUN cp -rf /home/pico-sdk/external/pico_sdk_import.cmake /home/project_options/tests/pico/pico_sdk_import.cmake +WORKDIR /home/project_options +ENV PROJECT_DIR /home/project_options +CMD ["/bin/bash", "-c", "task pico:build"] + diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 19dd8d3d..0facf3d7 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -20,4 +20,36 @@ tasks: emscripten: - docker-compose up --build build-emscripten + - docker-compose down + + rpi3: + - docker-compose up --build build-rpi3 + - docker-compose down + + rpi3.release: + - docker-compose up --build build-rpi3-release + - docker-compose down + + rpi4: + - docker-compose up --build build-rpi4 + - docker-compose down + + rpi4.release: + - docker-compose up --build build-rpi4-release + - docker-compose down + + rpi4.test: + - docker-compose up --build test-rpi4 + - docker-compose down + + rpi4.vcpkg: + - docker-compose up --build build-rpi4-vcpkg + - docker-compose down + + rpi4.custom: + - docker-compose up --build build-rpi4-custom + - docker-compose down + + pico: + - docker-compose up --build build-pico - docker-compose down \ No newline at end of file diff --git a/tests/pico/.dockerignore b/tests/pico/.dockerignore new file mode 100644 index 00000000..98f8675f --- /dev/null +++ b/tests/pico/.dockerignore @@ -0,0 +1,8 @@ +build/ +.idea +.vscode +_deps +cmake-* +build +.DS_Store +*.pdf \ No newline at end of file diff --git a/tests/pico/.gitignore b/tests/pico/.gitignore new file mode 100644 index 00000000..9a4a7f5d --- /dev/null +++ b/tests/pico/.gitignore @@ -0,0 +1,7 @@ +.idea +.vscode +_deps +cmake-* +build +.DS_Store +*.pdf \ No newline at end of file diff --git a/tests/pico/CMakeLists.txt b/tests/pico/CMakeLists.txt new file mode 100644 index 00000000..71288af6 --- /dev/null +++ b/tests/pico/CMakeLists.txt @@ -0,0 +1,119 @@ +cmake_minimum_required(VERSION 3.13) + +# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. +# You can later set fine-grained standards for each target using `target_compile_features` +#set(CMAKE_CXX_STANDARD 20) +#set(CMAKE_C_STANDARD 99) + +# initialize pico-sdk from GIT +# (note this can come from environment, CMake cache etc) +#set(PICO_SDK_FETCH_FROM_GIT on) + +# Pull in SDK (must be before project) +include(pico_sdk_import.cmake) + + +### Add project_options +# include(FetchContent) +# FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) +# FetchContent_MakeAvailable(_project_options) +# include(${_project_options_SOURCE_DIR}/Index.cmake) +include(../../src/Index.cmake) + + +#include(example_auto_set_url.cmake) +# Set the project name to your project name, my project isn't very descriptive +project( + pico + VERSION 0.1.0 + LANGUAGES C CXX ASM) + +# initialize the Raspberry Pi Pico SDK +pico_sdk_init() + +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) +set(ENABLE_INCLUDE_WHAT_YOU_USE OFF) + +option(ENABLE_CHECKING "Enable Static analyzer" OFF) +option(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE "Enable Static analyzer for include-what-you-use" OFF) +if(ENABLE_CHECKING) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() +if(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE) + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() + +#option(ENABLE_TESTING "Enable the tests" OFF) +option(DISABLE_SANITIZER "Disable Sanitizer" OFF) +if(ENABLE_TESTING) + if(NOT DEFINED OPT_ENABLE_COVERAGE) + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + endif() + + if(NOT DISABLE_SANITIZER) + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() + endif() +endif() + +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ${ENABLE_INCLUDE_WHAT_YOU_USE} + ENABLE_VS_ANALYSIS + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + #DISABLE_EXCEPTIONS + #DISABLE_RTTI + # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors + PCH_HEADERS + # This is a list of headers to pre-compile, here are some common ones + + + + + + + + CPPCHECK_OPTIONS + --enable=style,performance,warning,portability + --inline-suppr + # We cannot act on a bug/missing feature of cppcheck + --suppress=cppcheckError + --suppress=internalAstError + # if a file does not have an internalAstError, we get an unmatchedSuppression error + --suppress=unmatchedSuppression + --suppress=passedByValue + --suppress=syntaxError + --inconclusive) + +add_executable(hello_world + hello_world.c +) + +# Add pico_stdlib library which aggregates commonly used features +target_link_system_libraries(hello_world PRIVATE pico_stdlib) + +# create map/bin/hex/uf2 file in addition to ELF. +pico_add_extra_outputs(hello_world) + +target_link_libraries(hello_world PRIVATE project_options project_warnings) \ No newline at end of file diff --git a/tests/pico/LICENSE.TXT b/tests/pico/LICENSE.TXT new file mode 100644 index 00000000..e8a64f19 --- /dev/null +++ b/tests/pico/LICENSE.TXT @@ -0,0 +1,21 @@ +Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following + disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/tests/pico/Taskfile.yml b/tests/pico/Taskfile.yml new file mode 100644 index 00000000..7c68737f --- /dev/null +++ b/tests/pico/Taskfile.yml @@ -0,0 +1,10 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + build: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/pico/hello_world.c b/tests/pico/hello_world.c new file mode 100644 index 00000000..42fca187 --- /dev/null +++ b/tests/pico/hello_world.c @@ -0,0 +1,8 @@ +#include +#include "pico/stdlib.h" + +int main() { + setup_default_uart(); + printf("Hello, world!\n"); + return 0; +} \ No newline at end of file diff --git a/tests/pico/pico_sdk_import.cmake b/tests/pico/pico_sdk_import.cmake new file mode 100644 index 00000000..0ba75584 --- /dev/null +++ b/tests/pico/pico_sdk_import.cmake @@ -0,0 +1,73 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE}) \ No newline at end of file diff --git a/tests/pico/vcpkg.json b/tests/pico/vcpkg.json new file mode 100644 index 00000000..5aa0e59b --- /dev/null +++ b/tests/pico/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "example", + "version-string": "0.1.0", + "dependencies": [ + "fmt", + "ms-gsl" + ] +} diff --git a/tests/rpi3/.dockerignore b/tests/rpi3/.dockerignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/tests/rpi3/.dockerignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt new file mode 100644 index 00000000..fd58bcb7 --- /dev/null +++ b/tests/rpi3/CMakeLists.txt @@ -0,0 +1,120 @@ +cmake_minimum_required(VERSION 3.16...3.21) + +# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. +# You can later set fine-grained standards for each target using `target_compile_features` +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 99) + +### Add project_options +# include(FetchContent) +# FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) +# FetchContent_MakeAvailable(_project_options) +# include(${_project_options_SOURCE_DIR}/Index.cmake) +include(../../src/Index.cmake) + +# opt-in cross-compiling +option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) +if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() +endif() + +# Set the project name to your project name, my project isn't very descriptive +project( + example + VERSION 0.1.0 + LANGUAGES C CXX ASM) + +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) +set(ENABLE_INCLUDE_WHAT_YOU_USE OFF) + +option(ENABLE_CHECKING "Enable Static analyzer" OFF) +option(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE "Enable Static analyzer for include-what-you-use" OFF) +if(ENABLE_CHECKING) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() +if(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE) + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() + +#option(ENABLE_TESTING "Enable the tests" OFF) +option(DISABLE_SANITIZER "Disable Sanitizer" OFF) +if(ENABLE_TESTING) + if(NOT DEFINED OPT_ENABLE_COVERAGE) + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + endif() + + if(NOT DISABLE_SANITIZER) + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() + endif() +endif() + +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ${ENABLE_INCLUDE_WHAT_YOU_USE} + ENABLE_VS_ANALYSIS + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + DISABLE_EXCEPTIONS + DISABLE_RTTI + # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors + PCH_HEADERS + # This is a list of headers to pre-compile, here are some common ones + + + + + + + + CPPCHECK_OPTIONS + --enable=style,performance,warning,portability + --inline-suppr + # We cannot act on a bug/missing feature of cppcheck + --suppress=cppcheckError + --suppress=internalAstError + # if a file does not have an internalAstError, we get an unmatchedSuppression error + --suppress=unmatchedSuppression + --suppress=passedByValue + --suppress=syntaxError + --inconclusive) + +#add_executable(example) +#target_sources(example PRIVATE main.cpp) +#target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +#target_link_libraries(example PRIVATE project_options project_warnings) +#target_link_options(example PRIVATE -Wl,--start-group -lgcc -lc -lstdc++ -lm -lrdimon -Wl,--end-group) +#FIXME: linking with c++ (libs) ... /libstdc++.a(cxx11-ios_failure.o): in function `(anonymous namespace)::__io_category_instance()': + +add_executable(example_c) +target_sources(example_c PRIVATE main.c) +target_include_directories(example_c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(example_c PRIVATE project_options project_warnings) + +if(ENABLE_CROSS_COMPILING) + # fix: ...arm-none-eabi/lib/libg.a(lib_a-exit.o): in function `exit': + target_link_options(example_c PRIVATE -Wl,--start-group -lgcc -lc -lm -lrdimon -Wl,--end-group) + + # custom raspberry pi 3 options + target_compile_options(project_options INTERFACE -march=armv8-a -mfpu=neon-fp-armv8 -mthumb) +endif() \ No newline at end of file diff --git a/tests/rpi3/Taskfile.yml b/tests/rpi3/Taskfile.yml new file mode 100644 index 00000000..66e18a40 --- /dev/null +++ b/tests/rpi3/Taskfile.yml @@ -0,0 +1,26 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + build: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Debug + + build.release: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release + + build.cross: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux + + build.cross.release: + cmds: + - task: build.release + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi3/main.c b/tests/rpi3/main.c new file mode 100644 index 00000000..0cee53ff --- /dev/null +++ b/tests/rpi3/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello World\n"); + return 0; +} \ No newline at end of file diff --git a/tests/rpi3/main.cpp b/tests/rpi3/main.cpp new file mode 100644 index 00000000..b94615d2 --- /dev/null +++ b/tests/rpi3/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello World!"; + return 0; +} \ No newline at end of file diff --git a/tests/rpi3/vcpkg.json b/tests/rpi3/vcpkg.json new file mode 100644 index 00000000..5aa0e59b --- /dev/null +++ b/tests/rpi3/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "example", + "version-string": "0.1.0", + "dependencies": [ + "fmt", + "ms-gsl" + ] +} diff --git a/tests/rpi4-vcpkg/.dockerignore b/tests/rpi4-vcpkg/.dockerignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/tests/rpi4-vcpkg/.dockerignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/tests/rpi4-vcpkg/CMakeLists.txt b/tests/rpi4-vcpkg/CMakeLists.txt new file mode 100644 index 00000000..4e37cf94 --- /dev/null +++ b/tests/rpi4-vcpkg/CMakeLists.txt @@ -0,0 +1,121 @@ +cmake_minimum_required(VERSION 3.16...3.21) + +# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. +# You can later set fine-grained standards for each target using `target_compile_features` +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 99) + +### Add project_options +# include(FetchContent) +# FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) +# FetchContent_MakeAvailable(_project_options) +# include(${_project_options_SOURCE_DIR}/Index.cmake) +include(../../src/Index.cmake) + +# opt-in cross-compiling +option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) +if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() +endif() +run_vcpkg() + +# Set the project name to your project name, my project isn't very descriptive +project( + example + VERSION 0.1.0 + LANGUAGES C CXX ASM) + +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) +set(ENABLE_INCLUDE_WHAT_YOU_USE OFF) + +option(ENABLE_CHECKING "Enable Static analyzer" OFF) +option(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE "Enable Static analyzer for include-what-you-use" OFF) +if(ENABLE_CHECKING) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() +if(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE) + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() + +#option(ENABLE_TESTING "Enable the tests" OFF) +option(DISABLE_SANITIZER "Disable Sanitizer" OFF) +if(ENABLE_TESTING) + if(NOT DEFINED OPT_ENABLE_COVERAGE) + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + endif() + + if(NOT DISABLE_SANITIZER) + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() + endif() +endif() + +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ${ENABLE_INCLUDE_WHAT_YOU_USE} + ENABLE_VS_ANALYSIS + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + # DISABLE_EXCEPTIONS + # DISABLE_RTTI + # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors + PCH_HEADERS + # This is a list of headers to pre-compile, here are some common ones + + + + + + + + CPPCHECK_OPTIONS + --enable=style,performance,warning,portability + --inline-suppr + # We cannot act on a bug/missing feature of cppcheck + --suppress=cppcheckError + --suppress=internalAstError + # if a file does not have an internalAstError, we get an unmatchedSuppression error + --suppress=unmatchedSuppression + --suppress=passedByValue + --suppress=syntaxError + --inconclusive) + +find_package(Microsoft.GSL CONFIG REQUIRED) +find_package(fmt CONFIG REQUIRED) + +add_executable(example) +target_sources(example PRIVATE main.cpp) +target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(example PRIVATE project_options project_warnings) +target_link_system_libraries( + example + PRIVATE + Microsoft.GSL::GSL + fmt::fmt-header-only) + +if(ENABLE_CROSS_COMPILING) + # custom raspberry pi 4 options + #target_compile_definitions(project_options INTERFACE -D__ARM_NEON) + target_compile_options(project_options INTERFACE -mcpu=cortex-a72) + #target_compile_options(project_options INTERFACE -march=armv8-a+fp+simd) # use mcpu ? +endif() \ No newline at end of file diff --git a/tests/rpi4-vcpkg/Taskfile.yml b/tests/rpi4-vcpkg/Taskfile.yml new file mode 100644 index 00000000..897106b7 --- /dev/null +++ b/tests/rpi4-vcpkg/Taskfile.yml @@ -0,0 +1,16 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + build: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Debug + + build.cross: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi4-vcpkg/cmake/my-toolchain.cmake b/tests/rpi4-vcpkg/cmake/my-toolchain.cmake new file mode 100644 index 00000000..fb865c50 --- /dev/null +++ b/tests/rpi4-vcpkg/cmake/my-toolchain.cmake @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/tests/rpi4-vcpkg/main.cpp b/tests/rpi4-vcpkg/main.cpp new file mode 100644 index 00000000..115ff095 --- /dev/null +++ b/tests/rpi4-vcpkg/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + fmt::print("Hello World!"); + return 0; +} \ No newline at end of file diff --git a/tests/rpi4-vcpkg/vcpkg.json b/tests/rpi4-vcpkg/vcpkg.json new file mode 100644 index 00000000..5aa0e59b --- /dev/null +++ b/tests/rpi4-vcpkg/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "example", + "version-string": "0.1.0", + "dependencies": [ + "fmt", + "ms-gsl" + ] +} diff --git a/tests/rpi4/.dockerignore b/tests/rpi4/.dockerignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/tests/rpi4/.dockerignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/tests/rpi4/CMakeLists.txt b/tests/rpi4/CMakeLists.txt new file mode 100644 index 00000000..91716760 --- /dev/null +++ b/tests/rpi4/CMakeLists.txt @@ -0,0 +1,112 @@ +cmake_minimum_required(VERSION 3.16...3.21) + +# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. +# You can later set fine-grained standards for each target using `target_compile_features` +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 99) + +### Add project_options +# include(FetchContent) +# FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) +# FetchContent_MakeAvailable(_project_options) +# include(${_project_options_SOURCE_DIR}/Index.cmake) +include(../../src/Index.cmake) + +# opt-in cross-compiling +option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) +if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() +endif() + +# Set the project name to your project name, my project isn't very descriptive +project( + example + VERSION 0.1.0 + LANGUAGES C CXX ASM) + +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) +set(ENABLE_INCLUDE_WHAT_YOU_USE OFF) + +option(ENABLE_CHECKING "Enable Static analyzer" OFF) +option(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE "Enable Static analyzer for include-what-you-use" OFF) +if(ENABLE_CHECKING) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() +if(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE) + set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") +endif() + +#option(ENABLE_TESTING "Enable the tests" OFF) +option(DISABLE_SANITIZER "Disable Sanitizer" OFF) +if(ENABLE_TESTING) + if(NOT DEFINED OPT_ENABLE_COVERAGE) + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + endif() + + if(NOT DISABLE_SANITIZER) + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() + endif() +endif() + +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ${ENABLE_INCLUDE_WHAT_YOU_USE} + ENABLE_VS_ANALYSIS + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + DISABLE_EXCEPTIONS + DISABLE_RTTI + # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors + PCH_HEADERS + # This is a list of headers to pre-compile, here are some common ones + + + + + + + + CPPCHECK_OPTIONS + --enable=style,performance,warning,portability + --inline-suppr + # We cannot act on a bug/missing feature of cppcheck + --suppress=cppcheckError + --suppress=internalAstError + # if a file does not have an internalAstError, we get an unmatchedSuppression error + --suppress=unmatchedSuppression + --suppress=passedByValue + --suppress=syntaxError + --inconclusive) + +add_executable(example) +target_sources(example PRIVATE main.cpp) +target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(example PRIVATE project_options project_warnings) + +if(ENABLE_CROSS_COMPILING) + # custom raspberry pi 4 options + #target_compile_definitions(project_options INTERFACE -D__ARM_NEON) + target_compile_options(project_options INTERFACE -mcpu=cortex-a72) + #target_compile_options(project_options INTERFACE "-march=armv8-a+fp+simd") # use mcpu ? +endif() \ No newline at end of file diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml new file mode 100644 index 00000000..923bcc37 --- /dev/null +++ b/tests/rpi4/Taskfile.yml @@ -0,0 +1,32 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + build: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Debug + + build.release: + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release + + build.cross: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + + build.cross.release: + cmds: + - task: build.release + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + + build.cross.custom-toolchain: + cmds: + - task: build.release + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake + + lint: + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi4/cmake/my-toolchain.cmake b/tests/rpi4/cmake/my-toolchain.cmake new file mode 100644 index 00000000..fb865c50 --- /dev/null +++ b/tests/rpi4/cmake/my-toolchain.cmake @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/tests/rpi4/main.cpp b/tests/rpi4/main.cpp new file mode 100644 index 00000000..b94615d2 --- /dev/null +++ b/tests/rpi4/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello World!"; + return 0; +} \ No newline at end of file diff --git a/tests/rpi4/vcpkg.json b/tests/rpi4/vcpkg.json new file mode 100644 index 00000000..5aa0e59b --- /dev/null +++ b/tests/rpi4/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "example", + "version-string": "0.1.0", + "dependencies": [ + "fmt", + "ms-gsl" + ] +} From d58152d88f9251be878cbe923fcaa80512f09fef Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 11 Jan 2023 10:45:37 +0100 Subject: [PATCH 024/139] feat: add CLANG_TIDY_EXTRA_ARGUMENTS in enable_clang_tidy --- src/Index.cmake | 3 ++- src/StaticAnalyzers.cmake | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Index.cmake b/src/Index.cmake index 531ccd5d..75529101 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -107,6 +107,7 @@ macro(project_options) GCC_WARNINGS CUDA_WARNINGS CPPCHECK_OPTIONS + CLANG_TIDY_EXTRA_ARGUMENTS PCH_HEADERS CONAN_OPTIONS) cmake_parse_arguments( @@ -219,7 +220,7 @@ macro(project_options) endif() if(${ProjectOptions_ENABLE_CLANG_TIDY}) - enable_clang_tidy() + enable_clang_tidy("${ProjectOptions_CLANG_TIDY_EXTRA_ARGUMENTS}") endif() if(${ProjectOptions_ENABLE_VS_ANALYSIS}) diff --git a/src/StaticAnalyzers.cmake b/src/StaticAnalyzers.cmake index b302f027..f1703467 100644 --- a/src/StaticAnalyzers.cmake +++ b/src/StaticAnalyzers.cmake @@ -56,7 +56,7 @@ macro(enable_cppcheck CPPCHECK_OPTIONS) endmacro() # Enable static analysis with clang-tidy -macro(enable_clang_tidy) +macro(enable_clang_tidy CLANG_TIDY_EXTRA_ARGUMENTS) find_program(CLANGTIDY clang-tidy) if(CLANGTIDY) @@ -114,6 +114,9 @@ macro(enable_clang_tidy) endif() endif() + set(CMAKE_C_CLANG_TIDY ${CMAKE_C_CLANG_TIDY} ${CLANG_TIDY_EXTRA_ARGUMENTS}) + set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} ${CLANG_TIDY_EXTRA_ARGUMENTS}) + else() message(${WARNING_MESSAGE} "clang-tidy requested but executable not found") endif() From d57af360af904336ef2191f9d8e8c8719ab524ec Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 11 Jan 2023 10:51:25 +0100 Subject: [PATCH 025/139] wip: add target argument in clang-tidy --- Taskfile.yml | 5 ++++- src/toolchains/aarch64.toolchain.cmake | 8 ++++++++ src/toolchains/arm.toolchain.cmake | 10 +++++++++- src/toolchains/arm64.toolchain.cmake | 10 +++++++++- tests/rpi3/CMakeLists.txt | 7 +++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index dc241b02..2f85760d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -47,7 +47,10 @@ tasks: - task: install:lint - task: minimal:lint - task: emscripten:lint - - task: rpi:lint + - task: rpi3:lint + - task: rpi4:lint + - task: rpi4-vcpkg:lint + - task: pico:lint - npx -y cspell lint --no-progress --show-suggestions clean: diff --git a/src/toolchains/aarch64.toolchain.cmake b/src/toolchains/aarch64.toolchain.cmake index 9035cb5d..73d00afc 100644 --- a/src/toolchains/aarch64.toolchain.cmake +++ b/src/toolchains/aarch64.toolchain.cmake @@ -28,3 +28,11 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# The target triple needs to match the prefix of the binutils exactly +# (e.g. CMake looks for arm-none-eabi-ar) +#set(CLANG_TARGET_TRIPLE ${CROSS_TRIPLET}) +#set(GCC_ARM_TOOLCHAIN_PREFIX ${CROSS_TRIPLET}) +#set(CMAKE_C_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_CXX_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_ASM_COMPILER_TARGET ${CROSS_TRIPLET}) diff --git a/src/toolchains/arm.toolchain.cmake b/src/toolchains/arm.toolchain.cmake index a2238f0b..99a426d7 100644 --- a/src/toolchains/arm.toolchain.cmake +++ b/src/toolchains/arm.toolchain.cmake @@ -27,4 +27,12 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# The target triple needs to match the prefix of the binutils exactly +# (e.g. CMake looks for arm-none-eabi-ar) +#set(CLANG_TARGET_TRIPLE ${CROSS_TRIPLET}) +#set(GCC_ARM_TOOLCHAIN_PREFIX ${CROSS_TRIPLET}) +#set(CMAKE_C_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_CXX_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_ASM_COMPILER_TARGET ${CROSS_TRIPLET}) diff --git a/src/toolchains/arm64.toolchain.cmake b/src/toolchains/arm64.toolchain.cmake index 396366d7..8caeb262 100644 --- a/src/toolchains/arm64.toolchain.cmake +++ b/src/toolchains/arm64.toolchain.cmake @@ -27,4 +27,12 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) \ No newline at end of file +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# The target triple needs to match the prefix of the binutils exactly +# (e.g. CMake looks for arm-none-eabi-ar) +#set(CLANG_TARGET_TRIPLE ${CROSS_TRIPLET}) +#set(GCC_ARM_TOOLCHAIN_PREFIX ${CROSS_TRIPLET}) +#set(CMAKE_C_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_CXX_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_ASM_COMPILER_TARGET ${CROSS_TRIPLET}) diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt index fd58bcb7..7c31a1d3 100644 --- a/tests/rpi3/CMakeLists.txt +++ b/tests/rpi3/CMakeLists.txt @@ -66,6 +66,9 @@ if(ENABLE_TESTING) endif() endif() +if(ENABLE_CROSS_COMPILING) + set(CLANG_TIDY_EXTRA_ARGUMENTS --extra-arg=--target=${CROSS_TRIPLET}) +endif() project_options( ENABLE_CACHE ${ENABLE_CPPCHECK} @@ -87,6 +90,10 @@ project_options( + + CLANG_TIDY_EXTRA_ARGUMENTS + ${CLANG_TIDY_EXTRA_ARGUMENTS} + CPPCHECK_OPTIONS --enable=style,performance,warning,portability --inline-suppr From 2c6b50af19d02886dc80f963f655dc63885946cb Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 16 Jan 2023 21:37:44 +0100 Subject: [PATCH 026/139] fix: clean up tasks * remove pico --- Taskfile.yml | 3 - docker-compose.yml | 15 ++-- docker/Dockerfile.aarch64 | 6 +- docker/Dockerfile.arm | 4 +- tests/pico/.dockerignore | 8 --- tests/pico/.gitignore | 7 -- tests/pico/CMakeLists.txt | 119 ------------------------------- tests/pico/LICENSE.TXT | 21 ------ tests/pico/Taskfile.yml | 10 --- tests/pico/hello_world.c | 8 --- tests/pico/pico_sdk_import.cmake | 73 ------------------- tests/pico/vcpkg.json | 8 --- tests/rpi3/Taskfile.yml | 15 ++-- tests/rpi3/vcpkg.json | 8 --- tests/rpi4-vcpkg/Taskfile.yml | 4 +- tests/rpi4/Taskfile.yml | 15 ++-- tests/rpi4/vcpkg.json | 8 --- 17 files changed, 24 insertions(+), 308 deletions(-) delete mode 100644 tests/pico/.dockerignore delete mode 100644 tests/pico/.gitignore delete mode 100644 tests/pico/CMakeLists.txt delete mode 100644 tests/pico/LICENSE.TXT delete mode 100644 tests/pico/Taskfile.yml delete mode 100644 tests/pico/hello_world.c delete mode 100644 tests/pico/pico_sdk_import.cmake delete mode 100644 tests/pico/vcpkg.json delete mode 100644 tests/rpi3/vcpkg.json delete mode 100644 tests/rpi4/vcpkg.json diff --git a/Taskfile.yml b/Taskfile.yml index 2f85760d..5106dc23 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -47,10 +47,7 @@ tasks: - task: install:lint - task: minimal:lint - task: emscripten:lint - - task: rpi3:lint - - task: rpi4:lint - task: rpi4-vcpkg:lint - - task: pico:lint - npx -y cspell lint --no-progress --show-suggestions clean: diff --git a/docker-compose.yml b/docker-compose.yml index 27f88a16..6b43e85c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -84,21 +84,21 @@ services: context: . dockerfile: ./docker/Dockerfile.arm target: build - build-rpi3-release: + build-rpi3-debug: build: context: . dockerfile: ./docker/Dockerfile.arm - target: build-release + target: build-debug build-rpi4: build: context: . dockerfile: ./docker/Dockerfile.aarch64 target: build - build-rpi4-release: + build-rpi4-debug: build: context: . dockerfile: ./docker/Dockerfile.aarch64 - target: build-release + target: build-debug test-rpi4: build: context: . @@ -113,9 +113,4 @@ services: build: context: . dockerfile: ./docker/Dockerfile.aarch64 - target: build-custom - build-pico: - build: - context: . - dockerfile: ./docker/Dockerfile.pico - target: build \ No newline at end of file + target: build-custom \ No newline at end of file diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 index 46f7bcec..ee16e82a 100644 --- a/docker/Dockerfile.aarch64 +++ b/docker/Dockerfile.aarch64 @@ -26,10 +26,10 @@ COPY . /home/project_options WORKDIR /home/project_options CMD ["/bin/bash", "-c", "task rpi4:build.cross"] -FROM setup AS build-release +FROM setup AS build-debug COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task rpi4:build.cross.release"] +CMD ["/bin/bash", "-c", "task rpi4:build.cross.debug"] FROM setup AS build-vcpkg COPY . /home/project_options @@ -49,4 +49,4 @@ RUN apt-get update && apt-get install -y \ COPY . /home/project_options WORKDIR /home/project_options ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu -CMD ["/bin/bash", "-c", "task rpi4:build.cross.release && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] +CMD ["/bin/bash", "-c", "task rpi4:build.cross && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 2e581801..273e654a 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -27,7 +27,7 @@ WORKDIR /home/project_options CMD ["/bin/bash", "-c", "task rpi3:build.cross"] -FROM setup AS build-release +FROM setup AS build-debug COPY . /home/project_options WORKDIR /home/project_options -CMD ["/bin/bash", "-c", "task rpi3:build.cross.release"] \ No newline at end of file +CMD ["/bin/bash", "-c", "task rpi3:build.cross.debug"] \ No newline at end of file diff --git a/tests/pico/.dockerignore b/tests/pico/.dockerignore deleted file mode 100644 index 98f8675f..00000000 --- a/tests/pico/.dockerignore +++ /dev/null @@ -1,8 +0,0 @@ -build/ -.idea -.vscode -_deps -cmake-* -build -.DS_Store -*.pdf \ No newline at end of file diff --git a/tests/pico/.gitignore b/tests/pico/.gitignore deleted file mode 100644 index 9a4a7f5d..00000000 --- a/tests/pico/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.idea -.vscode -_deps -cmake-* -build -.DS_Store -*.pdf \ No newline at end of file diff --git a/tests/pico/CMakeLists.txt b/tests/pico/CMakeLists.txt deleted file mode 100644 index 71288af6..00000000 --- a/tests/pico/CMakeLists.txt +++ /dev/null @@ -1,119 +0,0 @@ -cmake_minimum_required(VERSION 3.13) - -# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. -# You can later set fine-grained standards for each target using `target_compile_features` -#set(CMAKE_CXX_STANDARD 20) -#set(CMAKE_C_STANDARD 99) - -# initialize pico-sdk from GIT -# (note this can come from environment, CMake cache etc) -#set(PICO_SDK_FETCH_FROM_GIT on) - -# Pull in SDK (must be before project) -include(pico_sdk_import.cmake) - - -### Add project_options -# include(FetchContent) -# FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/heads/main.zip) -# FetchContent_MakeAvailable(_project_options) -# include(${_project_options_SOURCE_DIR}/Index.cmake) -include(../../src/Index.cmake) - - -#include(example_auto_set_url.cmake) -# Set the project name to your project name, my project isn't very descriptive -project( - pico - VERSION 0.1.0 - LANGUAGES C CXX ASM) - -# initialize the Raspberry Pi Pico SDK -pico_sdk_init() - -set(ENABLE_CLANG_TIDY OFF) -set(ENABLE_CPPCHECK OFF) -set(ENABLE_SANITIZER_ADDRESS OFF) -set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) -set(ENABLE_COVERAGE OFF) -set(ENABLE_INCLUDE_WHAT_YOU_USE OFF) - -option(ENABLE_CHECKING "Enable Static analyzer" OFF) -option(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE "Enable Static analyzer for include-what-you-use" OFF) -if(ENABLE_CHECKING) - set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") - set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") - set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") -endif() -if(ENABLE_CHECKING_INCLUDE_WHAT_YOU_USE) - set(ENABLE_INCLUDE_WHAT_YOU_USE "ENABLE_INCLUDE_WHAT_YOU_USE") -endif() - -#option(ENABLE_TESTING "Enable the tests" OFF) -option(DISABLE_SANITIZER "Disable Sanitizer" OFF) -if(ENABLE_TESTING) - if(NOT DEFINED OPT_ENABLE_COVERAGE) - set(ENABLE_COVERAGE "ENABLE_COVERAGE") - endif() - - if(NOT DISABLE_SANITIZER) - if(NOT - "${CMAKE_SYSTEM_NAME}" - STREQUAL - "Windows") - set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") - set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") - else() - # or it is MSVC and has run vcvarsall - string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) - if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") - set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") - endif() - endif() - endif() -endif() - -project_options( - ENABLE_CACHE - ${ENABLE_CPPCHECK} - ${ENABLE_CLANG_TIDY} - ${ENABLE_INCLUDE_WHAT_YOU_USE} - ENABLE_VS_ANALYSIS - ${ENABLE_COVERAGE} - ${ENABLE_SANITIZER_ADDRESS} - ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} - #DISABLE_EXCEPTIONS - #DISABLE_RTTI - # Note: PCH is disabled by default in developer mode because these headers become globally included and they can mask other errors - PCH_HEADERS - # This is a list of headers to pre-compile, here are some common ones - - - - - - - - CPPCHECK_OPTIONS - --enable=style,performance,warning,portability - --inline-suppr - # We cannot act on a bug/missing feature of cppcheck - --suppress=cppcheckError - --suppress=internalAstError - # if a file does not have an internalAstError, we get an unmatchedSuppression error - --suppress=unmatchedSuppression - --suppress=passedByValue - --suppress=syntaxError - --inconclusive) - -add_executable(hello_world - hello_world.c -) - -# Add pico_stdlib library which aggregates commonly used features -target_link_system_libraries(hello_world PRIVATE pico_stdlib) - -# create map/bin/hex/uf2 file in addition to ELF. -pico_add_extra_outputs(hello_world) - -target_link_libraries(hello_world PRIVATE project_options project_warnings) \ No newline at end of file diff --git a/tests/pico/LICENSE.TXT b/tests/pico/LICENSE.TXT deleted file mode 100644 index e8a64f19..00000000 --- a/tests/pico/LICENSE.TXT +++ /dev/null @@ -1,21 +0,0 @@ -Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/tests/pico/Taskfile.yml b/tests/pico/Taskfile.yml deleted file mode 100644 index 7c68737f..00000000 --- a/tests/pico/Taskfile.yml +++ /dev/null @@ -1,10 +0,0 @@ -# https://taskfile.dev/#6/installation -version: 3 - -tasks: - build: - - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - - cmake --build ./build --config Release - - lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/pico/hello_world.c b/tests/pico/hello_world.c deleted file mode 100644 index 42fca187..00000000 --- a/tests/pico/hello_world.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "pico/stdlib.h" - -int main() { - setup_default_uart(); - printf("Hello, world!\n"); - return 0; -} \ No newline at end of file diff --git a/tests/pico/pico_sdk_import.cmake b/tests/pico/pico_sdk_import.cmake deleted file mode 100644 index 0ba75584..00000000 --- a/tests/pico/pico_sdk_import.cmake +++ /dev/null @@ -1,73 +0,0 @@ -# This is a copy of /external/pico_sdk_import.cmake - -# This can be dropped into an external project to help locate this SDK -# It should be include()ed prior to project() - -if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) - set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) - message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") -endif () - -if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) - set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) - message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") -endif () - -if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) - set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) - message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") -endif () - -set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") -set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") -set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") - -if (NOT PICO_SDK_PATH) - if (PICO_SDK_FETCH_FROM_GIT) - include(FetchContent) - set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) - if (PICO_SDK_FETCH_FROM_GIT_PATH) - get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") - endif () - # GIT_SUBMODULES_RECURSE was added in 3.17 - if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG master - GIT_SUBMODULES_RECURSE FALSE - ) - else () - FetchContent_Declare( - pico_sdk - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG master - ) - endif () - - if (NOT pico_sdk) - message("Downloading Raspberry Pi Pico SDK") - FetchContent_Populate(pico_sdk) - set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) - endif () - set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) - else () - message(FATAL_ERROR - "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." - ) - endif () -endif () - -get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") -if (NOT EXISTS ${PICO_SDK_PATH}) - message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") -endif () - -set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) -if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) - message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") -endif () - -set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) - -include(${PICO_SDK_INIT_CMAKE_FILE}) \ No newline at end of file diff --git a/tests/pico/vcpkg.json b/tests/pico/vcpkg.json deleted file mode 100644 index 5aa0e59b..00000000 --- a/tests/pico/vcpkg.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "example", - "version-string": "0.1.0", - "dependencies": [ - "fmt", - "ms-gsl" - ] -} diff --git a/tests/rpi3/Taskfile.yml b/tests/rpi3/Taskfile.yml index 66e18a40..8bdc0fd8 100644 --- a/tests/rpi3/Taskfile.yml +++ b/tests/rpi3/Taskfile.yml @@ -2,25 +2,22 @@ version: 3 tasks: - build: + build.debug: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Debug - build.release: + build: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Release - build.cross: + build.cross.debug: cmds: - - task: build + - task: build.debug vars: CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux - build.cross.release: + build.cross: cmds: - - task: build.release + - task: build vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux - - lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi3/vcpkg.json b/tests/rpi3/vcpkg.json deleted file mode 100644 index 5aa0e59b..00000000 --- a/tests/rpi3/vcpkg.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "example", - "version-string": "0.1.0", - "dependencies": [ - "fmt", - "ms-gsl" - ] -} diff --git a/tests/rpi4-vcpkg/Taskfile.yml b/tests/rpi4-vcpkg/Taskfile.yml index 897106b7..175de702 100644 --- a/tests/rpi4-vcpkg/Taskfile.yml +++ b/tests/rpi4-vcpkg/Taskfile.yml @@ -3,8 +3,8 @@ version: 3 tasks: build: - - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - - cmake --build ./build --config Debug + - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} + - cmake --build ./build --config Release build.cross: cmds: diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml index 923bcc37..3732c960 100644 --- a/tests/rpi4/Taskfile.yml +++ b/tests/rpi4/Taskfile.yml @@ -2,11 +2,11 @@ version: 3 tasks: - build: + build.debug: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Debug - build.release: + build: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} - cmake --build ./build --config Release @@ -14,19 +14,16 @@ tasks: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux - build.cross.release: + build.cross.debug: cmds: - - task: build.release + - task: build.debug vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux build.cross.custom-toolchain: cmds: - task: build.release vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake - - lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi4/vcpkg.json b/tests/rpi4/vcpkg.json deleted file mode 100644 index 5aa0e59b..00000000 --- a/tests/rpi4/vcpkg.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "example", - "version-string": "0.1.0", - "dependencies": [ - "fmt", - "ms-gsl" - ] -} From 27a009d9c590f40656c882dc6028ba81fb8a0b80 Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 16 Jan 2023 21:38:28 +0100 Subject: [PATCH 027/139] feat: add cross ARM CI --- .github/workflows/ci.cross.arm.yml | 73 +++++++++++++++++++ .../{ci.mingw.yml => ci.cross.mingw.yml} | 4 +- .github/workflows/ci.emscripten.yml | 2 +- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.cross.arm.yml rename .github/workflows/{ci.mingw.yml => ci.cross.mingw.yml} (90%) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml new file mode 100644 index 00000000..72eff3a6 --- /dev/null +++ b/.github/workflows/ci.cross.arm.yml @@ -0,0 +1,73 @@ +name: ci-cross-arm +on: + pull_request: + push: + branches: + - main + - master + +jobs: + Test: + if: "!contains(github.event.head_commit.message, '[ci skip]')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-22.04 + cmake: + - true + include: + - task: rpi4:build.cross + install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + target: aarch64-linux-gnu + - task: rpi4-vcpkg:build.cross + install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + target: aarch64-linux-gnu + - task: rpi4:build.cross.custom-toolchain + insstall-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + target: aarch64-linux-gnu + - task: rpi3:build.cross + install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi + target: arm-none-eabi + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/vcpkg + ./build/vcpkg_installed + ${{ env.HOME }}/.cache/vcpkg/archives + ${{ env.XDG_CACHE_HOME }}/vcpkg/archives + ${{ env.LOCALAPPDATA }}\vcpkg\archives + ${{ env.APPDATA }}\vcpkg\archives + key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} + restore-keys: | + ${{ runner.os }}-${{ env.BUILD_TYPE }}- + + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + cmake: ${{ matrix.cmake }} + ninja: true + vcpkg: true + conan: true + cppcheck: true + clangtidy: true + task: true + doxygen: true + powershell: true + + - name: Setup ARM (Cross) Compiler + uses: tecolicom/actions-use-apt-tools@v1 + with: + tools: ${{ matrix.install-cross-compiler }} + + - name: Build (Task) + run: | + task ${{ matrix.task }} + env: + CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.cross.mingw.yml similarity index 90% rename from .github/workflows/ci.mingw.yml rename to .github/workflows/ci.cross.mingw.yml index 846d2a89..d001371a 100644 --- a/.github/workflows/ci.mingw.yml +++ b/.github/workflows/ci.cross.mingw.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: - - ubuntu-20.04 + - ubuntu-22.04 cmake: - true platform: @@ -41,7 +41,7 @@ jobs: ${{ env.XDG_CACHE_HOME }}/vcpkg/archives ${{ env.LOCALAPPDATA }}\vcpkg\archives ${{ env.APPDATA }}\vcpkg\archives - key: ${{ runner.os }}-mingw-${{ matrix.platform }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} + key: ${{ runner.os }}-cross-mingw-${{ matrix.platform }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} restore-keys: | ${{ runner.os }}-${{ env.BUILD_TYPE }}- diff --git a/.github/workflows/ci.emscripten.yml b/.github/workflows/ci.emscripten.yml index 1ac9b7dd..bdae61a4 100644 --- a/.github/workflows/ci.emscripten.yml +++ b/.github/workflows/ci.emscripten.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: - - ubuntu-20.04 + - ubuntu-22.04 cmake: - true steps: From 19e6dd98e5ed17bc1b6615e41f0ce11b32b16eaa Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 16 Jan 2023 21:53:06 +0100 Subject: [PATCH 028/139] fix: Taskfile --- Taskfile.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 5106dc23..10420d8e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -26,9 +26,6 @@ includes: rpi4-vcpkg: taskfile: ./tests/rpi4-vcpkg/Taskfile.yml dir: ./tests/rpi4-vcpkg - pico: - taskfile: ./tests/pico/Taskfile.yml - dir: ./tests/pico vars: CWD: From ff716a5ea0bfbbfdc28419ec5dfc24acd071c4e1 Mon Sep 17 00:00:00 2001 From: abeimler Date: Mon, 16 Jan 2023 22:16:00 +0100 Subject: [PATCH 029/139] fix: cleanup pico example --- docker/Dockerfile.pico | 37 ------------------------------------- docker/Taskfile.yml | 4 ---- 2 files changed, 41 deletions(-) delete mode 100644 docker/Dockerfile.pico diff --git a/docker/Dockerfile.pico b/docker/Dockerfile.pico deleted file mode 100644 index a140c263..00000000 --- a/docker/Dockerfile.pico +++ /dev/null @@ -1,37 +0,0 @@ -FROM ubuntu:22.04 AS base - -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux - - - -FROM base AS setup - -# install cmake, ninja, and ccache -RUN /setup_cpp_linux --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true - -RUN apt-get update && apt-get install -y \ - gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \ - && rm -rf /var/lib/apt/lists/* - -# https://github.com/raspberrypi/pico-sdk -RUN git clone https://github.com/raspberrypi/pico-sdk /home/pico-sdk -ENV PICO_SDK_PATH /home/pico-sdk -WORKDIR /home/pico-sdk -RUN git submodule update --init -WORKDIR / - -COPY ./docker/entrypoint.sh /docker-entrypoint.sh -ENTRYPOINT [ "/docker-entrypoint.sh" ] - - -FROM setup AS build -COPY . /home/project_options -RUN cp -rf /home/pico-sdk/external/pico_sdk_import.cmake /home/project_options/tests/pico/pico_sdk_import.cmake -WORKDIR /home/project_options -ENV PROJECT_DIR /home/project_options -CMD ["/bin/bash", "-c", "task pico:build"] - diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 0facf3d7..59c95a21 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -49,7 +49,3 @@ tasks: rpi4.custom: - docker-compose up --build build-rpi4-custom - docker-compose down - - pico: - - docker-compose up --build build-pico - - docker-compose down \ No newline at end of file From 9983f837f2dc22b1f3579149ad2f7cd97b360732 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 21:39:29 -0800 Subject: [PATCH 030/139] test: fix the Windows specific tasks --- Taskfile.yml | 33 ++++++++++++++----- Taskfile_windows.yml | 12 ------- cspell.config.yaml | 4 ++- src/Optimization.cmake | 2 +- tests/emscripten/main.cpp | 4 +-- tests/install/Taskfile.yml | 6 ++-- tests/install/Taskfile_windows.yml | 5 --- tests/install/src/another_main.cpp | 4 +-- tests/minimal/Taskfile.yml | 13 +++++--- tests/minimal/Taskfile_windows.yml | 5 --- tests/minimal/main.cpp | 4 +-- tests/myproj/Taskfile.yml | 10 +++--- tests/myproj/Taskfile_windows.yml | 5 --- tests/myproj/include/mylib/lib.hpp | 12 +++---- .../libs/mythirdpartylib/include/Foo.hpp | 18 +++++----- tests/myproj/libs/mythirdpartylib/src/Foo.cpp | 20 +++++------ tests/myproj/src/main/main.cpp | 22 ++++++------- tests/myproj/src/mylib2/lib.cpp | 14 ++++---- 18 files changed, 94 insertions(+), 99 deletions(-) delete mode 100644 Taskfile_windows.yml delete mode 100644 tests/install/Taskfile_windows.yml delete mode 100644 tests/minimal/Taskfile_windows.yml delete mode 100644 tests/myproj/Taskfile_windows.yml diff --git a/Taskfile.yml b/Taskfile.yml index 9c9af0dd..3b9991da 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,7 +2,6 @@ version: 3 includes: - windows: ./Taskfile_windows.yml docker: ./docker/Taskfile.yml examples: ./examples/Taskfile.yml myproj: @@ -29,15 +28,31 @@ tasks: - task: install lint: - - git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file - - git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations - - task: myproj:lint - - task: install:lint - - task: minimal:lint - - task: emscripten:lint - - npx -y cspell lint --no-progress --show-suggestions + cmds: + - npx -y cspell lint --no-progress --show-suggestions + + - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' + platforms: [windows] + - cmd: git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file + platforms: [linux, darwin] + + - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file {{.CMAKE_LINT_FLAGS}} } }' + platforms: [windows] + - cmd: git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint {{.CMAKE_LINT_FLAGS}} + platforms: [linux, darwin] + + - task: myproj:lint + - task: install:lint + - task: minimal:lint + - task: emscripten:lint + vars: + CMAKE_LINT_FLAGS: --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations clean: + - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./install' + platforms: [windows] + - cmd: rm -rf ./install + platforms: [linux, darwin] + - task: myproj:clean - task: install:clean - - rm -rf {{.CWD}}/install diff --git a/Taskfile_windows.yml b/Taskfile_windows.yml deleted file mode 100644 index ca914fa7..00000000 --- a/Taskfile_windows.yml +++ /dev/null @@ -1,12 +0,0 @@ -# https://taskfile.dev/#6/installation -version: 3 - -tasks: - lint: - - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' - - powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }' - - ~/vcpkg/vcpkg format-manifest ./tests/emscripten/vcpkg.json ./tests/install/vcpkg.json ./tests/minimal/vcpkg.json ./tests/myproj/vcpkg.json - - npx -y cspell lint --no-progress --show-suggestions - - clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./tests/myproj/build; rmrf ./tests/install/build; rmrf ./install' diff --git a/cspell.config.yaml b/cspell.config.yaml index 1fd3b033..fe6236bf 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -29,6 +29,7 @@ words: - CPATH - Cppcheck - cppcoreguidelines + - cppreference - cppdbg - CPPFLAGS - cpprc @@ -40,8 +41,8 @@ words: - DOPT - dyld - dylib - - Eigen - egor-tensin + - Eigen - emcc - emcmake - emscripten @@ -82,6 +83,7 @@ words: - pwsh - rmrf - rpath + - rtti - sccache - setx - shlib diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 4d2b299f..2eb8c536 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -41,4 +41,4 @@ endmacro() macro(disable_rtti project_name) target_compile_options(${project_name} INTERFACE $<$:/GR->) target_compile_options(${project_name} INTERFACE $<$>:-fno-rtti>) -endmacro() \ No newline at end of file +endmacro() diff --git a/tests/emscripten/main.cpp b/tests/emscripten/main.cpp index 7daec985..7e674a92 100644 --- a/tests/emscripten/main.cpp +++ b/tests/emscripten/main.cpp @@ -13,6 +13,6 @@ #endif int main() { - printf("hello, world!\n"); - return 0; + printf("hello, world!\n"); + return 0; } \ No newline at end of file diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml index 2c66e944..b23551ec 100644 --- a/tests/install/Taskfile.yml +++ b/tests/install/Taskfile.yml @@ -2,7 +2,6 @@ version: 3 includes: - windows: ./Taskfile_windows.yml myproj: taskfile: ../myproj/Taskfile.yml dir: ../myproj @@ -33,4 +32,7 @@ tasks: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json clean: - - rm -rf ./build + - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' + platforms: [windows] + - cmd: rm -rf ./build + platforms: [linux, darwin] diff --git a/tests/install/Taskfile_windows.yml b/tests/install/Taskfile_windows.yml deleted file mode 100644 index 34c950c3..00000000 --- a/tests/install/Taskfile_windows.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: 3 - -tasks: - clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' diff --git a/tests/install/src/another_main.cpp b/tests/install/src/another_main.cpp index f14a6747..4b80c7b0 100644 --- a/tests/install/src/another_main.cpp +++ b/tests/install/src/another_main.cpp @@ -2,6 +2,6 @@ #include int main() { - some_fun2(); - return some_fun2(); + some_fun2(); + return some_fun2(); } \ No newline at end of file diff --git a/tests/minimal/Taskfile.yml b/tests/minimal/Taskfile.yml index c9ceb00a..1dd6b0be 100644 --- a/tests/minimal/Taskfile.yml +++ b/tests/minimal/Taskfile.yml @@ -1,9 +1,6 @@ # https://taskfile.dev/#6/installation version: 3 -includes: - windows: ./Taskfile_windows.yml - tasks: build: - cmake . -B ./build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{.CMAKE_ARGS}} @@ -16,7 +13,7 @@ tasks: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} build.mingw.from-env: - env: + env: CC: x86_64-w64-mingw32-gcc CXX: x86_64-w64-mingw32-g++ cmds: @@ -31,4 +28,10 @@ tasks: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json + + clean: + - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' + platforms: [windows] + - cmd: rm -rf ./build + platforms: [linux, darwin] diff --git a/tests/minimal/Taskfile_windows.yml b/tests/minimal/Taskfile_windows.yml deleted file mode 100644 index 34c950c3..00000000 --- a/tests/minimal/Taskfile_windows.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: 3 - -tasks: - clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' diff --git a/tests/minimal/main.cpp b/tests/minimal/main.cpp index 115ff095..0296dc98 100644 --- a/tests/minimal/main.cpp +++ b/tests/minimal/main.cpp @@ -1,6 +1,6 @@ #include int main() { - fmt::print("Hello World!"); - return 0; + fmt::print("Hello World!"); + return 0; } \ No newline at end of file diff --git a/tests/myproj/Taskfile.yml b/tests/myproj/Taskfile.yml index 4818f367..787a6d63 100644 --- a/tests/myproj/Taskfile.yml +++ b/tests/myproj/Taskfile.yml @@ -1,8 +1,5 @@ version: 3 -includes: - windows: ./Taskfile_windows.yml - vars: PROJECT_DIR: '{{.PROJECT_DIR | default "."}}' @@ -37,6 +34,9 @@ tasks: lint: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json - + clean: - - rm -rf ./build + - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' + platforms: [windows] + - cmd: rm -rf ./build + platforms: [linux, darwin] diff --git a/tests/myproj/Taskfile_windows.yml b/tests/myproj/Taskfile_windows.yml deleted file mode 100644 index 34c950c3..00000000 --- a/tests/myproj/Taskfile_windows.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: 3 - -tasks: - clean: - - powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./build' diff --git a/tests/myproj/include/mylib/lib.hpp b/tests/myproj/include/mylib/lib.hpp index 6ecad59b..e808b290 100644 --- a/tests/myproj/include/mylib/lib.hpp +++ b/tests/myproj/include/mylib/lib.hpp @@ -18,13 +18,13 @@ #include int some_fun() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - // populate an Eigen vector with the values - auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1); + // populate an Eigen vector with the values + auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1); - // print the vector - fmt::print("{}", eigen_vec); + // print the vector + fmt::print("{}", eigen_vec); - return 0; + return 0; } diff --git a/tests/myproj/libs/mythirdpartylib/include/Foo.hpp b/tests/myproj/libs/mythirdpartylib/include/Foo.hpp index 26aa7e0e..52915fce 100644 --- a/tests/myproj/libs/mythirdpartylib/include/Foo.hpp +++ b/tests/myproj/libs/mythirdpartylib/include/Foo.hpp @@ -8,18 +8,18 @@ namespace mythirdpartylib { class MYTHIRDPARTYLIB_EXPORT Foo { -public: - Foo() = default; + public: + Foo() = default; - /*implicit*/ Foo(int a) : m_a(a) {} + /*implicit*/ Foo(int a) : m_a(a) {} - int a() const { return m_a; } + int a() const { return m_a; } - void update(bool b, bool c, bool d); - void bad(std::vector &v); + void update(bool b, bool c, bool d); + void bad(std::vector &v); -private: - int m_a; + private: + int m_a; }; -} // namespace mythirdpartylib \ No newline at end of file +}// namespace mythirdpartylib \ No newline at end of file diff --git a/tests/myproj/libs/mythirdpartylib/src/Foo.cpp b/tests/myproj/libs/mythirdpartylib/src/Foo.cpp index 9e777af4..c8d279e7 100644 --- a/tests/myproj/libs/mythirdpartylib/src/Foo.cpp +++ b/tests/myproj/libs/mythirdpartylib/src/Foo.cpp @@ -3,22 +3,22 @@ namespace mythirdpartylib { void Foo::update(bool b, bool c, bool d) { - int e = b + d; - m_a = e; + int e = b + d; + m_a = e; } void Foo::bad(std::vector &v) { - std::string val = "hello"; - int index = -1; // bad, plus should use gsl::index - for (int i = 0; i < v.size(); ++i) { - if (v[i] == val) { - index = i; - break; + std::string val = "hello"; + int index = -1;// bad, plus should use gsl::index + for (int i = 0; i < v.size(); ++i) { + if (v[i] == val) { + index = i; + break; + } } - } } static Foo foo(5); static Foo bar = 42; -} // namespace mythirdpartylib \ No newline at end of file +}// namespace mythirdpartylib \ No newline at end of file diff --git a/tests/myproj/src/main/main.cpp b/tests/myproj/src/main/main.cpp index 3dc72141..8493180a 100644 --- a/tests/myproj/src/main/main.cpp +++ b/tests/myproj/src/main/main.cpp @@ -16,20 +16,20 @@ #include int main() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); + fmt::print("{}", eigen_vec); -#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails - Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); +#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails + Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); + fmt::print("{}", eigen_vec2); #endif - // trigger address sanitizer - // int *p = nullptr; - // *p = 1; + // trigger address sanitizer + // int *p = nullptr; + // *p = 1; - // trigger compiler warnings, clang-tidy, and cppcheck - int a; + // trigger compiler warnings, clang-tidy, and cppcheck + int a; } diff --git a/tests/myproj/src/mylib2/lib.cpp b/tests/myproj/src/mylib2/lib.cpp index 38458dce..41e4b510 100644 --- a/tests/myproj/src/mylib2/lib.cpp +++ b/tests/myproj/src/mylib2/lib.cpp @@ -16,15 +16,15 @@ #include int some_fun2() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); + fmt::print("{}", eigen_vec); -#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails - Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); +#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails + Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); + fmt::print("{}", eigen_vec2); #endif - return 0; + return 0; } From 550bbf54fad5fa3b6a773b3bda3edc3c27af5816 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 21:42:15 -0800 Subject: [PATCH 031/139] chore: parallelize the lint commands --- Taskfile.yml | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 3b9991da..4242381a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -27,27 +27,33 @@ tasks: - task: myproj:test.release - task: install - lint: - cmds: - - npx -y cspell lint --no-progress --show-suggestions + lint.cspell: npx -y cspell lint --no-progress --show-suggestions - - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' - platforms: [windows] - - cmd: git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file - platforms: [linux, darwin] + lint.clang-format: + - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }' + platforms: [windows] + - cmd: git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file + platforms: [linux, darwin] + lint.cmake-format: + cmds: - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file {{.CMAKE_LINT_FLAGS}} } }' platforms: [windows] - cmd: git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint {{.CMAKE_LINT_FLAGS}} platforms: [linux, darwin] - - - task: myproj:lint - - task: install:lint - - task: minimal:lint - - task: emscripten:lint vars: CMAKE_LINT_FLAGS: --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations + lint: + deps: + - lint.cspell + - lint.clang-format + - lint.cmake-format + - myproj:lint + - install:lint + - minimal:lint + - emscripten:lint + clean: - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./install' platforms: [windows] From 24ad044b54e5e2d8cb8c877c695c5bb75461e7a9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 21:46:28 -0800 Subject: [PATCH 032/139] fix: fix the built-in cmake-lint warnings --- src/CompilerWarnings.cmake | 4 ++-- src/Linker.cmake | 4 ++-- src/Optimization.cmake | 23 +++++++++++----------- src/Sanitizers.cmake | 10 +++++----- src/Tests.cmake | 6 +++--- src/Utilities.cmake | 40 +++++++++++++++++++------------------- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/CompilerWarnings.cmake b/src/CompilerWarnings.cmake index eff009bb..8952ca89 100644 --- a/src/CompilerWarnings.cmake +++ b/src/CompilerWarnings.cmake @@ -6,7 +6,7 @@ include_guard() # https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md function( set_project_warnings - project_name + _project_name WARNINGS_AS_ERRORS MSVC_WARNINGS CLANG_WARNINGS @@ -116,7 +116,7 @@ function( set(PROJECT_WARNINGS_CUDA "${CUDA_WARNINGS}") target_compile_options( - ${project_name} + ${_project_name} INTERFACE # C++ warnings $<$:${PROJECT_WARNINGS_CXX}> # C warnings diff --git a/src/Linker.cmake b/src/Linker.cmake index 62d16a2e..35fd08f1 100644 --- a/src/Linker.cmake +++ b/src/Linker.cmake @@ -1,7 +1,7 @@ include_guard() # Set the linker to use for the linking phase -macro(configure_linker project_name linker) +macro(configure_linker _project_name linker) if(NOT "${linker}" STREQUAL @@ -13,7 +13,7 @@ macro(configure_linker project_name linker) check_cxx_compiler_flag(${_linker_flag} _cxx_supports_linker) if(_cxx_supports_linker) - target_compile_options(${project_name} INTERFACE ${_linker_flag}) + target_compile_options(${_project_name} INTERFACE ${_linker_flag}) endif() endif() endmacro() diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 2eb8c536..73981819 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -1,6 +1,6 @@ include_guard() -macro(enable_interprocedural_optimization project_name) +macro(enable_interprocedural_optimization _project_name) if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") include(CheckIPOSupported) check_ipo_supported(RESULT result OUTPUT output) @@ -13,32 +13,33 @@ macro(enable_interprocedural_optimization project_name) "Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`" ) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) - set_target_properties(${project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) + set_target_properties(${_project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) else() message(WARNING "Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}") endif() endif() endmacro() -macro(enable_native_optimization project_name) +macro(enable_native_optimization _project_name) detect_architecture(_arch) if("${_arch}" STREQUAL "x64") message(STATUS "Enabling the optimizations specific to the current build machine (less portable)") if(MSVC) # TODO It seems it only accepts the exact instruction set like AVX https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64 - # target_compile_options(${project_name} INTERFACE /arch:native) + # target_compile_options(${_project_name} INTERFACE /arch:native) else() - target_compile_options(${project_name} INTERFACE -march=native) + target_compile_options(${_project_name} INTERFACE -march=native) endif() endif() endmacro() -macro(disable_exceptions project_name) - target_compile_options(${project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) - target_compile_options(${project_name} INTERFACE $<$>:-fno-exceptions -fno-unwind-tables>) +macro(disable_exceptions _project_name) + target_compile_options(${_project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) + target_compile_options(${_project_name} INTERFACE $<$>:-fno-exceptions + -fno-unwind-tables>) endmacro() -macro(disable_rtti project_name) - target_compile_options(${project_name} INTERFACE $<$:/GR->) - target_compile_options(${project_name} INTERFACE $<$>:-fno-rtti>) +macro(disable_rtti _project_name) + target_compile_options(${_project_name} INTERFACE $<$:/GR->) + target_compile_options(${_project_name} INTERFACE $<$>:-fno-rtti>) endmacro() diff --git a/src/Sanitizers.cmake b/src/Sanitizers.cmake index 91c277ff..aee213cd 100644 --- a/src/Sanitizers.cmake +++ b/src/Sanitizers.cmake @@ -2,7 +2,7 @@ include_guard() function( enable_sanitizers - project_name + _project_name ENABLE_SANITIZER_ADDRESS ENABLE_SANITIZER_LEAK ENABLE_SANITIZER_UNDEFINED_BEHAVIOR @@ -69,8 +69,8 @@ function( STREQUAL "") if(NOT MSVC) - target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) - target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + target_compile_options(${_project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + target_link_options(${_project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) else() string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) if("${index_of_vs_install_dir}" STREQUAL "-1") @@ -79,8 +79,8 @@ function( "Using MSVC sanitizers requires setting the MSVC environment before building the project. Please manually open the MSVC command prompt and rebuild the project." ) endif() - target_compile_options(${project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO) - target_link_options(${project_name} INTERFACE /INCREMENTAL:NO) + target_compile_options(${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO) + target_link_options(${_project_name} INTERFACE /INCREMENTAL:NO) endif() endif() endif() diff --git a/src/Tests.cmake b/src/Tests.cmake index e9bfbdb6..2f439b63 100644 --- a/src/Tests.cmake +++ b/src/Tests.cmake @@ -1,9 +1,9 @@ include_guard() # Enable coverage reporting for gcc/clang -function(enable_coverage project_name) +function(enable_coverage _project_name) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") - target_compile_options(${project_name} INTERFACE --coverage -O0 -g) - target_link_libraries(${project_name} INTERFACE --coverage) + target_compile_options(${_project_name} INTERFACE --coverage -O0 -g) + target_link_libraries(${_project_name} INTERFACE --coverage) endif() endfunction() diff --git a/src/Utilities.cmake b/src/Utilities.cmake index 392d49ec..9231c4b0 100644 --- a/src/Utilities.cmake +++ b/src/Utilities.cmake @@ -26,60 +26,60 @@ function( endfunction() # A function to set environment variables of CMake from the output of `cmd /c set` -function(set_env_from_string env_string) +function(set_env_from_string _env_string) # replace ; in paths with __sep__ so we can split on ; string( REGEX REPLACE ";" "__sep__" - env_string_sep_added - "${env_string}") + _env_string_sep_added + "${_env_string}") # the variables are separated by \r?\n string( REGEX REPLACE "\r?\n" ";" - env_list - "${env_string_sep_added}") + _env_list + "${_env_string_sep_added}") - foreach(env_var ${env_list}) + foreach(_env_var ${_env_list}) # split by = string( REGEX REPLACE "=" ";" - env_parts - "${env_var}") + _env_parts + "${_env_var}") - list(LENGTH env_parts env_parts_length) - if("${env_parts_length}" EQUAL "2") + list(LENGTH _env_parts _env_parts_length) + if("${_env_parts_length}" EQUAL "2") # get the variable name and value list( GET - env_parts + _env_parts 0 - env_name) + _env_name) list( GET - env_parts + _env_parts 1 - env_value) + _env_value) # recover ; in paths string( REGEX REPLACE "__sep__" ";" - env_value - "${env_value}") + _env_value + "${_env_value}") - # set env_name to env_value - set(ENV{${env_name}} "${env_value}") + # set _env_name to _env_value + set(ENV{${_env_name}} "${_env_value}") # update cmake program path - if("${env_name}" EQUAL "PATH") - list(APPEND CMAKE_PROGRAM_PATH ${env_value}) + if("${_env_name}" EQUAL "PATH") + list(APPEND CMAKE_PROGRAM_PATH ${_env_value}) endif() endif() endforeach() From 3bc9119dd818e6f784d4df6393f59f7740534edf Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 21:49:53 -0800 Subject: [PATCH 033/139] docs: add missing docstrings for the public macros --- src/CrossCompiler.cmake | 2 ++ src/DetectCompiler.cmake | 4 ++-- src/Optimization.cmake | 4 ++++ src/Sanitizers.cmake | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index c2a4f6b0..2afd121b 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -1,5 +1,6 @@ include_guard() +# Enable cross-compiling macro(enable_cross_compiler) include("${ProjectOptions_SRC_DIR}/Utilities.cmake") detect_architecture(_arch) @@ -159,6 +160,7 @@ macro(enable_cross_compiler) message(STATUS "Toolchain File: ${CMAKE_TOOLCHAIN_FILE}") endmacro() +# Get the toolchain file function(get_toolchain_file value) include("${ProjectOptions_SRC_DIR}/Utilities.cmake") detect_architecture(_arch) diff --git a/src/DetectCompiler.cmake b/src/DetectCompiler.cmake index 52ae048d..eb38e5f7 100644 --- a/src/DetectCompiler.cmake +++ b/src/DetectCompiler.cmake @@ -1,8 +1,8 @@ include_guard() +# includes a separate CMakeLists.txt file to detect the CXX/C compilers before project is called +# Using a separate file ensures that the current scope is not contaminated by the variable macro(detect_compiler) - # includes a separate CMakeLists.txt file to detect the CXX/C compilers before project is called - # Using a separate file ensures that the current scope is not contaminated by the variable find_program(CMAKE_EXECUTABLE cmake) execute_process( COMMAND "${CMAKE_EXECUTABLE}" -S "${ProjectOptions_SRC_DIR}/detect_compiler" -B diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 73981819..68058e42 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -1,5 +1,6 @@ include_guard() +# Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build macro(enable_interprocedural_optimization _project_name) if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") include(CheckIPOSupported) @@ -20,6 +21,7 @@ macro(enable_interprocedural_optimization _project_name) endif() endmacro() +# Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). macro(enable_native_optimization _project_name) detect_architecture(_arch) if("${_arch}" STREQUAL "x64") @@ -33,12 +35,14 @@ macro(enable_native_optimization _project_name) endif() endmacro() +# Disable C++ exceptions for the given project. macro(disable_exceptions _project_name) target_compile_options(${_project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) target_compile_options(${_project_name} INTERFACE $<$>:-fno-exceptions -fno-unwind-tables>) endmacro() +# Disable C++ RTTI (Run-Time Type Information) for the given project. macro(disable_rtti _project_name) target_compile_options(${_project_name} INTERFACE $<$:/GR->) target_compile_options(${_project_name} INTERFACE $<$>:-fno-rtti>) diff --git a/src/Sanitizers.cmake b/src/Sanitizers.cmake index aee213cd..dd4aaa99 100644 --- a/src/Sanitizers.cmake +++ b/src/Sanitizers.cmake @@ -1,5 +1,6 @@ include_guard() +# Enable the sanitizers for the given project function( enable_sanitizers _project_name From 85d10571c5d51d777c3d3847608ff13c642a5a8b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 21:54:21 -0800 Subject: [PATCH 034/139] chore: rename lint.cmake-format task [skip ci] --- Taskfile.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 4242381a..432418a2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -35,7 +35,7 @@ tasks: - cmd: git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file platforms: [linux, darwin] - lint.cmake-format: + lint.cmake: cmds: - cmd: powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file {{.CMAKE_LINT_FLAGS}} } }' platforms: [windows] @@ -48,7 +48,7 @@ tasks: deps: - lint.cspell - lint.clang-format - - lint.cmake-format + - lint.cmake - myproj:lint - install:lint - minimal:lint From 41fe69775397fae11e62424be1d6dfcac8892181 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 16 Jan 2023 23:13:22 -0800 Subject: [PATCH 035/139] chore: fix the lint issues --- .github/workflows/ci.cross.arm.yml | 2 +- cspell.config.yaml | 14 +++++++++++++- src/CrossCompiler.cmake | 2 +- tests/rpi3/CMakeLists.txt | 14 ++++++++++---- tests/rpi3/main.c | 6 +++--- tests/rpi4-vcpkg/CMakeLists.txt | 2 +- tests/rpi4-vcpkg/main.cpp | 4 ++-- tests/rpi4/CMakeLists.txt | 2 +- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 72eff3a6..bb011018 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -60,7 +60,7 @@ jobs: task: true doxygen: true powershell: true - + - name: Setup ARM (Cross) Compiler uses: tecolicom/actions-use-apt-tools@v1 with: diff --git a/cspell.config.yaml b/cspell.config.yaml index fe6236bf..27316dc3 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -16,6 +16,7 @@ words: - anotherproj - applellvm - ARGN + - armv - asan - buildtools - ccache @@ -29,10 +30,10 @@ words: - CPATH - Cppcheck - cppcoreguidelines - - cppreference - cppdbg - CPPFLAGS - cpprc + - cppreference - ctest - Cuda - DCMAKE @@ -41,6 +42,7 @@ words: - DOPT - dyld - dylib + - eabi - egor-tensin - Eigen - emcc @@ -52,20 +54,29 @@ words: - fdiagnostics - ftime - gcovr + - gnueabi + - gnueabihf - Graphviz - hwrap - iwwu - kcov - LDFLAGS + - lgcc - libc - libcuda + - libg - libstdc - LPSTR - LPWSTR + - lrdimon + - lstdc + - mcpu - mdfile + - mfpu - msbuild - msvc - msys + - mthumb - multilib - municode - myapp @@ -89,6 +100,7 @@ words: - shlib - suppr - SYSROOT + - tecolicom - TOLOWER - TOUPPER - ubsan diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index 64d09213..8c7436c4 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -168,7 +168,7 @@ macro(enable_cross_compiler) set(_toolchain_file) get_toolchain_file(_toolchain_file) - if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) endif() set(CROSSCOMPILING TRUE) diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt index 7c31a1d3..205baa02 100644 --- a/tests/rpi3/CMakeLists.txt +++ b/tests/rpi3/CMakeLists.txt @@ -90,10 +90,8 @@ project_options( - CLANG_TIDY_EXTRA_ARGUMENTS ${CLANG_TIDY_EXTRA_ARGUMENTS} - CPPCHECK_OPTIONS --enable=style,performance,warning,portability --inline-suppr @@ -120,8 +118,16 @@ target_link_libraries(example_c PRIVATE project_options project_warnings) if(ENABLE_CROSS_COMPILING) # fix: ...arm-none-eabi/lib/libg.a(lib_a-exit.o): in function `exit': - target_link_options(example_c PRIVATE -Wl,--start-group -lgcc -lc -lm -lrdimon -Wl,--end-group) + target_link_options( + example_c + PRIVATE + -Wl,--start-group + -lgcc + -lc + -lm + -lrdimon + -Wl,--end-group) # custom raspberry pi 3 options target_compile_options(project_options INTERFACE -march=armv8-a -mfpu=neon-fp-armv8 -mthumb) -endif() \ No newline at end of file +endif() diff --git a/tests/rpi3/main.c b/tests/rpi3/main.c index 0cee53ff..764e0c1e 100644 --- a/tests/rpi3/main.c +++ b/tests/rpi3/main.c @@ -1,6 +1,6 @@ -#include +#include int main() { - printf("Hello World\n"); - return 0; + printf("Hello World\n"); + return 0; } \ No newline at end of file diff --git a/tests/rpi4-vcpkg/CMakeLists.txt b/tests/rpi4-vcpkg/CMakeLists.txt index 4e37cf94..a118abc3 100644 --- a/tests/rpi4-vcpkg/CMakeLists.txt +++ b/tests/rpi4-vcpkg/CMakeLists.txt @@ -118,4 +118,4 @@ if(ENABLE_CROSS_COMPILING) #target_compile_definitions(project_options INTERFACE -D__ARM_NEON) target_compile_options(project_options INTERFACE -mcpu=cortex-a72) #target_compile_options(project_options INTERFACE -march=armv8-a+fp+simd) # use mcpu ? -endif() \ No newline at end of file +endif() diff --git a/tests/rpi4-vcpkg/main.cpp b/tests/rpi4-vcpkg/main.cpp index 115ff095..0296dc98 100644 --- a/tests/rpi4-vcpkg/main.cpp +++ b/tests/rpi4-vcpkg/main.cpp @@ -1,6 +1,6 @@ #include int main() { - fmt::print("Hello World!"); - return 0; + fmt::print("Hello World!"); + return 0; } \ No newline at end of file diff --git a/tests/rpi4/CMakeLists.txt b/tests/rpi4/CMakeLists.txt index 91716760..3292bb7d 100644 --- a/tests/rpi4/CMakeLists.txt +++ b/tests/rpi4/CMakeLists.txt @@ -109,4 +109,4 @@ if(ENABLE_CROSS_COMPILING) #target_compile_definitions(project_options INTERFACE -D__ARM_NEON) target_compile_options(project_options INTERFACE -mcpu=cortex-a72) #target_compile_options(project_options INTERFACE "-march=armv8-a+fp+simd") # use mcpu ? -endif() \ No newline at end of file +endif() From 88778227c83d2a02f4b35af35c87f4e32833cec4 Mon Sep 17 00:00:00 2001 From: abeimler Date: Tue, 17 Jan 2023 14:48:16 +0100 Subject: [PATCH 036/139] fix: CI cross arm --- .github/workflows/ci.cross.arm.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index bb011018..586d225c 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -17,6 +17,11 @@ jobs: - ubuntu-22.04 cmake: - true + task: + - rpi4:build.cross + - rpi4-vcpkg:build.cross + - rpi4:build.cross.custom-toolchain + - rpi3:build.cross include: - task: rpi4:build.cross install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu @@ -25,7 +30,7 @@ jobs: install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - task: rpi4:build.cross.custom-toolchain - insstall-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - task: rpi3:build.cross install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi From 62f4d81247e0bc9ee60f0f4847ba55b84e3b1fe6 Mon Sep 17 00:00:00 2001 From: abeimler Date: Tue, 17 Jan 2023 14:57:29 +0100 Subject: [PATCH 037/139] fix: CI cross arm --- tests/rpi4/Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml index 3732c960..f55b90d4 100644 --- a/tests/rpi4/Taskfile.yml +++ b/tests/rpi4/Taskfile.yml @@ -24,6 +24,6 @@ tasks: build.cross.custom-toolchain: cmds: - - task: build.release + - task: builds vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake From f0dc4595cb17342ef657566ed8a605d594e477a4 Mon Sep 17 00:00:00 2001 From: abeimler Date: Tue, 17 Jan 2023 19:07:33 +0100 Subject: [PATCH 038/139] fix: shell scripts (newline) --- docker/.gitattributes | 2 ++ docker/Taskfile.yml | 8 ++++---- docker/entrypoint.emscripten.sh | 2 +- docker/entrypoint.sh | 2 +- tests/rpi4/Taskfile.yml | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 docker/.gitattributes mode change 100755 => 100644 docker/entrypoint.emscripten.sh mode change 100755 => 100644 docker/entrypoint.sh diff --git a/docker/.gitattributes b/docker/.gitattributes new file mode 100644 index 00000000..13120907 --- /dev/null +++ b/docker/.gitattributes @@ -0,0 +1,2 @@ +* text=auto +*.sh text eol=lf \ No newline at end of file diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 59c95a21..9a71221e 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -26,16 +26,16 @@ tasks: - docker-compose up --build build-rpi3 - docker-compose down - rpi3.release: - - docker-compose up --build build-rpi3-release + rpi3.debug: + - docker-compose up --build build-rpi3-debug - docker-compose down rpi4: - docker-compose up --build build-rpi4 - docker-compose down - rpi4.release: - - docker-compose up --build build-rpi4-release + rpi4.debug: + - docker-compose up --build build-rpi4-debug - docker-compose down rpi4.test: diff --git a/docker/entrypoint.emscripten.sh b/docker/entrypoint.emscripten.sh old mode 100755 new mode 100644 index 323a3ac6..2287a423 --- a/docker/entrypoint.emscripten.sh +++ b/docker/entrypoint.emscripten.sh @@ -6,4 +6,4 @@ source ~/.cpprc # Activate PATH and other environment variables in the current terminal source /root/emsdk/emsdk_env.sh -exec "$@" \ No newline at end of file +exec "$@" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh old mode 100755 new mode 100644 index 0631eaba..172dce81 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,4 +3,4 @@ set -e source ~/.cpprc -exec "$@" \ No newline at end of file +exec "$@" diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml index f55b90d4..6c6704b5 100644 --- a/tests/rpi4/Taskfile.yml +++ b/tests/rpi4/Taskfile.yml @@ -24,6 +24,6 @@ tasks: build.cross.custom-toolchain: cmds: - - task: builds + - task: build vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake From cea73823b278cd3ff9b11720f6a1b388045e49ed Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 18 Jan 2023 09:48:30 +0100 Subject: [PATCH 039/139] fix: docker builds * add git submodule --- docker/Dockerfile | 2 ++ docker/Dockerfile.aarch64 | 5 +++++ docker/Dockerfile.arm | 2 ++ docker/Dockerfile.emscripten | 1 + docker/Dockerfile.mingw | 4 ++++ examples/Taskfile.yml | 1 + 6 files changed, 15 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index a8dd7dfe..7446b115 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,11 +21,13 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task myproj:build"] FROM setup AS test COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task myproj:test"] diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 index ee16e82a..449abb55 100644 --- a/docker/Dockerfile.aarch64 +++ b/docker/Dockerfile.aarch64 @@ -24,21 +24,25 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi4:build.cross"] FROM setup AS build-debug COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi4:build.cross.debug"] FROM setup AS build-vcpkg COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi4-vcpkg:build.cross"] FROM setup AS build-custom COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi4:build.cross.custom-toolchain"] @@ -48,5 +52,6 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu CMD ["/bin/bash", "-c", "task rpi4:build.cross && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 273e654a..cc99b513 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -24,10 +24,12 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi3:build.cross"] FROM setup AS build-debug COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi3:build.cross.debug"] \ No newline at end of file diff --git a/docker/Dockerfile.emscripten b/docker/Dockerfile.emscripten index 27f19412..bc559c87 100644 --- a/docker/Dockerfile.emscripten +++ b/docker/Dockerfile.emscripten @@ -33,4 +33,5 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task emscripten:build"] diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index f3c91859..56eef1b0 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -26,22 +26,26 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ] FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task myproj:build.mingw"] FROM setup AS build-minimal COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task minimal:build.mingw"] FROM setup AS build-minimal-from-env COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task minimal:build.mingw.from-env"] FROM setup AS build-minimal-from-triplet COPY . /home/project_options WORKDIR /home/project_options +RUN git submodule update --init CMD ["/bin/bash", "-c", "task minimal:build.mingw.from-triplet"] diff --git a/examples/Taskfile.yml b/examples/Taskfile.yml index 08cf88bd..9ccf87a2 100644 --- a/examples/Taskfile.yml +++ b/examples/Taskfile.yml @@ -3,6 +3,7 @@ version: 3 includes: cpp_vcpkg_project: taskfile: ./cpp_vcpkg_project/Taskfile.yml + optional: true dir: ./cpp_vcpkg_project vars: CMAKE_GENERATOR: "Ninja Multi-Config" \ No newline at end of file From 42fba373395e7e88338b0ac9b6da34ccaff1dbe2 Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 18 Jan 2023 10:16:56 +0100 Subject: [PATCH 040/139] chore: update setup-cpp in docker files --- docker/Dockerfile | 13 ++++++------- docker/Dockerfile.aarch64 | 12 ++++++------ docker/Dockerfile.arm | 12 ++++++------ docker/Dockerfile.emscripten | 12 ++++++------ docker/Dockerfile.mingw | 12 ++++++------ 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 7446b115..e9a764b7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,17 +1,16 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux - +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp FROM base AS setup ARG compiler="gcc" # install cmake, ninja, and ccache -RUN /setup_cpp_linux --compiler $compiler --llvm true --cmake true --doxygen true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true +RUN setup-cpp --compiler $compiler --llvm true --cmake true --doxygen true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true COPY ./docker/entrypoint.sh /docker-entrypoint.sh diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 index 449abb55..a16b09e5 100644 --- a/docker/Dockerfile.aarch64 +++ b/docker/Dockerfile.aarch64 @@ -1,17 +1,17 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp FROM base AS setup # install cmake, ninja, and ccache -RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true +RUN setup-cpp --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true RUN apt-get update && apt-get install -y \ g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \ diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index cc99b513..264ae86d 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -1,17 +1,17 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp FROM base AS setup # install cmake, ninja, and ccache -RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true +RUN setup-cpp --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true RUN apt-get update && apt-get install -y \ gcc-arm-none-eabi binutils-arm-none-eabi \ diff --git a/docker/Dockerfile.emscripten b/docker/Dockerfile.emscripten index bc559c87..ebfc97ff 100644 --- a/docker/Dockerfile.emscripten +++ b/docker/Dockerfile.emscripten @@ -1,17 +1,17 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp FROM base AS setup # install cmake, ninja, and ccache -RUN /setup_cpp_linux --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true +RUN setup-cpp --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true # install emscripten diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index 56eef1b0..0e8eb058 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -1,17 +1,17 @@ FROM ubuntu:22.04 AS base -ARG setup_cpp_linux_version="0.24.1" - -# add setup_cpp https://github.com/aminya/setup-cpp -ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux -RUN chmod +x /setup_cpp_linux +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp FROM base AS setup # install cmake, ninja, and ccache -RUN /setup_cpp_linux --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true --powershell true +RUN setup-cpp --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true --powershell true # TODO: install cross-compiler with setup_cpp_linux # NOTE: install mingw by hand, waiting for setup-cpp to have mingw cross-compiler support From 08b5cb6e17068957c2b3b26e5945b2938456eada Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 18 Jan 2023 10:44:45 +0100 Subject: [PATCH 041/139] fix: CI build, change apt install packages * use awalsh128/cache-apt-pkgs-action --- .github/workflows/ci.cross.arm.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 586d225c..5095c91d 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -67,9 +67,10 @@ jobs: powershell: true - name: Setup ARM (Cross) Compiler - uses: tecolicom/actions-use-apt-tools@v1 + uses: awalsh128/cache-apt-pkgs-action@latest with: - tools: ${{ matrix.install-cross-compiler }} + packages: ${{ matrix.install-cross-compiler }} + version: 1.0 - name: Build (Task) run: | From 211de69443b0bf7463e21e024c0081c38362a6b6 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 13:43:41 -0800 Subject: [PATCH 042/139] fix: remove unused ENABLE_USER_LINKER option --- README.md | 3 +-- src/Index.cmake | 2 -- tests/install/CMakeLists.txt | 1 - tests/myproj/CMakeLists.txt | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 2a9d6c71..2e64d7bd 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,9 @@ project_options( # PCH_HEADERS # WARNINGS_AS_ERRORS # ENABLE_INCLUDE_WHAT_YOU_USE - # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY + # LINKER "lld" # CONAN_PROFILE ${profile_path} # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html ) ``` @@ -236,7 +236,6 @@ It accepts the following named flags: - `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer - `ENABLE_PCH`: Enable Precompiled Headers - `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use -- `ENABLE_USER_LINKER`: Enable a specific linker if available - `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang - `ENABLE_UNITY`: Enable Unity builds of projects diff --git a/src/Index.cmake b/src/Index.cmake index 75529101..612fe7dc 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -53,7 +53,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/Vcpkg.cmake") # - DOXYGEN_THEME: the name of the Doxygen theme to use. Supported themes: `awesome-sidebar` (default), `awesome` and `original`. # - ENABLE_INTERPROCEDURAL_OPTIMIZATION: Enable Interprocedural Optimization, aka Link Time Optimization (LTO) # - ENABLE_NATIVE_OPTIMIZATION: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). -# - ENABLE_USER_LINKER: Enable a specific linker if available # - ENABLE_BUILD_WITH_TIME_TRACE: Enable -ftime-trace to generate time tracing .json files on clang # - ENABLE_UNITY: Enable Unity builds of projects # - ENABLE_SANITIZER_ADDRESS: Enable address sanitizer @@ -87,7 +86,6 @@ macro(project_options) ENABLE_NATIVE_OPTIMIZATION DISABLE_EXCEPTIONS DISABLE_RTTI - ENABLE_USER_LINKER ENABLE_BUILD_WITH_TIME_TRACE ENABLE_UNITY ENABLE_SANITIZER_ADDRESS diff --git a/tests/install/CMakeLists.txt b/tests/install/CMakeLists.txt index e3f72443..99ffae04 100644 --- a/tests/install/CMakeLists.txt +++ b/tests/install/CMakeLists.txt @@ -26,7 +26,6 @@ project_options( "${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme.css" "${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme_extra.css" ENABLE_INTERPROCEDURAL_OPTIMIZATION - # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY # ENABLE_SANITIZER_ADDRESS diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index d439ba2f..5e913926 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -64,7 +64,6 @@ project_options( ENABLE_DOXYGEN ENABLE_INTERPROCEDURAL_OPTIMIZATION ENABLE_NATIVE_OPTIMIZATION - # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY ${ENABLE_SANITIZER_ADDRESS} From 1e67ac39a8698affa667da24ba846c05851c8dbd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 13:53:59 -0800 Subject: [PATCH 043/139] fix: fix the custom LINKER option --- src/Linker.cmake | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Linker.cmake b/src/Linker.cmake index 35fd08f1..65d5b4fc 100644 --- a/src/Linker.cmake +++ b/src/Linker.cmake @@ -1,19 +1,22 @@ include_guard() # Set the linker to use for the linking phase -macro(configure_linker _project_name linker) +macro(configure_linker _project_name _linker) if(NOT - "${linker}" + "${_linker}" STREQUAL "") include(CheckCXXCompilerFlag) - set(_linker_flag "-fuse-ld=${linker}") + set(_linker_flag "-fuse-ld=${_linker}") check_cxx_compiler_flag(${_linker_flag} _cxx_supports_linker) - if(_cxx_supports_linker) - target_compile_options(${_project_name} INTERFACE ${_linker_flag}) + if("${_cxx_supports_linker}" STREQUAL "1") + message(TRACE "Using ${_linker} as the linker for ${_project_name}") + target_link_options(${_project_name} INTERFACE ${_linker_flag}) + else() + message(WARNING "Linker ${_linker} is not supported by the compiler. Using the default linker.") endif() endif() endmacro() From de8b145862fc311d6b9b2b70209d747aa32a3a26 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 14:20:03 -0800 Subject: [PATCH 044/139] fix: do not use the exceptions and rtti optimizations for C --- src/Optimization.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 68058e42..f741b0c2 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -37,13 +37,13 @@ endmacro() # Disable C++ exceptions for the given project. macro(disable_exceptions _project_name) - target_compile_options(${_project_name} INTERFACE $<$:/EHs-c- /D_HAS_EXCEPTIONS=0>) - target_compile_options(${_project_name} INTERFACE $<$>:-fno-exceptions + target_compile_options(${_project_name} INTERFACE $<$>>:/EHs-c- /D_HAS_EXCEPTIONS=0>) + target_compile_options(${_project_name} INTERFACE $<$>>>:-fno-exceptions -fno-unwind-tables>) endmacro() # Disable C++ RTTI (Run-Time Type Information) for the given project. macro(disable_rtti _project_name) - target_compile_options(${_project_name} INTERFACE $<$:/GR->) - target_compile_options(${_project_name} INTERFACE $<$>:-fno-rtti>) + target_compile_options(${_project_name} INTERFACE $<$>>:/GR->) + target_compile_options(${_project_name} INTERFACE $<$>>>:-fno-rtti>) endmacro() From 9633694f2436762d0f589a80ecf1098dc16279a7 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 15:12:41 -0800 Subject: [PATCH 045/139] chore: fix the linter errors --- cspell.config.yaml | 2 ++ src/Optimization.cmake | 11 ++++++---- tests/emscripten/main.cpp | 4 ++-- tests/install/src/another_main.cpp | 4 ++-- tests/minimal/main.cpp | 4 ++-- tests/myproj/include/mylib/lib.hpp | 12 +++++----- .../libs/mythirdpartylib/include/Foo.hpp | 18 +++++++-------- tests/myproj/libs/mythirdpartylib/src/Foo.cpp | 20 ++++++++--------- tests/myproj/src/main/main.cpp | 22 +++++++++---------- tests/myproj/src/mylib2/lib.cpp | 14 ++++++------ tests/rpi3/main.c | 4 ++-- tests/rpi3/main.cpp | 4 ++-- tests/rpi4-vcpkg/main.cpp | 4 ++-- tests/rpi4/main.cpp | 4 ++-- 14 files changed, 66 insertions(+), 61 deletions(-) diff --git a/cspell.config.yaml b/cspell.config.yaml index 27316dc3..578690f5 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -10,6 +10,8 @@ language: en, en-GB allowCompoundWords: true enableGlobDot: true words: + - awalsh + - pkgs - aarch - aminya - Amnet diff --git a/src/Optimization.cmake b/src/Optimization.cmake index f741b0c2..e5d1407c 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -37,13 +37,16 @@ endmacro() # Disable C++ exceptions for the given project. macro(disable_exceptions _project_name) - target_compile_options(${_project_name} INTERFACE $<$>>:/EHs-c- /D_HAS_EXCEPTIONS=0>) - target_compile_options(${_project_name} INTERFACE $<$>>>:-fno-exceptions - -fno-unwind-tables>) + target_compile_options(${_project_name} INTERFACE $<$>>:/EHs-c- + /D_HAS_EXCEPTIONS=0>) + target_compile_options( + ${_project_name} INTERFACE $<$>>>:-fno-exceptions + -fno-unwind-tables>) endmacro() # Disable C++ RTTI (Run-Time Type Information) for the given project. macro(disable_rtti _project_name) target_compile_options(${_project_name} INTERFACE $<$>>:/GR->) - target_compile_options(${_project_name} INTERFACE $<$>>>:-fno-rtti>) + target_compile_options(${_project_name} + INTERFACE $<$>>>:-fno-rtti>) endmacro() diff --git a/tests/emscripten/main.cpp b/tests/emscripten/main.cpp index 7e674a92..7daec985 100644 --- a/tests/emscripten/main.cpp +++ b/tests/emscripten/main.cpp @@ -13,6 +13,6 @@ #endif int main() { - printf("hello, world!\n"); - return 0; + printf("hello, world!\n"); + return 0; } \ No newline at end of file diff --git a/tests/install/src/another_main.cpp b/tests/install/src/another_main.cpp index 4b80c7b0..f14a6747 100644 --- a/tests/install/src/another_main.cpp +++ b/tests/install/src/another_main.cpp @@ -2,6 +2,6 @@ #include int main() { - some_fun2(); - return some_fun2(); + some_fun2(); + return some_fun2(); } \ No newline at end of file diff --git a/tests/minimal/main.cpp b/tests/minimal/main.cpp index 0296dc98..115ff095 100644 --- a/tests/minimal/main.cpp +++ b/tests/minimal/main.cpp @@ -1,6 +1,6 @@ #include int main() { - fmt::print("Hello World!"); - return 0; + fmt::print("Hello World!"); + return 0; } \ No newline at end of file diff --git a/tests/myproj/include/mylib/lib.hpp b/tests/myproj/include/mylib/lib.hpp index e808b290..6ecad59b 100644 --- a/tests/myproj/include/mylib/lib.hpp +++ b/tests/myproj/include/mylib/lib.hpp @@ -18,13 +18,13 @@ #include int some_fun() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - // populate an Eigen vector with the values - auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1); + // populate an Eigen vector with the values + auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1); - // print the vector - fmt::print("{}", eigen_vec); + // print the vector + fmt::print("{}", eigen_vec); - return 0; + return 0; } diff --git a/tests/myproj/libs/mythirdpartylib/include/Foo.hpp b/tests/myproj/libs/mythirdpartylib/include/Foo.hpp index 52915fce..26aa7e0e 100644 --- a/tests/myproj/libs/mythirdpartylib/include/Foo.hpp +++ b/tests/myproj/libs/mythirdpartylib/include/Foo.hpp @@ -8,18 +8,18 @@ namespace mythirdpartylib { class MYTHIRDPARTYLIB_EXPORT Foo { - public: - Foo() = default; +public: + Foo() = default; - /*implicit*/ Foo(int a) : m_a(a) {} + /*implicit*/ Foo(int a) : m_a(a) {} - int a() const { return m_a; } + int a() const { return m_a; } - void update(bool b, bool c, bool d); - void bad(std::vector &v); + void update(bool b, bool c, bool d); + void bad(std::vector &v); - private: - int m_a; +private: + int m_a; }; -}// namespace mythirdpartylib \ No newline at end of file +} // namespace mythirdpartylib \ No newline at end of file diff --git a/tests/myproj/libs/mythirdpartylib/src/Foo.cpp b/tests/myproj/libs/mythirdpartylib/src/Foo.cpp index c8d279e7..9e777af4 100644 --- a/tests/myproj/libs/mythirdpartylib/src/Foo.cpp +++ b/tests/myproj/libs/mythirdpartylib/src/Foo.cpp @@ -3,22 +3,22 @@ namespace mythirdpartylib { void Foo::update(bool b, bool c, bool d) { - int e = b + d; - m_a = e; + int e = b + d; + m_a = e; } void Foo::bad(std::vector &v) { - std::string val = "hello"; - int index = -1;// bad, plus should use gsl::index - for (int i = 0; i < v.size(); ++i) { - if (v[i] == val) { - index = i; - break; - } + std::string val = "hello"; + int index = -1; // bad, plus should use gsl::index + for (int i = 0; i < v.size(); ++i) { + if (v[i] == val) { + index = i; + break; } + } } static Foo foo(5); static Foo bar = 42; -}// namespace mythirdpartylib \ No newline at end of file +} // namespace mythirdpartylib \ No newline at end of file diff --git a/tests/myproj/src/main/main.cpp b/tests/myproj/src/main/main.cpp index 8493180a..3dc72141 100644 --- a/tests/myproj/src/main/main.cpp +++ b/tests/myproj/src/main/main.cpp @@ -16,20 +16,20 @@ #include int main() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); + fmt::print("{}", eigen_vec); -#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails - Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); +#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails + Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); + fmt::print("{}", eigen_vec2); #endif - // trigger address sanitizer - // int *p = nullptr; - // *p = 1; + // trigger address sanitizer + // int *p = nullptr; + // *p = 1; - // trigger compiler warnings, clang-tidy, and cppcheck - int a; + // trigger compiler warnings, clang-tidy, and cppcheck + int a; } diff --git a/tests/myproj/src/mylib2/lib.cpp b/tests/myproj/src/mylib2/lib.cpp index 41e4b510..38458dce 100644 --- a/tests/myproj/src/mylib2/lib.cpp +++ b/tests/myproj/src/mylib2/lib.cpp @@ -16,15 +16,15 @@ #include int some_fun2() { - fmt::print("Hello from fmt{}", "!"); + fmt::print("Hello from fmt{}", "!"); - Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); + fmt::print("{}", eigen_vec); -#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails - Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); +#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails + Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); + fmt::print("{}", eigen_vec2); #endif - return 0; + return 0; } diff --git a/tests/rpi3/main.c b/tests/rpi3/main.c index 764e0c1e..c18a0350 100644 --- a/tests/rpi3/main.c +++ b/tests/rpi3/main.c @@ -1,6 +1,6 @@ #include int main() { - printf("Hello World\n"); - return 0; + printf("Hello World\n"); + return 0; } \ No newline at end of file diff --git a/tests/rpi3/main.cpp b/tests/rpi3/main.cpp index b94615d2..4706104d 100644 --- a/tests/rpi3/main.cpp +++ b/tests/rpi3/main.cpp @@ -1,6 +1,6 @@ #include int main() { - std::cout << "Hello World!"; - return 0; + std::cout << "Hello World!"; + return 0; } \ No newline at end of file diff --git a/tests/rpi4-vcpkg/main.cpp b/tests/rpi4-vcpkg/main.cpp index 0296dc98..115ff095 100644 --- a/tests/rpi4-vcpkg/main.cpp +++ b/tests/rpi4-vcpkg/main.cpp @@ -1,6 +1,6 @@ #include int main() { - fmt::print("Hello World!"); - return 0; + fmt::print("Hello World!"); + return 0; } \ No newline at end of file diff --git a/tests/rpi4/main.cpp b/tests/rpi4/main.cpp index b94615d2..4706104d 100644 --- a/tests/rpi4/main.cpp +++ b/tests/rpi4/main.cpp @@ -1,6 +1,6 @@ #include int main() { - std::cout << "Hello World!"; - return 0; + std::cout << "Hello World!"; + return 0; } \ No newline at end of file From 254a256b5b477e61c25ceeda80551c73d83bcea2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 15:17:06 -0800 Subject: [PATCH 046/139] fix: add the missing > in the generator expression --- src/Optimization.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Optimization.cmake b/src/Optimization.cmake index e5d1407c..4fdd1bb4 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -37,16 +37,16 @@ endmacro() # Disable C++ exceptions for the given project. macro(disable_exceptions _project_name) - target_compile_options(${_project_name} INTERFACE $<$>>:/EHs-c- + target_compile_options(${_project_name} INTERFACE $<$,$>>:/EHs-c- /D_HAS_EXCEPTIONS=0>) target_compile_options( - ${_project_name} INTERFACE $<$>>>:-fno-exceptions + ${_project_name} INTERFACE $<$,$>>>:-fno-exceptions -fno-unwind-tables>) endmacro() # Disable C++ RTTI (Run-Time Type Information) for the given project. macro(disable_rtti _project_name) - target_compile_options(${_project_name} INTERFACE $<$>>:/GR->) + target_compile_options(${_project_name} INTERFACE $<$,$>>:/GR->) target_compile_options(${_project_name} - INTERFACE $<$>>>:-fno-rtti>) + INTERFACE $<$,$>>>:-fno-rtti>) endmacro() From 6ad95df2dabefec268f4593a8ced1d099c29e9fb Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 19 Jan 2023 15:24:23 -0800 Subject: [PATCH 047/139] fix: remove extra > from the end --- src/Optimization.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Optimization.cmake b/src/Optimization.cmake index 4fdd1bb4..6dc3ad47 100644 --- a/src/Optimization.cmake +++ b/src/Optimization.cmake @@ -37,16 +37,16 @@ endmacro() # Disable C++ exceptions for the given project. macro(disable_exceptions _project_name) - target_compile_options(${_project_name} INTERFACE $<$,$>>:/EHs-c- + target_compile_options(${_project_name} INTERFACE $<$,$>:/EHs-c- /D_HAS_EXCEPTIONS=0>) target_compile_options( - ${_project_name} INTERFACE $<$,$>>>:-fno-exceptions + ${_project_name} INTERFACE $<$,$>>:-fno-exceptions -fno-unwind-tables>) endmacro() # Disable C++ RTTI (Run-Time Type Information) for the given project. macro(disable_rtti _project_name) - target_compile_options(${_project_name} INTERFACE $<$,$>>:/GR->) + target_compile_options(${_project_name} INTERFACE $<$,$>:/GR->) target_compile_options(${_project_name} - INTERFACE $<$,$>>>:-fno-rtti>) + INTERFACE $<$,$>>:-fno-rtti>) endmacro() From c9be40e4360c356c4b6d3623891c922100fd097c Mon Sep 17 00:00:00 2001 From: abeimler Date: Fri, 20 Jan 2023 10:50:31 +0100 Subject: [PATCH 048/139] fix: cross arm C build --- .github/workflows/ci.cross.arm.yml | 2 +- docker/Dockerfile.arm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 5095c91d..a020fcc7 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -33,7 +33,7 @@ jobs: install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - task: rpi3:build.cross - install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi + install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi target: arm-none-eabi steps: - uses: actions/checkout@v3 diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 264ae86d..975b6ef5 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -14,7 +14,7 @@ FROM base AS setup RUN setup-cpp --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true RUN apt-get update && apt-get install -y \ - gcc-arm-none-eabi binutils-arm-none-eabi \ + gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi \ && rm -rf /var/lib/apt/lists/* COPY ./docker/entrypoint.sh /docker-entrypoint.sh From 01a63ffa4cbaffc9e96b7639416478d26b8b3e66 Mon Sep 17 00:00:00 2001 From: Brandon Michael Whitchurch Date: Fri, 20 Jan 2023 09:21:18 -0800 Subject: [PATCH 049/139] Added riscv architecture to Utilities.cmake --- src/Utilities.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Utilities.cmake b/src/Utilities.cmake index 9231c4b0..bc209005 100644 --- a/src/Utilities.cmake +++ b/src/Utilities.cmake @@ -189,6 +189,14 @@ function(detect_architecture arch) set(${arch} arm64 PARENT_SCOPE) + elseif(_arch STREQUAL riscv64) + set(${arch} + rv64 + PARENT_SCOPE) + elseif(_arch STREQUAL riscv32) + set(${arch} + rv32 + PARENT_SCOPE) else() # fallback to the most common architecture message(STATUS "Unknown architecture ${_arch} - using x64") From 42bbceddac134df7b7f25801245fd39e9441be00 Mon Sep 17 00:00:00 2001 From: Brandon Michael Whitchurch Date: Fri, 20 Jan 2023 09:49:33 -0800 Subject: [PATCH 050/139] Allow passing build and host profiles through to conan --- src/Conan.cmake | 21 +++++++++++++++++++++ src/Index.cmake | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Conan.cmake b/src/Conan.cmake index 029bc214..4fe4844a 100644 --- a/src/Conan.cmake +++ b/src/Conan.cmake @@ -77,6 +77,23 @@ macro(run_conan) # CONAN_ENV should be redundant, since the profile can set CC & CXX endif() + if("${ProjectOptions_CONAN_PROFILE}" STREQUAL "") + set(CONAN_DEFAULT_PROFILE "default") + else() + set(CONAN_DEFAULT_PROFILE ${ProjectOptions_CONAN_PROFILE}) + endif() + if("${ProjectOptions_CONAN_BUILD_PROFILE}" STREQUAL "") + set(CONAN_BUILD_PROFILE ${CONAN_DEFAULT_PROFILE}) + else() + set(CONAN_BUILD_PROFILE ${ProjectOptions_CONAN_BUILD_PROFILE}) + endif() + + if("${ProjectOptions_CONAN_HOST_PROFILE}" STREQUAL "") + set(CONAN_HOST_PROFILE ${CONAN_DEFAULT_PROFILE}) + else() + set(CONAN_HOST_PROFILE ${ProjectOptions_CONAN_HOST_PROFILE}) + endif() + # PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR} is used to tell conan to process # the external "conanfile.py" provided with the project # Alternatively a conanfile.txt could be used @@ -90,6 +107,10 @@ macro(run_conan) ${ProjectOptions_CONAN_OPTIONS} # Pass CMake compilers to Conan ${CONAN_ENV} + PROFILE_HOST + ${CONAN_HOST_PROFILE} + PROFILE_BUILD + ${CONAN_BUILD_PROFILE} # Pass either autodetected settings or a conan profile ${CONAN_SETTINGS} ${OUTPUT_QUIET}) diff --git a/src/Index.cmake b/src/Index.cmake index 612fe7dc..00b9c436 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -97,7 +97,9 @@ macro(project_options) PREFIX LINKER VS_ANALYSIS_RULESET - CONAN_PROFILE) + CONAN_PROFILE + CONAN_HOST_PROFILE + CONAN_BUILD_PROFILE) set(multiValueArgs DOXYGEN_THEME MSVC_WARNINGS From 742777c7d4ec667f82985481aa5747c7694b4254 Mon Sep 17 00:00:00 2001 From: abeimler Date: Wed, 25 Jan 2023 12:55:57 +0100 Subject: [PATCH 051/139] feat: make enable_cross_compiler more open-closed (#180) --- .github/workflows/ci.cross.arm.yml | 19 +- docker-compose.yml | 17 +- docker/Dockerfile.aarch64 | 22 ++ docker/Dockerfile.arm | 4 +- docker/Dockerfile.arm-bare-metal | 27 +++ docker/Taskfile.yml | 12 ++ src/CrossCompiler.cmake | 194 +++++++++++++----- src/Vcpkg.cmake | 24 ++- ...in.cmake => aarch64-linux.toolchain.cmake} | 6 +- src/toolchains/arm-linux.toolchain.cmake | 38 ++++ src/toolchains/arm.toolchain.cmake | 8 +- ...hain.cmake => arm64-linux.toolchain.cmake} | 6 +- .../i686-w64-mingw32.toolchain.cmake | 20 +- .../x86_64-w64-mingw32.toolchain.cmake | 20 +- tests/rpi3/CMakeLists.txt | 29 ++- tests/rpi3/Taskfile.yml | 10 +- tests/rpi3/main.c | 17 +- tests/rpi4-vcpkg/Taskfile.yml | 6 + tests/rpi4/CMakeLists.txt | 21 +- tests/rpi4/Taskfile.yml | 6 + 20 files changed, 403 insertions(+), 103 deletions(-) create mode 100644 docker/Dockerfile.arm-bare-metal rename src/toolchains/{aarch64.toolchain.cmake => aarch64-linux.toolchain.cmake} (91%) create mode 100644 src/toolchains/arm-linux.toolchain.cmake rename src/toolchains/{arm64.toolchain.cmake => arm64-linux.toolchain.cmake} (91%) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index a020fcc7..97050567 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -19,21 +19,33 @@ jobs: - true task: - rpi4:build.cross - - rpi4-vcpkg:build.cross - rpi4:build.cross.custom-toolchain + - rpi4-vcpkg:build.cross + - rpi4-vcpkg:build.cross.custom-toolchain + - rpi4:build.cross.aarch64 - rpi3:build.cross + - rpi3:build.cross.bare-metal include: - task: rpi4:build.cross install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu + - task: rpi4:build.cross.custom-toolchain + install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + target: aarch64-linux-gnu - task: rpi4-vcpkg:build.cross install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - - task: rpi4:build.cross.custom-toolchain + - task: rpi4-vcpkg:build.cross.custom-toolchain + install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + target: aarch64-linux-gnu + - task: rpi4:build.cross.aarch64 install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - task: rpi3:build.cross - install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi + install-cross-compiler: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + target: arm-linux-gnueabi + - task: rpi3:build.cross.bare-metal + install-cross-compiler: gcc-arm-none-eabi g++-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi target: arm-none-eabi steps: - uses: actions/checkout@v3 @@ -64,7 +76,6 @@ jobs: clangtidy: true task: true doxygen: true - powershell: true - name: Setup ARM (Cross) Compiler uses: awalsh128/cache-apt-pkgs-action@latest diff --git a/docker-compose.yml b/docker-compose.yml index 6b43e85c..38602127 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -109,8 +109,23 @@ services: context: . dockerfile: ./docker/Dockerfile.aarch64 target: build-vcpkg + build-rpi4-vcpkg-custom: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build-vcpkg-custom build-rpi4-custom: build: context: . dockerfile: ./docker/Dockerfile.aarch64 - target: build-custom \ No newline at end of file + target: build-custom + build-rpi4-aarch64: + build: + context: . + dockerfile: ./docker/Dockerfile.aarch64 + target: build-aarch64 + build-rpi3-bare-metal: + build: + context: . + dockerfile: ./docker/Dockerfile.arm-bare-metal + target: build \ No newline at end of file diff --git a/docker/Dockerfile.aarch64 b/docker/Dockerfile.aarch64 index a16b09e5..f992d821 100644 --- a/docker/Dockerfile.aarch64 +++ b/docker/Dockerfile.aarch64 @@ -45,6 +45,17 @@ WORKDIR /home/project_options RUN git submodule update --init CMD ["/bin/bash", "-c", "task rpi4:build.cross.custom-toolchain"] +FROM setup AS build-vcpkg-custom +COPY . /home/project_options +WORKDIR /home/project_options +RUN git submodule update --init +CMD ["/bin/bash", "-c", "task rpi4-vcpkg:build.cross.custom-toolchain"] + +FROM setup AS build-aarch64 +COPY . /home/project_options +WORKDIR /home/project_options +RUN git submodule update --init +CMD ["/bin/bash", "-c", "task rpi4:build.cross.aarch64"] FROM setup AS test RUN apt-get update && apt-get install -y \ @@ -55,3 +66,14 @@ WORKDIR /home/project_options RUN git submodule update --init ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu CMD ["/bin/bash", "-c", "task rpi4:build.cross && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] + + +FROM setup AS test-aarch64 +RUN apt-get update && apt-get install -y \ + qemu-user \ + && rm -rf /var/lib/apt/lists/* +COPY . /home/project_options +WORKDIR /home/project_options +RUN git submodule update --init +ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu +CMD ["/bin/bash", "-c", "task rpi4:build.aarch64 && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"] diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 975b6ef5..28249144 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -14,7 +14,7 @@ FROM base AS setup RUN setup-cpp --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true RUN apt-get update && apt-get install -y \ - gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi \ + gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ && rm -rf /var/lib/apt/lists/* COPY ./docker/entrypoint.sh /docker-entrypoint.sh @@ -32,4 +32,4 @@ FROM setup AS build-debug COPY . /home/project_options WORKDIR /home/project_options RUN git submodule update --init -CMD ["/bin/bash", "-c", "task rpi3:build.cross.debug"] \ No newline at end of file +CMD ["/bin/bash", "-c", "task rpi3:build.cross.debug"] diff --git a/docker/Dockerfile.arm-bare-metal b/docker/Dockerfile.arm-bare-metal new file mode 100644 index 00000000..517d25bb --- /dev/null +++ b/docker/Dockerfile.arm-bare-metal @@ -0,0 +1,27 @@ +FROM ubuntu:22.04 AS base + +# add setup-cpp https://github.com/aminya/setup-cpp +RUN apt-get update && apt-get install -y \ + npm \ + && rm -rf /var/lib/apt/lists/* +RUN npm install -g setup-cpp + + +FROM base AS setup + +# install cmake, ninja, and ccache +RUN setup-cpp --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true + +RUN apt-get update && apt-get install -y \ + gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi \ + && rm -rf /var/lib/apt/lists/* + +COPY ./docker/entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] + + +FROM setup AS build +COPY . /home/project_options +WORKDIR /home/project_options +RUN git submodule update --init +CMD ["/bin/bash", "-c", "task rpi3:build.cross.bare-metal"] diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 9a71221e..0eed9ce2 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -49,3 +49,15 @@ tasks: rpi4.custom: - docker-compose up --build build-rpi4-custom - docker-compose down + + rpi4.aarch64: + - docker-compose up --build build-rpi4-aarch64 + - docker-compose down + + rpi3.bare-metal: + - docker-compose up --build build-rpi3-bare-metal + - docker-compose down + + rpi4.vcpkg-custsom: + - docker-compose up --build build-rpi4-vcpkg-custom + - docker-compose down \ No newline at end of file diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index 8c7436c4..68fd4bd0 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -2,43 +2,102 @@ include_guard() # Enable cross-compiling macro(enable_cross_compiler) + set(options) + set(oneValueArgs + DEFAULT_TRIPLET + CC + CXX + TARGET_ARCHITECTURE + CROSS_ROOT + CROSS_TRIPLET + TOOLCHAIN_FILE) + set(multiValueArgs) + cmake_parse_arguments( + EnableCrossCompiler + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN}) + include("${ProjectOptions_SRC_DIR}/Utilities.cmake") detect_architecture(_arch) - if("${DEFAULT_TRIPLET}" STREQUAL "") - detect_compiler() + set(_default_triplet ${DEFAULT_TRIPLET}) + if(NOT "${EnableCrossCompiler_DEFAULT_TRIPLET}" STREQUAL "") + set(_default_triplet ${EnableCrossCompiler_DEFAULT_TRIPLET}) + else() + if("${DEFAULT_TRIPLET}" STREQUAL "") + detect_compiler() + endif() + set(_default_triplet ${CMAKE_SYSTEM_PROCESSOR}) endif() + set(_cc ${CMAKE_C_COMPILER}) set(_cxx ${CMAKE_CXX_COMPILER}) + if(NOT "${EnableCrossCompiler_CC}" STREQUAL "") + set(_cc ${EnableCrossCompiler_CC}) + endif() + if(NOT "${EnableCrossCompiler_CXX}" STREQUAL "") + set(_cxx ${EnableCrossCompiler_CXX}) + endif() + + set(_target_architecture ${TARGET_ARCHITECTURE}) + if(NOT "${EnableCrossCompiler_TARGET_ARCHITECTURE}" STREQUAL "") + set(_target_architecture ${EnableCrossCompiler_TARGET_ARCHITECTURE}) + endif() + + set(_cross_root ${CROSS_ROOT}) + if(NOT "${EnableCrossCompiler_CROSS_ROOT}" STREQUAL "") + set(_cross_root ${EnableCrossCompiler_CROSS_ROOT}) + endif() + + set(_cross_triplet ${CROSS_TRIPLET}) + if(NOT "${EnableCrossCompiler_CROSS_TRIPLET}" STREQUAL "") + set(_cross_triplet ${EnableCrossCompiler_CROSS_TRIPLET}) + endif() # detect compiler by triplet - if("${DEFAULT_TRIPLET}" STREQUAL "x64-mingw-dynamic" OR "${DEFAULT_TRIPLET}" STREQUAL "x64-mingw-static") + if("${_default_triplet}" STREQUAL "x64-mingw-dynamic" OR "${_default_triplet}" STREQUAL "x64-mingw-static") if("${_cc}" STREQUAL "") set(_cc "x86_64-w64-mingw32-gcc") endif() if("${_cxx}" STREQUAL "") set(_cxx "x86_64-w64-mingw32-g++") endif() - set(TARGET_ARCHITECTURE "x64") - elseif("${DEFAULT_TRIPLET}" STREQUAL "x86-mingw-dynamic" OR "${DEFAULT_TRIPLET}" STREQUAL "x86-mingw-static") + if("${_target_architecture}" STREQUAL "") + set(_target_architecture "x64") + endif() + elseif("${_default_triplet}" STREQUAL "x86-mingw-dynamic" OR "${_default_triplet}" STREQUAL "x86-mingw-static") if("${_cc}" STREQUAL "") set(_cc "i686-w64-mingw32-gcc") endif() if("${_cxx}" STREQUAL "") set(_cxx "i686-w64-mingw32-g++") endif() - set(TARGET_ARCHITECTURE "x86") - elseif("${DEFAULT_TRIPLET}" STREQUAL "wasm32-emscripten") - set(_cc "emcc") - set(_cxx "em++") - set(TARGET_ARCHITECTURE "wasm32-emscripten") - elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux") - set(TARGET_ARCHITECTURE "arm-linux") - elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") - set(TARGET_ARCHITECTURE "arm64-linux") + if("${_target_architecture}" STREQUAL "") + set(_target_architecture "x86") + endif() + elseif("${_default_triplet}" STREQUAL "wasm32-emscripten") + if("${_cc}" STREQUAL "") + set(_cc "emcc") + endif() + if("${_cxx}" STREQUAL "") + set(_cxx "em++") + endif() + if("${_target_architecture}" STREQUAL "") + set(_target_architecture "wasm32-emscripten") + endif() + elseif("${_default_triplet}" STREQUAL "arm64-linux") + if("${_target_architecture}" STREQUAL "") + set(_target_architecture "arm64-linux") + endif() + elseif("${_default_triplet}" STREQUAL "arm-linux") + if("${_target_architecture}" STREQUAL "") + set(_target_architecture "arm-linux") + endif() endif() - if("${TARGET_ARCHITECTURE}" STREQUAL "") + if("${_target_architecture}" STREQUAL "") if("${_cc}" STREQUAL "") set(_cc $ENV{CC}) endif() @@ -46,15 +105,15 @@ macro(enable_cross_compiler) set(_cxx $ENV{CXX}) endif() if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") - set(TARGET_ARCHITECTURE "x64") + set(_target_architecture "x64") elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") - set(TARGET_ARCHITECTURE "x86") + set(_target_architecture "x86") elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em\\+\\+") - set(TARGET_ARCHITECTURE "wasm32-emscripten") + set(_target_architecture "wasm32-emscripten") else() # TODO: check for arm compiler message(WARNING "if you are using arm cross-compiler, please set DEFAULT_TRIPLET") - set(TARGET_ARCHITECTURE ${_arch}) + set(_target_architecture ${_arch}) endif() endif() @@ -80,56 +139,65 @@ macro(enable_cross_compiler) set(USE_CROSSCOMPILER_EMSCRIPTEN TRUE) elseif(_cc MATCHES "aarch64-linux-gnu-gcc" OR _cxx MATCHES "aarch64-linux-gnu-g\\+\\+") set(USE_CROSSCOMPILER_AARCH64 TRUE) - elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux") - set(USE_CROSSCOMPILER_ARM TRUE) - elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") - set(USE_CROSSCOMPILER_ARM64 TRUE) + elseif(_default_triplet MATCHES "arm64-linux") + set(USE_CROSSCOMPILER_ARM64_LINUX TRUE) + elseif(_default_triplet MATCHES "arm-linux") + set(USE_CROSSCOMPILER_ARM_LINUX TRUE) endif() set(LIBRARY_LINKAGE) if(BUILD_SHARED_LIBS) set(LIBRARY_LINKAGE "dynamic") - if("${TRIPLET}" STREQUAL "x64-mingw-static" OR "${TRIPLET}" STREQUAL "x86-mingw-static") + if("${_default_triplet}" STREQUAL "x64-mingw-static" OR "${_default_triplet}" STREQUAL "x86-mingw-static") message(WARNING "cross-compiler triplet is set to 'static' but BUILD_SHARED_LIBS is enabled") endif() else() - if("${TRIPLET}" STREQUAL "x64-mingw-dynamic" OR "${TRIPLET}" STREQUAL "x86-mingw-dynamic") + if("${_default_triplet}" STREQUAL "x64-mingw-dynamic" OR "${_default_triplet}" STREQUAL "x86-mingw-dynamic") set(LIBRARY_LINKAGE "dynamic") - elseif("${TRIPLET}" STREQUAL "x64-mingw-static" OR "${TRIPLET}" STREQUAL "x86-mingw-static") + elseif("${_default_triplet}" STREQUAL "x64-mingw-static" OR "${_default_triplet}" STREQUAL "x86-mingw-static") set(LIBRARY_LINKAGE "static") else() set(LIBRARY_LINKAGE "static") endif() endif() - - if(NOT DEFINED CROSS_ROOT) + + if("${_cross_root}" STREQUAL "") if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") - set(CROSS_ROOT "/usr/x86_64-w64-mingw32") + set(_cross_root "/usr/x86_64-w64-mingw32") elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") - set(CROSS_ROOT "/usr/i686-w64-mingw32") + set(_cross_root "/usr/i686-w64-mingw32") elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?") - set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabi") - if(NOT DEFINED CROSS_TRIPLET) - set(CROSS_TRIPLET "arm-linux-gnueabi") + set(_cross_root "/usr/gcc-arm-linux-gnueabi") + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-linux-gnueabi") endif() elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?") - set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabihf") - if(NOT DEFINED CROSS_TRIPLET) - set(CROSS_TRIPLET "arm-linux-gnueabihf") - endif() - elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?") - set(CROSS_ROOT "/usr/gcc-arm-none-eabi") - if(NOT DEFINED CROSS_TRIPLET) - set(CROSS_TRIPLET "arm-none-eabi") + set(_cross_root "/usr/gcc-arm-linux-gnueabihf") + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-linux-gnueabihf") endif() elseif(_cc MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?") - set(CROSS_ROOT "/usr/gcc-aarch64-linux-gnu") - if(NOT DEFINED CROSS_TRIPLET) - set(CROSS_TRIPLET "gcc-aarch64-linux-gnu") + set(_cross_root "/usr/gcc-aarch64-linux-gnu") + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "gcc-aarch64-linux-gnu") + endif() + elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?") + set(_cross_root "/usr/gcc-arm-none-eabi") + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-none-eabi") endif() + set(USE_CROSSCOMPILER_ARM_NONE TRUE) endif() # TODO: check if path is right, check for header files or something endif() + if(NOT "${_cross_root}" STREQUAL "" AND "${_cross_triplet}" STREQUAL "") + message(WARNING "CROSS_ROOT (${_cross_root}) is set, but CROSS_TRIPLET is not") + endif() + + set(CROSS_ROOT ${_cross_root}) + set(CROSS_TRIPLET ${_cross_triplet}) + set(DEFAULT_TRIPLET ${_default_triplet}) + set(TARGET_ARCHITECTURE ${_target_architecture}) if(USE_CROSSCOMPILER_EMSCRIPTEN) if(NOT @@ -167,9 +235,15 @@ macro(enable_cross_compiler) endif() set(_toolchain_file) - get_toolchain_file(_toolchain_file) + if(${EnableCrossCompiler_TOOLCHAIN_FILE}) + set(_toolchain_file ${EnableCrossCompiler_TOOLCHAIN_FILE}) + else() + get_toolchain_file(_toolchain_file) + endif() if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) + else() + set(CROSS_TOOLCHAIN_FILE ${_toolchain_file}) endif() set(CROSSCOMPILING TRUE) @@ -187,13 +261,21 @@ macro(enable_cross_compiler) #message(STATUS "EMSDK_NODE: $ENV{EMSDK_NODE}") #message(STATUS "EMSDK: $ENV{EMSDK}") message(STATUS "use emscripten cross-compiler emulator: ${CMAKE_CROSSCOMPILING_EMULATOR}") + else() + message(STATUS "use SYSROOT: ${CROSS_ROOT}") endif() message(STATUS "Target Architecture: ${TARGET_ARCHITECTURE}") - if(DEFAULT_TRIPLET) + if(NOT "${DEFAULT_TRIPLET}" STREQUAL "") message(STATUS "Default Triplet: ${DEFAULT_TRIPLET}") endif() message(STATUS "Host Triplet: ${HOST_TRIPLET}") - message(STATUS "Toolchain File: ${CMAKE_TOOLCHAIN_FILE}") + if(NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") + message(STATUS "Toolchain File: ${CMAKE_TOOLCHAIN_FILE}") + else() + if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + message(STATUS "Cross-compile Toolchain File (for vcpkg): ${CROSS_TOOLCHAIN_FILE}") + endif() + endif() endmacro() # Get the toolchain file @@ -221,19 +303,23 @@ function(get_toolchain_file value) else() message(ERROR "EMSCRIPTEN_ROOT is not set, please define EMSCRIPTEN_ROOT (emscripten repo)") endif() - elseif(USE_CROSSCOMPILER_AARCH64) + elseif(USE_CROSSCOMPILER_AARCH64_LINUX) set(${value} - ${ProjectOptions_SRC_DIR}/toolchains/aarch64.toolchain.cmake + ${ProjectOptions_SRC_DIR}/toolchains/aarch64-linux.toolchain.cmake PARENT_SCOPE) - elseif(USE_CROSSCOMPILER_ARM) + elseif(USE_CROSSCOMPILER_ARM_LINUX) set(${value} - ${ProjectOptions_SRC_DIR}/toolchains/arm.toolchain.cmake + ${ProjectOptions_SRC_DIR}/toolchains/arm-linux.toolchain.cmake + PARENT_SCOPE) + elseif(USE_CROSSCOMPILER_ARM64_LINUX) + set(${value} + ${ProjectOptions_SRC_DIR}/toolchains/arm64-linux.toolchain.cmake PARENT_SCOPE) - elseif(USE_CROSSCOMPILER_ARM64) + elseif(USE_CROSSCOMPILER_ARM_NONE) set(${value} - ${ProjectOptions_SRC_DIR}/toolchains/arm64.toolchain.cmake + ${ProjectOptions_SRC_DIR}/toolchains/arm.toolchain.cmake PARENT_SCOPE) - elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux" OR "${DEFAULT_TRIPLET}" STREQUAL "arm64-linux") + elseif(DEFAULT_TRIPLET MATCHES "arm") message(STATUS "Don't forget to provide an cmake-toolchain file (for ${DEFAULT_TRIPLET})") endif() endfunction() diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 47eeaeaf..648397bc 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -124,14 +124,22 @@ macro(run_vcpkg) set(VCPKG_LIBRARY_LINKAGE "${LIBRARY_LINKAGE}") endif() endif() - set(_toolchain_file) - get_toolchain_file(_toolchain_file) - if(_toolchain_file) - set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE - ${_toolchain_file} - CACHE STRING "vcpkg chainload toolchain file") - message(STATUS "Setup cross-compiler for ${VCPKG_TARGET_TRIPLET}") - message(STATUS "Use cross-compiler toolchain: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") + + if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + set(_toolchain_file) + if(NOT "${CROSS_TOOLCHAIN_FILE}" STREQUAL "") + set(_toolchain_file ${CROSS_TOOLCHAIN_FILE}) + else() + get_toolchain_file(_toolchain_file) + endif() + + if(${_toolchain_file}) + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + ${_toolchain_file} + CACHE STRING "vcpkg chainload toolchain file") + message(STATUS "Setup cross-compiler for ${VCPKG_TARGET_TRIPLET}") + message(STATUS "Use cross-compiler toolchain for vcpkg: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") + endif() endif() endif() endmacro() diff --git a/src/toolchains/aarch64.toolchain.cmake b/src/toolchains/aarch64-linux.toolchain.cmake similarity index 91% rename from src/toolchains/aarch64.toolchain.cmake rename to src/toolchains/aarch64-linux.toolchain.cmake index 73d00afc..48c8f095 100644 --- a/src/toolchains/aarch64.toolchain.cmake +++ b/src/toolchains/aarch64-linux.toolchain.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) -if(CROSS_ROOT) +if(NOT "${CROSS_ROOT}" STREQUAL "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +11,12 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) endif() -if(CROSS_C) +if(NOT "${CROSS_C}" STREQUAL "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) endif() -if(CROSS_CXX) +if(NOT "${CROSS_CXX}" STREQUAL "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) diff --git a/src/toolchains/arm-linux.toolchain.cmake b/src/toolchains/arm-linux.toolchain.cmake new file mode 100644 index 00000000..08d19d62 --- /dev/null +++ b/src/toolchains/arm-linux.toolchain.cmake @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +if(NOT "${CROSS_ROOT}" STREQUAL "") + set(CMAKE_SYSROOT ${CROSS_ROOT}) + #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) +elseif("${CMAKE_SYSROOT}" STREQUAL "") + set(CMAKE_SYSROOT /usr/${CROSS_TRIPLET}) + #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) +endif() + +if(NOT "${CROSS_C}" STREQUAL "") + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) +endif() +if(NOT "${CROSS_CXX}" STREQUAL "") + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# The target triple needs to match the prefix of the binutils exactly +# (e.g. CMake looks for arm-none-eabi-ar) +#set(CLANG_TARGET_TRIPLE ${CROSS_TRIPLET}) +#set(GCC_ARM_TOOLCHAIN_PREFIX ${CROSS_TRIPLET}) +#set(CMAKE_C_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_CXX_COMPILER_TARGET ${CROSS_TRIPLET}) +#set(CMAKE_ASM_COMPILER_TARGET ${CROSS_TRIPLET}) diff --git a/src/toolchains/arm.toolchain.cmake b/src/toolchains/arm.toolchain.cmake index 99a426d7..e3f1962c 100644 --- a/src/toolchains/arm.toolchain.cmake +++ b/src/toolchains/arm.toolchain.cmake @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) -if(CROSS_ROOT) +if(NOT "${CROSS_ROOT}" STREQUAL "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +11,12 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) endif() -if(CROSS_C) +if(NOT "${CROSS_C}" STREQUAL "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) endif() -if(CROSS_CXX) +if(NOT "${CROSS_CXX}" STREQUAL "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) diff --git a/src/toolchains/arm64.toolchain.cmake b/src/toolchains/arm64-linux.toolchain.cmake similarity index 91% rename from src/toolchains/arm64.toolchain.cmake rename to src/toolchains/arm64-linux.toolchain.cmake index 8caeb262..c23aef9c 100644 --- a/src/toolchains/arm64.toolchain.cmake +++ b/src/toolchains/arm64-linux.toolchain.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm64) -if(CROSS_ROOT) +if(NOT "${CROSS_ROOT}" STREQUAL "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +11,12 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) endif() -if(CROSS_C) +if(NOT "${CROSS_C}" STREQUAL "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) endif() -if(CROSS_CXX) +if(NOT "${CROSS_CXX}" STREQUAL "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) diff --git a/src/toolchains/i686-w64-mingw32.toolchain.cmake b/src/toolchains/i686-w64-mingw32.toolchain.cmake index 0ba729fd..9c807703 100644 --- a/src/toolchains/i686-w64-mingw32.toolchain.cmake +++ b/src/toolchains/i686-w64-mingw32.toolchain.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "i686") -if(CROSS_ROOT) +if(NOT "${CROSS_ROOT}" STREQUAL "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,9 +11,21 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) endif() -set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) -set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) -set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) +if(NOT "${CROSS_C}" STREQUAL "") + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +endif() +if(NOT "${CROSS_CXX}" STREQUAL "") + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) +endif() +if(NOT "${CROSS_RC}" STREQUAL "") + set(CMAKE_RC_COMPILER ${CROSS_RC}) +else() + set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) +endif() # search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) diff --git a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake index ad234935..243f0c96 100644 --- a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake +++ b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "x64") -if(CROSS_ROOT) +if(NOT "${CROSS_ROOT}" STREQUAL "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,9 +11,21 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) endif() -set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) -set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) -set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) +if(NOT "${CROSS_C}" STREQUAL "") + set(CMAKE_C_COMPILER ${CROSS_C}) +else() + set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +endif() +if(NOT "${CROSS_CXX}" STREQUAL "") + set(CMAKE_CXX_COMPILER ${CROSS_CXX}) +else() + set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +endif() +if(NOT "${CROSS_RC}" STREQUAL "") + set(CMAKE_RC_COMPILER ${CROSS_RC}) +else() + set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) +endif() # search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt index 205baa02..fccdf501 100644 --- a/tests/rpi3/CMakeLists.txt +++ b/tests/rpi3/CMakeLists.txt @@ -13,9 +13,26 @@ set(CMAKE_C_STANDARD 99) include(../../src/Index.cmake) # opt-in cross-compiling -option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) -if(ENABLE_CROSS_COMPILING) - enable_cross_compiler() +if(ENABLE_BARE_METAL_CROSS_COMPILING) + # my custom arm settings + enable_cross_compiler( + CC "arm-none-eabi-gcc" + CXX "arm-none-eabi-g++" + TARGET_ARCHITECTURE "arm" + CROSS_ROOT "/usr/arm-none-eabi-gcc" + CROSS_TRIPLET "arm-none-eabi-gcc" + ) + + # some more custom compiler settings + # -Wl,--gc-sections Perform the dead code elimination. + # --specs=nano.specs Link with newlib-nano. + # --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb" CACHE INTERNAL "Linker options") +else() + option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) + if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() + endif() endif() # Set the project name to your project name, my project isn't very descriptive @@ -108,7 +125,6 @@ project_options( #target_sources(example PRIVATE main.cpp) #target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) #target_link_libraries(example PRIVATE project_options project_warnings) -#target_link_options(example PRIVATE -Wl,--start-group -lgcc -lc -lstdc++ -lm -lrdimon -Wl,--end-group) #FIXME: linking with c++ (libs) ... /libstdc++.a(cxx11-ios_failure.o): in function `(anonymous namespace)::__io_category_instance()': add_executable(example_c) @@ -116,7 +132,9 @@ target_sources(example_c PRIVATE main.c) target_include_directories(example_c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(example_c PRIVATE project_options project_warnings) -if(ENABLE_CROSS_COMPILING) +if(ENABLE_BARE_METAL_CROSS_COMPILING OR ENABLE_CROSS_COMPILING) + #target_link_options(example PRIVATE -Wl,--start-group -lgcc -lc -lstdc++ -lm -lrdimon -Wl,--end-group) + # fix: ...arm-none-eabi/lib/libg.a(lib_a-exit.o): in function `exit': target_link_options( example_c @@ -125,7 +143,6 @@ if(ENABLE_CROSS_COMPILING) -lgcc -lc -lm - -lrdimon -Wl,--end-group) # custom raspberry pi 3 options diff --git a/tests/rpi3/Taskfile.yml b/tests/rpi3/Taskfile.yml index 8bdc0fd8..892a427f 100644 --- a/tests/rpi3/Taskfile.yml +++ b/tests/rpi3/Taskfile.yml @@ -14,10 +14,16 @@ tasks: cmds: - task: build.debug vars: - CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabihf-g++"}} -DDEFAULT_TRIPLET=arm-linux -DCROSS_ROOT=/usr/gcc-arm-linux-gnueabihf build.cross: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-none-eabi-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-none-eabi-g++"}} -DDEFAULT_TRIPLET=arm-linux + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabi-g++"}} -DDEFAULT_TRIPLET=arm-linux -DCROSS_ROOT=/usr/gcc-arm-linux-gnueabihf + + build.cross.bare-metal: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_BARE_METAL_CROSS_COMPILING:BOOL=ON diff --git a/tests/rpi3/main.c b/tests/rpi3/main.c index c18a0350..1b12d56d 100644 --- a/tests/rpi3/main.c +++ b/tests/rpi3/main.c @@ -1,6 +1,15 @@ -#include +// dummy functions +void uart_init() {} +void uart_send(unsigned int c) {} +char uart_getc() { return 'a'; } +void uart_puts(char *s) {} -int main() { - printf("Hello World\n"); - return 0; +void main() { + uart_init(); + + uart_puts("Hello World!\n"); + + while(1) { + uart_send(uart_getc()); + } } \ No newline at end of file diff --git a/tests/rpi4-vcpkg/Taskfile.yml b/tests/rpi4-vcpkg/Taskfile.yml index 175de702..992a7c4d 100644 --- a/tests/rpi4-vcpkg/Taskfile.yml +++ b/tests/rpi4-vcpkg/Taskfile.yml @@ -12,5 +12,11 @@ tasks: vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + build.cross.custom-toolchain: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake + lint: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi4/CMakeLists.txt b/tests/rpi4/CMakeLists.txt index 3292bb7d..b53f000e 100644 --- a/tests/rpi4/CMakeLists.txt +++ b/tests/rpi4/CMakeLists.txt @@ -13,9 +13,22 @@ set(CMAKE_C_STANDARD 99) include(../../src/Index.cmake) # opt-in cross-compiling -option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) -if(ENABLE_CROSS_COMPILING) - enable_cross_compiler() +if(ENABLE_AARCH64_CROSS_COMPILING) + # my custom aarch64 settings + enable_cross_compiler( + DEFAULT_TRIPLET "arm64-linux" + CC "aarch64-linux-gnu-gcc" + CXX "aarch64-linux-gnu-g++" + TARGET_ARCHITECTURE "arm64-linux" + CROSS_ROOT "/usr/gcc-aarch64-linux-gnu" + CROSS_TRIPLET "aarch64-linux-gnu" + #TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/my-toolchain.cmake" + ) +else() + option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) + if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() + endif() endif() # Set the project name to your project name, my project isn't very descriptive @@ -104,7 +117,7 @@ target_sources(example PRIVATE main.cpp) target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(example PRIVATE project_options project_warnings) -if(ENABLE_CROSS_COMPILING) +if(ENABLE_AARCH64_CROSS_COMPILING OR ENABLE_CROSS_COMPILING) # custom raspberry pi 4 options #target_compile_definitions(project_options INTERFACE -D__ARM_NEON) target_compile_options(project_options INTERFACE -mcpu=cortex-a72) diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml index 6c6704b5..6bad4141 100644 --- a/tests/rpi4/Taskfile.yml +++ b/tests/rpi4/Taskfile.yml @@ -27,3 +27,9 @@ tasks: - task: build vars: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake + + build.cross.aarch64: + cmds: + - task: build + vars: + CMAKE_ARGS: -DENABLE_AARCH64_CROSS_COMPILING:BOOL=ON \ No newline at end of file From b18054b2ef1f4d9096451609fecc195f976580f8 Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 26 Jan 2023 13:43:28 +0100 Subject: [PATCH 052/139] fix: CI arm bare-metal build --- .github/workflows/ci.cross.arm.yml | 28 +++--- docker/Taskfile.yml | 12 +-- src/CrossCompiler.cmake | 134 +++++++++++++++++++---------- src/Vcpkg.cmake | 14 +-- tests/rpi3/CMakeLists.txt | 2 +- tests/rpi3/Taskfile.yml | 4 +- tests/rpi4-vcpkg/Taskfile.yml | 2 +- tests/rpi4/Taskfile.yml | 6 +- 8 files changed, 120 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 97050567..0e1add9c 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -18,35 +18,31 @@ jobs: cmake: - true task: + - rpi3:build.cross + - rpi3:build.cross.bare-metal - rpi4:build.cross + - rpi4:build.cross.aarch64 - rpi4:build.cross.custom-toolchain - rpi4-vcpkg:build.cross - - rpi4-vcpkg:build.cross.custom-toolchain - - rpi4:build.cross.aarch64 - - rpi3:build.cross - - rpi3:build.cross.bare-metal include: + - task: rpi3:build.cross + install-cross-compiler: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + target: arm-linux-gnueabi + - task: rpi3:build.cross.bare-metal + install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi + target: arm-none-eabi - task: rpi4:build.cross install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - - task: rpi4:build.cross.custom-toolchain - install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu - target: aarch64-linux-gnu - - task: rpi4-vcpkg:build.cross + - task: rpi4:build.cross.aarch64 install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - - task: rpi4-vcpkg:build.cross.custom-toolchain + - task: rpi4:build.cross.custom-toolchain install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - - task: rpi4:build.cross.aarch64 + - task: rpi4-vcpkg:build.cross install-cross-compiler: g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu target: aarch64-linux-gnu - - task: rpi3:build.cross - install-cross-compiler: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf - target: arm-linux-gnueabi - - task: rpi3:build.cross.bare-metal - install-cross-compiler: gcc-arm-none-eabi g++-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi - target: arm-none-eabi steps: - uses: actions/checkout@v3 with: diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index 0eed9ce2..f0ace602 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -29,6 +29,10 @@ tasks: rpi3.debug: - docker-compose up --build build-rpi3-debug - docker-compose down + + rpi3.bare-metal: + - docker-compose up --build build-rpi3-bare-metal + - docker-compose down rpi4: - docker-compose up --build build-rpi4 @@ -42,10 +46,6 @@ tasks: - docker-compose up --build test-rpi4 - docker-compose down - rpi4.vcpkg: - - docker-compose up --build build-rpi4-vcpkg - - docker-compose down - rpi4.custom: - docker-compose up --build build-rpi4-custom - docker-compose down @@ -54,8 +54,8 @@ tasks: - docker-compose up --build build-rpi4-aarch64 - docker-compose down - rpi3.bare-metal: - - docker-compose up --build build-rpi3-bare-metal + rpi4.vcpkg: + - docker-compose up --build build-rpi4-vcpkg - docker-compose down rpi4.vcpkg-custsom: diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index 68fd4bd0..ba6c4370 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -25,13 +25,11 @@ macro(enable_cross_compiler) set(_default_triplet ${DEFAULT_TRIPLET}) if(NOT "${EnableCrossCompiler_DEFAULT_TRIPLET}" STREQUAL "") set(_default_triplet ${EnableCrossCompiler_DEFAULT_TRIPLET}) - else() - if("${DEFAULT_TRIPLET}" STREQUAL "") - detect_compiler() - endif() - set(_default_triplet ${CMAKE_SYSTEM_PROCESSOR}) endif() + if(DEFINED CMAKE_TOOLCHAIN_FILE OR DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + detect_compiler() + endif() set(_cc ${CMAKE_C_COMPILER}) set(_cxx ${CMAKE_CXX_COMPILER}) if(NOT "${EnableCrossCompiler_CC}" STREQUAL "") @@ -56,7 +54,24 @@ macro(enable_cross_compiler) set(_cross_triplet ${EnableCrossCompiler_CROSS_TRIPLET}) endif() - # detect compiler by triplet + # detect triplet by compiler (fallback) + if("${_default_triplet}" STREQUAL "") + if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") + set(_default_triplet "x64-mingw-dynamic") + elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") + set(_default_triplet "i686-mingw-dynamic") + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?") + set(_default_triplet "arm-linux") + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?") + set(_default_triplet "arm-linux") + elseif(_cc MATCHES "(gcc-)?aarch64-linux-(gnu-)?[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-(gnu-)?[gc]..?") + set(_default_triplet "arm64-linux") + elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em..") + set(_default_triplet "wasm32-emscripten") + endif() + endif() + + # detect compiler and target_architecture by triplet if("${_default_triplet}" STREQUAL "x64-mingw-dynamic" OR "${_default_triplet}" STREQUAL "x64-mingw-static") if("${_cc}" STREQUAL "") set(_cc "x86_64-w64-mingw32-gcc") @@ -96,19 +111,19 @@ macro(enable_cross_compiler) set(_target_architecture "arm-linux") endif() endif() + if("${_cc}" STREQUAL "") + set(_cc $ENV{CC}) + endif() + if("${_cxx}" STREQUAL "") + set(_cxx $ENV{CXX}) + endif() if("${_target_architecture}" STREQUAL "") - if("${_cc}" STREQUAL "") - set(_cc $ENV{CC}) - endif() - if("${_cxx}" STREQUAL "") - set(_cxx $ENV{CXX}) - endif() if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") set(_target_architecture "x64") elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") set(_target_architecture "x86") - elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em\\+\\+") + elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em..") set(_target_architecture "wasm32-emscripten") else() # TODO: check for arm compiler @@ -117,7 +132,7 @@ macro(enable_cross_compiler) endif() endif() - if(NOT DEFINED HOST_TRIPLET) + if("${HOST_TRIPLET}" STREQUAL "") if(WIN32) set(HOST_TRIPLET "${_arch}-windows") elseif(APPLE) @@ -129,16 +144,17 @@ macro(enable_cross_compiler) set(USE_CROSSCOMPILER_MINGW) set(USE_CROSSCOMPILER_EMSCRIPTEN) - set(USE_CROSSCOMPILER_ARM) - set(USE_CROSSCOMPILER_ARM64) - set(USE_CROSSCOMPILER_AARCH64) + set(USE_CROSSCOMPILER_ARM_LINUX) + set(USE_CROSSCOMPILER_ARM64_LINUX) + set(USE_CROSSCOMPILER_AARCH64_LINUX) + set(USE_CROSSCOMPILER_ARM_NONE) if(_cc MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?") set(MINGW TRUE) set(USE_CROSSCOMPILER_MINGW TRUE) - elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em\\+\\+") + elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em..") set(USE_CROSSCOMPILER_EMSCRIPTEN TRUE) elseif(_cc MATCHES "aarch64-linux-gnu-gcc" OR _cxx MATCHES "aarch64-linux-gnu-g\\+\\+") - set(USE_CROSSCOMPILER_AARCH64 TRUE) + set(USE_CROSSCOMPILER_AARCH64_LINUX TRUE) elseif(_default_triplet MATCHES "arm64-linux") set(USE_CROSSCOMPILER_ARM64_LINUX TRUE) elseif(_default_triplet MATCHES "arm-linux") @@ -161,39 +177,56 @@ macro(enable_cross_compiler) endif() endif() - if("${_cross_root}" STREQUAL "") - if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") + if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/x86_64-w64-mingw32") - elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") + endif() + set(MINGW TRUE) + set(USE_CROSSCOMPILER_MINGW TRUE) + elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/i686-w64-mingw32") - elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?") + endif() + set(MINGW TRUE) + set(USE_CROSSCOMPILER_MINGW TRUE) + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/gcc-arm-linux-gnueabi") - if("${_cross_triplet}" STREQUAL "") - set(_cross_triplet "arm-linux-gnueabi") - endif() - elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?") + endif() + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-linux-gnueabi") + endif() + elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/gcc-arm-linux-gnueabihf") - if("${_cross_triplet}" STREQUAL "") - set(_cross_triplet "arm-linux-gnueabihf") - endif() - elseif(_cc MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?") + endif() + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-linux-gnueabihf") + endif() + elseif(_cc MATCHES "(gcc-)?aarch64-linux-(gnu-)?[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-(gnu-)?[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/gcc-aarch64-linux-gnu") - if("${_cross_triplet}" STREQUAL "") - set(_cross_triplet "gcc-aarch64-linux-gnu") - endif() - elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?") + endif() + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "gcc-aarch64-linux-gnu") + endif() + set(USE_CROSSCOMPILER_AARCH64_LINUX TRUE) + elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?") + if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/gcc-arm-none-eabi") - if("${_cross_triplet}" STREQUAL "") - set(_cross_triplet "arm-none-eabi") - endif() - set(USE_CROSSCOMPILER_ARM_NONE TRUE) endif() - # TODO: check if path is right, check for header files or something + if("${_cross_triplet}" STREQUAL "") + set(_cross_triplet "arm-none-eabi") + endif() + set(USE_CROSSCOMPILER_ARM_NONE TRUE) endif() + # TODO: check if path is right, check for header files or something if(NOT "${_cross_root}" STREQUAL "" AND "${_cross_triplet}" STREQUAL "") message(WARNING "CROSS_ROOT (${_cross_root}) is set, but CROSS_TRIPLET is not") endif() + set(CROSS_C ${_cc}) + set(CROSS_CXX ${_cxx}) set(CROSS_ROOT ${_cross_root}) set(CROSS_TRIPLET ${_cross_triplet}) set(DEFAULT_TRIPLET ${_default_triplet}) @@ -230,20 +263,27 @@ macro(enable_cross_compiler) set(CMAKE_CROSSCOMPILING_EMULATOR "$ENV{EMSDK_NODE};--experimental-wasm-threads") endif() else() - set(CMAKE_C_COMPILER ${_cc}) - set(CMAKE_CXX_COMPILER ${_cxx}) + if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + set(CMAKE_C_COMPILER ${_cc}) + set(CMAKE_CXX_COMPILER ${_cxx}) + endif() endif() set(_toolchain_file) - if(${EnableCrossCompiler_TOOLCHAIN_FILE}) + if(NOT "${EnableCrossCompiler_TOOLCHAIN_FILE}" STREQUAL "") set(_toolchain_file ${EnableCrossCompiler_TOOLCHAIN_FILE}) else() get_toolchain_file(_toolchain_file) endif() + set(CROSS_TOOLCHAIN_FILE ${_toolchain_file}) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) + if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) + else() + set(CROSS_TOOLCHAIN_FILE ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}) + endif() else() - set(CROSS_TOOLCHAIN_FILE ${_toolchain_file}) + set(CROSS_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}) endif() set(CROSSCOMPILING TRUE) @@ -262,7 +302,9 @@ macro(enable_cross_compiler) #message(STATUS "EMSDK: $ENV{EMSDK}") message(STATUS "use emscripten cross-compiler emulator: ${CMAKE_CROSSCOMPILING_EMULATOR}") else() - message(STATUS "use SYSROOT: ${CROSS_ROOT}") + if(NOT "${CROSS_ROOT}" STREQUAL "") + message(STATUS "use SYSROOT: ${CROSS_ROOT}") + endif() endif() message(STATUS "Target Architecture: ${TARGET_ARCHITECTURE}") if(NOT "${DEFAULT_TRIPLET}" STREQUAL "") diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 648397bc..f73abe48 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -114,13 +114,13 @@ macro(run_vcpkg) if(CROSSCOMPILING) if(NOT MINGW) - if(TARGET_ARCHITECTURE) + if(NOT "${TARGET_ARCHITECTURE}" STREQUAL "") set(VCPKG_TARGET_TRIPLET "${TARGET_ARCHITECTURE}") endif() - if(DEFAULT_TRIPLET) + if(NOT "${DEFAULT_TRIPLET}" STREQUAL "") set(VCPKG_DEFAULT_TRIPLET "${DEFAULT_TRIPLET}") endif() - if(LIBRARY_LINKAGE) + if(NOT "${LIBRARY_LINKAGE}" STREQUAL "") set(VCPKG_LIBRARY_LINKAGE "${LIBRARY_LINKAGE}") endif() endif() @@ -133,13 +133,13 @@ macro(run_vcpkg) get_toolchain_file(_toolchain_file) endif() - if(${_toolchain_file}) + if(NOT "${_toolchain_file}" STREQUAL "") set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${_toolchain_file} - CACHE STRING "vcpkg chainload toolchain file") - message(STATUS "Setup cross-compiler for ${VCPKG_TARGET_TRIPLET}") - message(STATUS "Use cross-compiler toolchain for vcpkg: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") + CACHE STRING "vcpkg chainload toolchain file" FORCE) endif() endif() + message(STATUS "Setup cross-compiler for ${VCPKG_TARGET_TRIPLET}") + message(STATUS "Use cross-compiler toolchain for vcpkg: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") endif() endmacro() diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt index fccdf501..bba143c3 100644 --- a/tests/rpi3/CMakeLists.txt +++ b/tests/rpi3/CMakeLists.txt @@ -20,7 +20,7 @@ if(ENABLE_BARE_METAL_CROSS_COMPILING) CXX "arm-none-eabi-g++" TARGET_ARCHITECTURE "arm" CROSS_ROOT "/usr/arm-none-eabi-gcc" - CROSS_TRIPLET "arm-none-eabi-gcc" + CROSS_TRIPLET "arm-none-eabi" ) # some more custom compiler settings diff --git a/tests/rpi3/Taskfile.yml b/tests/rpi3/Taskfile.yml index 892a427f..0d3b6c74 100644 --- a/tests/rpi3/Taskfile.yml +++ b/tests/rpi3/Taskfile.yml @@ -14,13 +14,13 @@ tasks: cmds: - task: build.debug vars: - CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabihf-g++"}} -DDEFAULT_TRIPLET=arm-linux -DCROSS_ROOT=/usr/gcc-arm-linux-gnueabihf + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabihf-g++"}} -DDEFAULT_TRIPLET=arm-linux build.cross: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabi-g++"}} -DDEFAULT_TRIPLET=arm-linux -DCROSS_ROOT=/usr/gcc-arm-linux-gnueabihf + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "arm-linux-gnueabihf-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "arm-linux-gnueabi-g++"}} -DDEFAULT_TRIPLET=arm-linux build.cross.bare-metal: cmds: diff --git a/tests/rpi4-vcpkg/Taskfile.yml b/tests/rpi4-vcpkg/Taskfile.yml index 992a7c4d..b410198a 100644 --- a/tests/rpi4-vcpkg/Taskfile.yml +++ b/tests/rpi4-vcpkg/Taskfile.yml @@ -16,7 +16,7 @@ tasks: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE={{.CWD}}/tests/rpi4-vcpkg/cmake/my-toolchain.cmake -DDEFAULT_TRIPLET=arm64-linux lint: - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file diff --git a/tests/rpi4/Taskfile.yml b/tests/rpi4/Taskfile.yml index 6bad4141..81d8f0d6 100644 --- a/tests/rpi4/Taskfile.yml +++ b/tests/rpi4/Taskfile.yml @@ -14,19 +14,19 @@ tasks: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "aarch64-linux-gnu-g++"}} build.cross.debug: cmds: - task: build.debug vars: - CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux + CMAKE_ARGS: -DENABLE_CHECKING:BOOL=ON -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "aarch64-linux-gnu-g++"}} build.cross.custom-toolchain: cmds: - task: build vars: - CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "gcc-aarch64-linux-gnu-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "gcc-aarch64-linux-gnu-g++"}} -DDEFAULT_TRIPLET=arm64-linux -DCMAKE_TOOLCHAIN_FILE=./cmake/my-toolchain.cmake + CMAKE_ARGS: -DCMAKE_TOOLCHAIN_FILE={{.CWD}}/tests/rpi4/cmake/my-toolchain.cmake build.cross.aarch64: cmds: From 1c5d9a53e8d1303431df54795d11494f29743942 Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 26 Jan 2023 14:20:11 +0100 Subject: [PATCH 053/139] fix: CI arm bare-metal build --- .github/workflows/ci.cross.arm.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 0e1add9c..58e5a870 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -74,10 +74,8 @@ jobs: doxygen: true - name: Setup ARM (Cross) Compiler - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: ${{ matrix.install-cross-compiler }} - version: 1.0 + run: sudo apt-get install -y ${{ matrix.install-cross-compiler }} + shell: bash - name: Build (Task) run: | From 6491f7b890ee0a6eb1b52a585c2bfd6876b5b257 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 26 Jan 2023 14:02:03 -0800 Subject: [PATCH 054/139] fix: append -Xcompiler= to each Cuda warning --- src/CompilerWarnings.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CompilerWarnings.cmake b/src/CompilerWarnings.cmake index 8952ca89..78f3a86d 100644 --- a/src/CompilerWarnings.cmake +++ b/src/CompilerWarnings.cmake @@ -74,7 +74,7 @@ function( endif() if("${CUDA_WARNINGS}" STREQUAL "") - set(CUDA_WARNINGS + set(_CUDA_WARNINGS -Wall -Wextra -Wunused @@ -82,6 +82,12 @@ function( -Wshadow # TODO add more Cuda warnings ) + + # append -Xcompiler= to each warning + set(CUDA_WARNINGS "") + foreach(_warning ${_CUDA_WARNINGS}) + list(APPEND CUDA_WARNINGS "-Xcompiler=${_warning}") + endforeach() endif() if(WARNINGS_AS_ERRORS) From 08348bf9bd0ff418631cf713bb467276ba44a27f Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Mon, 30 Jan 2023 13:49:11 +0800 Subject: [PATCH 055/139] feat: create a symlink of `complie_commands.json` on the source dir (#190) --- src/Common.cmake | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Common.cmake b/src/Common.cmake index bd14d3a3..8c985daf 100644 --- a/src/Common.cmake +++ b/src/Common.cmake @@ -69,8 +69,52 @@ macro(common_project_options) CACHE STRING "Fallbacks for the RelWithDebInfo build type") endif() - # Generate compile_commands.json to make it easier to work with clang based tools - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # Generate and possibly symlink compile_commands.json to make it easier to work with clang based tools + if(CMAKE_GENERATOR MATCHES ".*Makefile*." OR CMAKE_GENERATOR MATCHES ".*Ninja*") + # Enable generate compile_commands.json + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + # Make a symbol link of compile_commands.json on the source dir to help clang based tools find it + if(WIN32) + # Detect whether cmake is run as administrator (only administrator can read the LOCAL SERVICE account reg key) + execute_process( + COMMAND reg query "HKU\\S-1-5-19" + ERROR_VARIABLE IS_NONADMINISTRATOR + OUTPUT_QUIET + ) + else() + set(IS_NONADMINISTRATOR "") + endif() + + if(IS_NONADMINISTRATOR) + # For non-administrator, create an auxiliary target and ask user to run it + add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/compile_commands.json + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json + DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json + VERBATIM + ) + add_custom_target(_copy_compile_commands + DEPENDS ${CMAKE_SOURCE_DIR}/compile_commands.json + VERBATIM + ) + message(STATUS "compile_commands.json was not symlinked to the root. Run `cmake --build -t _copy_compile_commands` if needed.") + else() + file(CREATE_LINK ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json SYMBOLIC) + message(TRACE "compile_commands.json was symlinked to the root.") + endif() + + # Add compile_commans.json to .gitignore if .gitignore exists + set(GITIGNORE_FILE "${CMAKE_SOURCE_DIR}/.gitignore") + + if(EXISTS ${GITIGNORE_FILE}) + file(STRINGS ${GITIGNORE_FILE} HAS_IGNORED REGEX "^compile_commands.json") + + if(NOT HAS_IGNORED) + message(TRACE "Adding compile_commands.json to .gitignore") + file(APPEND ${GITIGNORE_FILE} "\ncompile_commands.json") + endif() + endif() + endif() # Enhance error reporting and compiler messages if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") From 15086e1a9db063c29da9a8cf70805e120ade448a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 19:42:57 -0800 Subject: [PATCH 056/139] docs: generate documentation for project_options via Sphinx --- .github/workflows/ci.yml | 4 +- .gitignore | 4 +- LICENSE.txt | 2 +- Taskfile.yml | 10 +- docs/CMakeLists.txt | 168 +++++++++++++++++++++++++++++++ docs/Taskfile.yml | 13 +++ docs/cmake/FindSphinx.cmake | 59 +++++++++++ docs/conf.py.in | 156 ++++++++++++++++++++++++++++ docs/index.rst | 21 ++++ docs/root/css/company_style.css | 21 ++++ docs/root/index.html | 24 +++++ docs/root/js/version_switcher.js | 39 +++++++ docs/src/index.rst | 8 ++ docs/templates/layout.html | 4 + docs/templates/versions.html | 20 ++++ docs/update_versions.py | 87 ++++++++++++++++ src/Index.cmake | 7 ++ 17 files changed, 641 insertions(+), 6 deletions(-) create mode 100644 docs/CMakeLists.txt create mode 100644 docs/Taskfile.yml create mode 100644 docs/cmake/FindSphinx.cmake create mode 100644 docs/conf.py.in create mode 100644 docs/index.rst create mode 100644 docs/root/css/company_style.css create mode 100644 docs/root/index.html create mode 100644 docs/root/js/version_switcher.js create mode 100644 docs/src/index.rst create mode 100644 docs/templates/layout.html create mode 100644 docs/templates/versions.html create mode 100644 docs/update_versions.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be081b5c..bfd2cdbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: compiler: "gcc" cmake: true vcvarsall: true - steps: + steps: - uses: actions/checkout@v3 with: submodules: true @@ -84,7 +84,7 @@ jobs: - name: Test run: | - task ci.test + task test env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} diff --git a/.gitignore b/.gitignore index 04536277..14751714 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ test/build/ install/ test_install/build/ -build/ \ No newline at end of file +build/ +compile_commands.json +.mypy_cache/ diff --git a/LICENSE.txt b/LICENSE.txt index 576d69dd..07bdd39c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 aminya +Copyright (c) 2022-2100 Amin Yahyaabadi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Taskfile.yml b/Taskfile.yml index e9162ef0..736fbb9c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -25,13 +25,15 @@ includes: rpi4-vcpkg: taskfile: ./tests/rpi4-vcpkg/Taskfile.yml dir: ./tests/rpi4-vcpkg - + docs: + taskfile: ./docs/Taskfile.yml + dir: ./docs vars: CWD: sh: git rev-parse --show-toplevel tasks: - ci.test: + test: - task: myproj:test - task: myproj:test.release - task: install @@ -72,3 +74,7 @@ tasks: - task: myproj:clean - task: install:clean + + docs: + deps: + - docs:docs diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 00000000..9590f7cf --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,168 @@ +# This module builds the documentation for the project. +# Based on https://gitlab.com/Pro1/doxygen-cmake-sphinx/-/blob/master/doc/CMakeLists.txt + +cmake_minimum_required(VERSION 3.25) + +project( + project_options_docs + VERSION 0.1.0 + DESCRIPTION "Documentation" + LANGUAGES NONE) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include("../src/Index.cmake") + +project_options(ENABLE_DOXYGEN) + +find_package(Sphinx REQUIRED) +find_package(Python) + +option(SPHINX_INFO "Build Info manual with Sphinx" OFF) +option(SPHINX_MAN "Build man pages with Sphinx" OFF) +option(SPHINX_HTML "Build html help with Sphinx" ON) +option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF) +set(COMPONENT "documentation") + +set(SPHINX_FLAGS + "" + CACHE STRING "Flags to pass to sphinx-build") +separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}") + +mark_as_advanced(SPHINX_TEXT) +mark_as_advanced(SPHINX_FLAGS) + +if(NOT SPHINX_INFO + AND NOT SPHINX_MAN + AND NOT SPHINX_HTML + AND NOT SPHINX_SINGLEHTML + AND NOT SPHINX_QTHELP + AND NOT SPHINX_TEXT) + return() +elseif(NOT SPHINX_EXECUTABLE) + message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!") +endif() + +set(conf_copyright "MIT - Copyright (c) 2022-2100 Amin Yahyaabadi") +set(conf_docs "${CMAKE_CURRENT_SOURCE_DIR}") # Location of your index.rst +set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}") # Location of your conf.py +set(conf_out_path "${CMAKE_CURRENT_BINARY_DIR}") # Location of the output directory +set(conf_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +set(conf_release "${PROJECT_VERSION}") +set(conf_name "CMake Spinx Documentation") +set(conf_author "Firstname Lastname") +set(conf_brief "TODO some brief description.") +set(conf_doxygen_input + "\ + \"${CMAKE_SOURCE_DIR}/include\" \ + \"${CMAKE_SOURCE_DIR}/src\" \ + \"${CMAKE_SOURCE_DIR}/cmake\" \ +") +configure_file(conf.py.in conf.py @ONLY) + +set(doc_formats "") +if(SPHINX_HTML) + list(APPEND doc_formats html) + set(html_extra_commands COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/root/ + ${CMAKE_CURRENT_BINARY_DIR}) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/js/versions.js + "var ar_versions = [{\"version\": \"build\", \"folder\": \"html\", \"has_pdf\": false}]") +endif() +if(SPHINX_MAN) + list(APPEND doc_formats man) +endif() +if(SPHINX_SINGLEHTML) + list(APPEND doc_formats singlehtml) +endif() +if(SPHINX_TEXT) + list(APPEND doc_formats text) +endif() +if(SPHINX_INFO) + find_program( + MAKEINFO_EXECUTABLE + NAMES makeinfo + DOC "makeinfo tool") + if(NOT MAKEINFO_EXECUTABLE) + message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!") + endif() + list(APPEND doc_formats texinfo) + + # Sphinx texinfo builder supports .info, .txt, .html and .pdf output. + # SPHINX_INFO controls the .info output. + set(texinfo_extra_commands + COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info + ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi) +endif() + +set(doc_format_outputs "") +set(doc_format_last "") +foreach(format ${doc_formats}) + set(doc_format_output "doc_format_${format}") + set(doc_format_log "build-${format}.log") + add_custom_command( + OUTPUT ${doc_format_output} + COMMAND + ${SPHINX_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees -b ${format} + ${sphinx_flags} ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${format} > + ${CMAKE_CURRENT_BINARY_DIR}/${doc_format_log} # log stdout, pass stderr + ${${format}_extra_commands} + DEPENDS ${doc_format_last} + COMMENT "sphinx-build ${format}: see ${CMAKE_CURRENT_BINARY_DIR}/${doc_format_log}" + VERBATIM) + set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1) + list(APPEND doc_format_outputs ${doc_format_output}) + set(doc_format_last ${doc_format_output}) +endforeach() + +add_custom_target(documentation ALL DEPENDS ${doc_format_outputs}) + +if(SPHINX_INFO) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info + DESTINATION ${CMAKE_INFO_DIR} + ${COMPONENT}) +endif() + +if(SPHINX_MAN) + file( + GLOB man_rst + RELATIVE ${CMAKE_SOURCE_DIR}/Help/manual + ${CMAKE_SOURCE_DIR}/Help/manual/*.[1-9].rst) + foreach(m ${man_rst}) + if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$") + set(name "${CMAKE_MATCH_1}") + set(sec "${CMAKE_MATCH_2}") + set(skip FALSE) + if(NOT CMakeHelp_STANDALONE) + if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog) + set(skip TRUE) + elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog) + set(skip TRUE) + endif() + endif() + if(NOT skip) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec} + DESTINATION ${CMAKE_MAN_DIR}/man${sec} + ${COMPONENT}) + endif() + unset(skip) + endif() + endforeach() +endif() + +if(SPHINX_HTML) + install( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html + DESTINATION ${CMAKE_DOC_DIR} + ${COMPONENT} + PATTERN .buildinfo EXCLUDE) +endif() + +if(SPHINX_SINGLEHTML) + install( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml + DESTINATION ${CMAKE_DOC_DIR} + ${COMPONENT} + PATTERN .buildinfo EXCLUDE) +endif() diff --git a/docs/Taskfile.yml b/docs/Taskfile.yml new file mode 100644 index 00000000..27e360df --- /dev/null +++ b/docs/Taskfile.yml @@ -0,0 +1,13 @@ +# https://taskfile.dev/#6/installation +version: 3 + +tasks: + docs-deps: + - pip install -U GitPython sphinx-rtd-theme breathe sphinx-sitemap sphinxcontrib-moderncmakedomain myst-parser + + docs: + deps: + - docs-deps + cmds: + - cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release + - cmake --build ./build --config Release diff --git a/docs/cmake/FindSphinx.cmake b/docs/cmake/FindSphinx.cmake new file mode 100644 index 00000000..0213242b --- /dev/null +++ b/docs/cmake/FindSphinx.cmake @@ -0,0 +1,59 @@ +# - This module looks for Sphinx +# Find the Sphinx documentation generator +# +# Based on https://gitlab.com/Pro1/doxygen-cmake-sphinx/-/blob/master/cmake/FindSphinx.cmake +# +# This modules defines +# SPHINX_EXECUTABLE +# SPHINX_FOUND +find_program( + SPHINX_EXECUTABLE + NAMES sphinx-build + PATHS /usr/bin /usr/local/bin /opt/local/bin + DOC "Sphinx documentation generator") + +if(NOT SPHINX_EXECUTABLE) + set(_Python_VERSIONS + 2.7 + 2.6 + 2.5 + 2.4 + 2.3 + 2.2 + 2.1 + 2.0 + 1.6 + 1.5) + foreach(_version ${_Python_VERSIONS}) + set(_sphinx_NAMES sphinx-build-${_version}) + find_program( + SPHINX_EXECUTABLE + NAMES ${_sphinx_NAMES} + PATHS /usr/bin /usr/local/bin /opt/loca/bin + DOC "Sphinx documentation generator") + endforeach() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE) +mark_as_advanced(SPHINX_EXECUTABLE) + +function( + Sphinx_add_target + target_name + builder + conf + source + destination) + + add_custom_target( + ${target_name} ALL + COMMAND ${SPHINX_EXECUTABLE} -b ${builder} -c ${conf} ${source} ${destination} + COMMENT "Generating sphinx documentation: ${builder}") + + set_property( + DIRECTORY + APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${destination}) + +endfunction() diff --git a/docs/conf.py.in b/docs/conf.py.in new file mode 100644 index 00000000..eb9e3631 --- /dev/null +++ b/docs/conf.py.in @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 + +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, r'@conf_path@') +from sphinx.builders.html import StandaloneHTMLBuilder +import subprocess, os + + +source_suffix = '.rst' +# Doxygen +subprocess.call('doxygen ./Doxyfile.doxygen-docs', shell=True) + +# -- Project information ----------------------------------------------------- + +project = '@conf_name@' +author = '@conf_author@' +copyright = '@conf_copyright@' +version = '@conf_version@' # feature version +release = '@conf_release@' # full version string + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.autosectionlabel', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.mathjax', + 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode', + 'sphinx_sitemap', + 'sphinx.ext.inheritance_diagram', + 'breathe', + 'sphinxcontrib.moderncmakedomain', + 'myst_parser' +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['@conf_path@/templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +highlight_language = 'c++' + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' +html_theme_options = { + 'canonical_url': '', + 'analytics_id': '', # Provided by Google in your dashboard + 'display_version': True, + 'prev_next_buttons_location': 'bottom', + 'style_external_links': False, + + 'logo_only': False, + + # Toc options + 'collapse_navigation': True, + 'sticky_navigation': True, + 'navigation_depth': 4, + 'includehidden': True, + 'titles_only': False +} +# html_logo = '' +# github_url = '' +# html_baseurl = '' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ['@conf_path@/static'] +# html_style = 'css/cmake.css' +# +# html_js_files = [ +# 'js/version_switcher.js', +# ] + +# -- Breathe configuration ------------------------------------------------- + +master_doc = 'index' + +breathe_projects = { + 'C++ Sphinx Doxygen Breathe': "@conf_out_path@/xml/" +} +breathe_default_project = 'C++ Sphinx Doxygen Breathe' +breathe_default_members = ('members', 'undoc-members') + +############################ +# SETUP THE RTD LOWER-LEFT # +############################ +try: + html_context +except NameError: + html_context = dict() +html_context['display_lower_left'] = True + +if 'REPO_NAME' in os.environ: + REPO_NAME = os.environ['REPO_NAME'] +else: + REPO_NAME = '' + +# SET CURRENT_LANGUAGE +if 'current_language' in os.environ: + # get the current_language env var set by buildDocs.sh + current_language = os.environ['current_language'] +else: + # the user is probably doing `make html` + # set this build's current language to english + current_language = 'en' + +# tell the theme which language to we're currently building +html_context['current_language'] = current_language + +# SET CURRENT_VERSION +from git import Repo +repo = Repo( search_parent_directories=True ) + +if 'current_version' in os.environ: + # get the current_version env var set by buildDocs.sh + current_version = os.environ['current_version'] +elif 'CI_COMMIT_REF_NAME' in os.environ: + # get the current_version env var set by buildDocs.sh + current_version = os.environ['CI_COMMIT_REF_NAME'] +else: + # the user is probably doing `make html` + # set this build's current version by looking at the branch + current_version = repo.active_branch.name + +# tell the theme which version we're currently on ('current_version' affects +# the lower-left rtd menu and 'version' affects the logo-area version) +html_context['current_version'] = current_version +html_context['version'] = current_version diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..4c436fb1 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,21 @@ +project_options +====================================================== + +.. include:: ../README.md + :parser: myst_parser.sphinx_ + +Table of Contents +================== + +.. toctree:: + :maxdepth: 2 + + self + src/index + +Indices +================== + +* :ref:`genindex` +.. * :ref:`modindex` +* :ref:`search` diff --git a/docs/root/css/company_style.css b/docs/root/css/company_style.css new file mode 100644 index 00000000..e71d5e68 --- /dev/null +++ b/docs/root/css/company_style.css @@ -0,0 +1,21 @@ +/* Wrap sidebar content even within words so that long + document names do not escape sidebar borders. */ +div.sphinxsidebarwrapper { + word-wrap: break-word; +} + +/* Make links inside parsed-literal blocks more obvious + by using a background color and increased line spacing + to make them look boxed. */ +.literal-block { + line-height: 1.4; +} +.literal-block a.reference.internal { + background-color: #dfdfdf; +} + +/* Remove unwanted margin in case list item contains a div-wrapping + directive like `.. versionadded` or `.. deprecated`. */ +dd > :first-child > p { + margin-top: 0px; +} \ No newline at end of file diff --git a/docs/root/index.html b/docs/root/index.html new file mode 100644 index 00000000..156e4991 --- /dev/null +++ b/docs/root/index.html @@ -0,0 +1,24 @@ + + + + + + + Documentation + + + + + + This page should automatically redirect you to the latest version.., + + + + + diff --git a/docs/root/js/version_switcher.js b/docs/root/js/version_switcher.js new file mode 100644 index 00000000..da5074ed --- /dev/null +++ b/docs/root/js/version_switcher.js @@ -0,0 +1,39 @@ +function replaceContentInContainer(matchClass, content) { + var elems = document.getElementsByTagName('*'), i; + for (i in elems) { + if ((' ' + elems[i].className + ' ').indexOf(' ' + matchClass + ' ') + > -1) { + elems[i].innerHTML = content; + } + } +} + +function ar_updateVersionList(current_version) { + console.log(ar_versions, current_version); + + var versions_html = ["
Versions
"]; + var downloads_html = ["
Downloads
"]; + var show_downloads = false + for (const version of ar_versions) { + var version_link = '
' + version.version + '
' + var download_link = '' + if (version.has_pdf) { + download_link = '
' + version.version + '
' + show_downloads = true + } + if (version.version === current_version) { + versions_html.push("") + versions_html.push(version_link) + versions_html.push("") + downloads_html.push("") + downloads_html.push(download_link) + downloads_html.push("") + } else { + versions_html.push(version_link) + downloads_html.push(download_link) + } + } + versions_html.push("
") + downloads_html.push("
") + replaceContentInContainer("rst-other-versions", versions_html.join("") + (show_downloads ? downloads_html.join("") : "")) +} diff --git a/docs/src/index.rst b/docs/src/index.rst new file mode 100644 index 00000000..efe615be --- /dev/null +++ b/docs/src/index.rst @@ -0,0 +1,8 @@ +.. cmake-manual-description: CMake Modules Reference + +Macros and Function +************* + +Below you find a list of macros and functions included in this project. + +.. cmake-module:: ../../src/Index.cmake diff --git a/docs/templates/layout.html b/docs/templates/layout.html new file mode 100644 index 00000000..dd86bd88 --- /dev/null +++ b/docs/templates/layout.html @@ -0,0 +1,4 @@ +{% extends "!layout.html" %} +{% block extrahead %} + +{% endblock %} \ No newline at end of file diff --git a/docs/templates/versions.html b/docs/templates/versions.html new file mode 100644 index 00000000..f0af8a74 --- /dev/null +++ b/docs/templates/versions.html @@ -0,0 +1,20 @@ +{% if READTHEDOCS or display_lower_left %} +{# Add rst-badge after rst-versions for small badge style. #} +
+ + Read the Docs + v: {{ current_version }} + + +
+ +
+
+ + + +{% endif %} diff --git a/docs/update_versions.py b/docs/update_versions.py new file mode 100644 index 00000000..6a026c2e --- /dev/null +++ b/docs/update_versions.py @@ -0,0 +1,87 @@ +# This script is called by the CI Pipeline on the master branch and on tag releases +# +# + +import os +import requests +import json +import re + +import argparse + +parser = argparse.ArgumentParser(description='Get current versions.js file from the gitlab pages URL and extend the ' + 'list of available versions with this jus built documentation.') +parser.add_argument('--version_file', metavar='version_file', type=str, + help='Path where the current and updated versions.js file should be stored.', required=True) +parser.add_argument('--folder', metavar='folder', type=str, + help='Folder name where the version is stored', required=True) +parser.add_argument('--version', metavar='version', type=str, + help='Version of the generated documentation', required=True) + +args = parser.parse_args() + +#var ar_versions = [ +# { +# version: "master", +# folder: "master", +# has_pdf: "true", +# pdf_name: "master.pdf" +# }, +# { +# version: "2.1.0@ar/stable", +# folder: "2_1_0_ar_stable", +# has_pdf: "true", +# pdf_name: "2_1_0_ar_stable.pdf" +# }, +#] + +versions = list() + +if os.path.exists(args.version_file): + with open(args.version_file, 'r') as file: + js_data = file.read() + if js_data.startswith("var ar_versions = "): + js_data= js_data[len("var ar_versions = "):] + versions = json.loads(js_data) + +# Get branch name or tag name + +ref_exists = False +for v in versions: + if v['version'] == args.version: + ref_exists = True + print("Version already configured. Skipping update!") + exit(0) + +# Version is not yet in list, add it +versions.append({ + 'version': args.version, + 'folder': args.folder, + 'has_pdf': False +}) + +is_semver = re.compile("^v?([0-9\.]+)([^0-9\.]*)?$") + +def versionSortFunc(s): + ma = is_semver.match(s['version']) + if ma: + ints = list(ma.group(1).split('.')) + ints.append(ma.group(2)) + return ints + else: + return list(s['version']) + +versions.sort(key=versionSortFunc, reverse=True) + +new_js = "var ar_versions = " + json.dumps(versions, indent=2) + +js_dir = os.path.dirname(args.version_file) +if not os.path.isdir(js_dir): + os.makedirs (js_dir) +with open(args.version_file, 'w') as filetowrite: + filetowrite.write(new_js) + +print("File updated: " + args.version_file) + + + diff --git a/src/Index.cmake b/src/Index.cmake index 00b9c436..4061a5fe 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -1,3 +1,10 @@ +#[=======================================================================[.rst: + +.. include:: ../../README.md + :parser: myst_parser.sphinx_ + +#]=======================================================================] + cmake_minimum_required(VERSION 3.20) # 3.20 is required by the windows toolchain and cmake_path. It also has a more reliable building functionality. # 3.18 required by package_project and interprocedural optimization. It also has a more reliable building functionality (no errors during the linking stage). From 0cde9f951ff947056842d129adbc2e77bfa00f9d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 20:11:54 -0800 Subject: [PATCH 057/139] docs: add docs for the readme functions --- README.md | 210 ------------------ docs/src/dynamic_project_oprions.md | 67 ++++++ docs/src/index.rst | 10 +- docs/src/package_project.md | 31 +++ docs/src/project_options.md | 41 ++++ docs/src/run_vcpkg.md | 36 +++ docs/src/target_disable_static_analysis.md | 13 ++ docs/src/target_include_system_directories.md | 5 + docs/src/target_link_cuda.md | 10 + docs/src/target_link_system_libraries.md | 8 + src/Cuda.cmake | 15 +- src/DynamicProjectOptions.cmake | 27 +-- src/Index.cmake | 45 +--- src/PackageProject.cmake | 8 +- src/StaticAnalyzers.cmake | 7 +- src/SystemLink.cmake | 15 +- src/Vcpkg.cmake | 9 +- 17 files changed, 270 insertions(+), 287 deletions(-) create mode 100644 docs/src/dynamic_project_oprions.md create mode 100644 docs/src/package_project.md create mode 100644 docs/src/project_options.md create mode 100644 docs/src/run_vcpkg.md create mode 100644 docs/src/target_disable_static_analysis.md create mode 100644 docs/src/target_include_system_directories.md create mode 100644 docs/src/target_link_cuda.md create mode 100644 docs/src/target_link_system_libraries.md diff --git a/README.md b/README.md index 2e64d7bd..62d1b965 100644 --- a/README.md +++ b/README.md @@ -215,216 +215,6 @@ package_project( ) ``` -## `project_options` function - -It accepts the following named flags: - -- `ENABLE_CACHE`: Enable cache if available -- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck -- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy -- `ENABLE_VS_ANALYSIS`: Enable Visual Studio IDE code analysis if the generator is Visual Studio. -- `ENABLE_CONAN`: Use Conan for dependency management -- `ENABLE_INTERPROCEDURAL_OPTIMIZATION`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build -- `ENABLE_NATIVE_OPTIMIZATION`: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). -- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang -- `ENABLE_DOXYGEN`: Enable Doxygen documentation. The added `doxygen-docs` target can be built via `cmake --build ./build --target doxygen-docs`. -- `WARNINGS_AS_ERRORS`: Treat compiler and static code analyzer warnings as errors. This also affects CMake warnings related to those. -- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer -- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer -- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer -- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer -- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer -- `ENABLE_PCH`: Enable Precompiled Headers -- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use -- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang -- `ENABLE_UNITY`: Enable Unity builds of projects - -It gets the following named parameters that can have different values in front of them: - -- `PREFIX`: the optional prefix that is used to define `${PREFIX}_project_options` and `${PREFIX}_project_warnings` targets when the function is used in a multi-project fashion. -- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: - - `awesome-sidebar` (default) - - `awesome` - - `original` - - Alternatively you can supply a list of css files to be added to [DOXYGEN_HTML_EXTRA_STYLESHEET](https://www.doxygen.nl/manual/config.html#cfg_html_extra_stylesheet) -- `LINKER`: choose a specific linker (e.g. lld, gold, bfd). If set to OFF (default), the linker is automatically chosen. -- `PCH_HEADERS`: the list of the headers to precompile -- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings -- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings -- `GCC_WARNINGS`: Override the defaults for the GCC warnings -- `CUDA_WARNINGS`: Override the defaults for the CUDA warnings -- `CPPCHECK_OPTIONS`: Override the defaults for the options passed to cppcheck -- `VS_ANALYSIS_RULESET`: Override the defaults for the code analysis rule set in Visual Studio. -- `CONAN_OPTIONS`: Extra Conan options - -## `run_vcpkg` function - -```cmake -run_vcpkg() -``` - -Or by specifying the options - -```cmake -run_vcpkg( - VCPKG_URL "https://github.com/microsoft/vcpkg.git" - VCPKG_REV "33c8f025390f8682811629b6830d2d66ecedcaa5" - ENABLE_VCPKG_UPDATE -) -``` - -Named Option: - -- `ENABLE_VCPKG_UPDATE`: (Disabled by default). If enabled, the vcpkg registry is updated before building (using `git pull`). - - If `VCPKG_REV` is set to a specific commit sha, no rebuilds are triggered. - If `VCPKG_REV` is not specified or is a branch, enabling `ENABLE_VCPKG_UPDATE` will rebuild your updated vcpkg dependencies. - -Named String: - -- `VCPKG_DIR`: (Defaults to `~/vcpkg`). You can provide the vcpkg installation directory using this optional parameter. - If the directory does not exist, it will automatically install vcpkg in this directory. - -- `VCPKG_URL`: (Defaults to `https://github.com/microsoft/vcpkg.git`). This option allows setting the URL of the vcpkg repository. By default, the official vcpkg repository is used. - -- `VCPKG_REV`: This option allows checking out a specific branch name or a commit sha. -If `VCPKG_REV` is set to a specific commit sha, the builds will become reproducible because that exact commit is always used for the builds. To make sure that this commit sha is pulled, enable `ENABLE_VCPKG_UPDATE` - -## `target_link_system_libraries` function - -A function that accepts the same arguments as `target_link_libraries`. It has the following features: - -- The include directories of the library are included as `SYSTEM` to suppress their warnings. This helps in enabling `WARNINGS_AS_ERRORS` for your own source code. -- For installation of the package, the includes are considered to be at `${CMAKE_INSTALL_INCLUDEDIR}`. - -## `target_include_system_directories` function - -A function that accepts the same arguments as `target_include_directories`. It has the above mentioned features of `target_link_system_libraries` - -## `target_link_cuda` function - -A function that links Cuda to the given target. - -```cmake -add_executable(main_cuda main.cu) -target_compile_features(main_cuda PRIVATE cxx_std_17) -target_link_libraries(main_cuda PRIVATE project_options project_warnings) -target_link_cuda(main_cuda) -``` - -## `package_project` function - -A function that packages the project for external usage (e.g. from vcpkg, Conan, etc). - -The following arguments specify the package: - -- `TARGETS`: the targets you want to package. It is recursively found for the current folder if not specified - -- `INTERFACE_INCLUDES` or `PUBLIC_INCLUDES`: a list of interface/public include directories or files. - - NOTE: The given include directories are directly installed to the install destination. To have an `include` folder in the install destination with the content of your include directory, name your directory `include`. - -- `INTERFACE_DEPENDENCIES_CONFIGURED` or `PUBLIC_DEPENDENCIES_CONFIGURED`: the names of the interface/public dependencies that are found using `CONFIG`. - -- `INTERFACE_DEPENDENCIES` or `PUBLIC_DEPENDENCIES`: the interface/public dependencies that will be found by any means using `find_dependency`. The arguments must be specified within quotes (e.g.`" 1.0.0 EXACT"` or `" CONFIG"`). - -- `PRIVATE_DEPENDENCIES_CONFIGURED`: the names of the PRIVATE dependencies found using `CONFIG`. Only included when `BUILD_SHARED_LIBS` is `OFF`. - -- `PRIVATE_DEPENDENCIES`: the PRIVATE dependencies found by any means using `find_dependency`. Only included when `BUILD_SHARED_LIBS` is `OFF` - -Other arguments that are automatically found and manually specifying them is not recommended: - -- `NAME`: the name of the package. Defaults to `${PROJECT_NAME}`. - -- `VERSION`: the version of the package. Defaults to `${PROJECT_VERSION}`. - -- `COMPATIBILITY`: the compatibility version of the package. Defaults to `SameMajorVersion`. - -- `CONFIG_EXPORT_DESTINATION`: the destination for exporting the configuration files. Defaults to `${CMAKE_BINARY_DIR}/${NAME}` - -- `CONFIG_INSTALL_DESTINATION`: the destination for installation of the configuration files. Defaults to `${CMAKE_INSTALL_DATADIR}/${NAME}` - -## Disabling static analysis for external targets - -This function disables static analysis for the given target: - -```cmake -target_disable_static_analysis(some_external_target) -``` - -There is also individual functions to disable a specific analysis for the target: - -- `target_disable_cpp_check(target)` -- `target_disable_vs_analysis(target)` -- `target_disable_clang_tidy(target)` - -## Changing the project_options dynamically - -During the test and development, it can be useful to change options on the fly. For example, to enable sanitizers when running tests. You can include `DynamicOptions.cmake`, which imports the `dynamic_project_options` function. - -`dynamic_project_options` provides a recommended set of defaults (all static analysis and runtime analysis enabled for platforms where that is possible) while also providing a high-level option `ENABLE_DEVELOPER_MODE` (defaulted to `ON`) which can be turned off for easy use by non-developers. - -The goal of the `dynamic_project_options` is to give a safe and well-analyzed environment to the developer by default while simultaneously making it easy for a user of the project to compile while not having to worry about clang-tidy, sanitizers, cppcheck, etc. - -The defaults presented to the user can be modified with - -- `set(_DEFAULT value)` - for user and developer builds -- `set(_USER_DEFAULT value)` - for user builds -- `set(_DEVELOPER_DEFAULT value)` - for developer builds - -If you need to fix a setting for the sake of a command-line configuration, you can use: - -```shell -cmake -DOPT_:BOOL=value -``` - -See `dynamic_project_options()` in action in [this template repository](https://github.com/aminya/cpp_boilerplate_project). - -
- 👉 Click to show the example: - -```cmake -cmake_minimum_required(VERSION 3.20) - -# set a default CXX standard for the tools and targets that do not specify them. -# If commented, the latest supported standard for your compiler is automatically set. -# set(CMAKE_CXX_STANDARD 20) - -# Add project_options v0.26.3 -# https://github.com/aminya/project_options -# Change the version in the following URL to update the package (watch the releases of the repository for future updates) -include(FetchContent) -FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) -FetchContent_MakeAvailable(_project_options) -include(${_project_options_SOURCE_DIR}/Index.cmake) - - # ❗ Add dynamic CMake options -include(${_project_options_SOURCE_DIR}/src/DynamicOptions.cmake) - -# install vcpkg dependencies: - should be called before defining project() -# run_vcpkg() - -# Set the project name and language -project(myproject LANGUAGES CXX C) - -# Set PCH to be on by default for all non-Developer Mode Builds -set(ENABLE_PCH_USER_DEFAULT ON) - -# enable Conan -set(ENABLE_CONAN_DEFAULT ON) - -# Initialize project_options variable related to this project -# This overwrites `project_options` and sets `project_warnings` -# This also accepts the same arguments as `project_options`. -dynamic_project_options( - # set the common headers you want to precompile - PCH_HEADERS -) -``` - -Add your executables, etc., as described above. - -
# License diff --git a/docs/src/dynamic_project_oprions.md b/docs/src/dynamic_project_oprions.md new file mode 100644 index 00000000..108816d7 --- /dev/null +++ b/docs/src/dynamic_project_oprions.md @@ -0,0 +1,67 @@ +# `dynamic_project_options` function + +During the test and development, it can be useful to change options on the fly. For example, to enable sanitizers when running tests. You can include `DynamicOptions.cmake`, which imports the `dynamic_project_options` function. + +`dynamic_project_options` provides a dynamic set of defaults (all static analysis and runtime analysis enabled for platforms where that is possible) while also providing a high-level option `ENABLE_DEVELOPER_MODE` (defaulted to `ON`) which can be turned off for easy use by non-developers. + +The goal of the `dynamic_project_options` is to give a safe and well-analyzed environment to the developer by default while simultaneously making it easy for a user of the project to compile while not having to worry about clang-tidy, sanitizers, cppcheck, etc. + +The defaults presented to the user can be modified with + +- `set(_DEFAULT value)` - for user and developer builds +- `set(_USER_DEFAULT value)` - for user builds +- `set(_DEVELOPER_DEFAULT value)` - for developer builds + +If you need to fix a setting for the sake of a command-line configuration, you can use: + +```shell +cmake -DOPT_:BOOL=value +``` + +See `dynamic_project_options()` in action in [this template repository](https://github.com/aminya/cpp_boilerplate_project). + +
+ 👉 Click to show the example: + +```cmake +cmake_minimum_required(VERSION 3.20) + +# set a default CXX standard for the tools and targets that do not specify them. +# If commented, the latest supported standard for your compiler is automatically set. +# set(CMAKE_CXX_STANDARD 20) + +# Add project_options v0.26.3 +# https://github.com/aminya/project_options +# Change the version in the following URL to update the package (watch the releases of the repository for future updates) +include(FetchContent) +FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) +FetchContent_MakeAvailable(_project_options) +include(${_project_options_SOURCE_DIR}/Index.cmake) + + # ❗ Add dynamic CMake options +include(${_project_options_SOURCE_DIR}/src/DynamicOptions.cmake) + +# install vcpkg dependencies: - should be called before defining project() +# run_vcpkg() + +# Set the project name and language +project(myproject LANGUAGES CXX C) + +# Set PCH to be on by default for all non-Developer Mode Builds +set(ENABLE_PCH_USER_DEFAULT ON) + +# enable Conan +set(ENABLE_CONAN_DEFAULT ON) + +# Initialize project_options variable related to this project +# This overwrites `project_options` and sets `project_warnings` +# This also accepts the same arguments as `project_options`. +dynamic_project_options( + # set the common headers you want to precompile + PCH_HEADERS +) +``` + +Add your executables, etc., as described above. + +
diff --git a/docs/src/index.rst b/docs/src/index.rst index efe615be..de1ca11a 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -1,8 +1,14 @@ .. cmake-manual-description: CMake Modules Reference -Macros and Function +Functions ************* -Below you find a list of macros and functions included in this project. +Here is a list of functions included in this project: .. cmake-module:: ../../src/Index.cmake +.. cmake-module:: ../../src/Vcpkg.cmake +.. cmake-module:: ../../src/PackageProject.cmake +.. cmake-module:: ../../src/SystemLink.cmake +.. cmake-module:: ../../src/StaticAnalyzers.cmake +.. cmake-module:: ../../src/Cuda.cmake +.. cmake-module:: ../../src/DynamicProjectOptions.cmake diff --git a/docs/src/package_project.md b/docs/src/package_project.md new file mode 100644 index 00000000..7b6ba01e --- /dev/null +++ b/docs/src/package_project.md @@ -0,0 +1,31 @@ +# `package_project` function + +A function that packages the project for external usage (e.g. from vcpkg, Conan, etc). + +The following arguments specify the package: + +- `TARGETS`: the targets you want to package. It is recursively found for the current folder if not specified + +- `INTERFACE_INCLUDES` or `PUBLIC_INCLUDES`: a list of interface/public include directories or files. + + NOTE: The given include directories are directly installed to the install destination. To have an `include` folder in the install destination with the content of your include directory, name your directory `include`. + +- `INTERFACE_DEPENDENCIES_CONFIGURED` or `PUBLIC_DEPENDENCIES_CONFIGURED`: the names of the interface/public dependencies that are found using `CONFIG`. + +- `INTERFACE_DEPENDENCIES` or `PUBLIC_DEPENDENCIES`: the interface/public dependencies that will be found by any means using `find_dependency`. The arguments must be specified within quotes (e.g.`" 1.0.0 EXACT"` or `" CONFIG"`). + +- `PRIVATE_DEPENDENCIES_CONFIGURED`: the names of the PRIVATE dependencies found using `CONFIG`. Only included when `BUILD_SHARED_LIBS` is `OFF`. + +- `PRIVATE_DEPENDENCIES`: the PRIVATE dependencies found by any means using `find_dependency`. Only included when `BUILD_SHARED_LIBS` is `OFF` + +Other arguments that are automatically found and manually specifying them is not recommended: + +- `NAME`: the name of the package. Defaults to `${PROJECT_NAME}`. + +- `VERSION`: the version of the package. Defaults to `${PROJECT_VERSION}`. + +- `COMPATIBILITY`: the compatibility version of the package. Defaults to `SameMajorVersion`. + +- `CONFIG_EXPORT_DESTINATION`: the destination for exporting the configuration files. Defaults to `${CMAKE_BINARY_DIR}/${NAME}` + +- `CONFIG_INSTALL_DESTINATION`: the destination for installation of the configuration files. Defaults to `${CMAKE_INSTALL_DATADIR}/${NAME}` diff --git a/docs/src/project_options.md b/docs/src/project_options.md new file mode 100644 index 00000000..7a8d2bc5 --- /dev/null +++ b/docs/src/project_options.md @@ -0,0 +1,41 @@ +# `project_options` function + +It accepts the following named flags: + +- `ENABLE_CACHE`: Enable cache if available +- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck +- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy +- `ENABLE_VS_ANALYSIS`: Enable Visual Studio IDE code analysis if the generator is Visual Studio. +- `ENABLE_CONAN`: Use Conan for dependency management +- `ENABLE_INTERPROCEDURAL_OPTIMIZATION`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build +- `ENABLE_NATIVE_OPTIMIZATION`: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). +- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang +- `ENABLE_DOXYGEN`: Enable Doxygen documentation. The added `doxygen-docs` target can be built via `cmake --build ./build --target doxygen-docs`. +- `WARNINGS_AS_ERRORS`: Treat compiler and static code analyzer warnings as errors. This also affects CMake warnings related to those. +- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer +- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer +- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer +- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer +- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer +- `ENABLE_PCH`: Enable Precompiled Headers +- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use +- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang +- `ENABLE_UNITY`: Enable Unity builds of projects + +It gets the following named parameters that can have different values in front of them: + +- `PREFIX`: the optional prefix that is used to define `${PREFIX}_project_options` and `${PREFIX}_project_warnings` targets when the function is used in a multi-project fashion. +- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: + - `awesome-sidebar` (default) + - `awesome` + - `original` + - Alternatively you can supply a list of css files to be added to [DOXYGEN_HTML_EXTRA_STYLESHEET](https://www.doxygen.nl/manual/config.html#cfg_html_extra_stylesheet) +- `LINKER`: choose a specific linker (e.g. lld, gold, bfd). If set to OFF (default), the linker is automatically chosen. +- `PCH_HEADERS`: the list of the headers to precompile +- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings +- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings +- `GCC_WARNINGS`: Override the defaults for the GCC warnings +- `CUDA_WARNINGS`: Override the defaults for the CUDA warnings +- `CPPCHECK_OPTIONS`: Override the defaults for the options passed to cppcheck +- `VS_ANALYSIS_RULESET`: Override the defaults for the code analysis rule set in Visual Studio. +- `CONAN_OPTIONS`: Extra Conan options diff --git a/docs/src/run_vcpkg.md b/docs/src/run_vcpkg.md new file mode 100644 index 00000000..74bad991 --- /dev/null +++ b/docs/src/run_vcpkg.md @@ -0,0 +1,36 @@ +# `run_vcpkg` function + +Install vcpkg and vcpkg dependencies: + +```cmake +run_vcpkg() +``` + +Or by specifying the options + +```cmake +run_vcpkg( + VCPKG_URL "https://github.com/microsoft/vcpkg.git" + VCPKG_REV "33c8f025390f8682811629b6830d2d66ecedcaa5" + ENABLE_VCPKG_UPDATE +) +``` + +Note that it should be called before defining `project()`. + +Named Option: + +- `ENABLE_VCPKG_UPDATE`: (Disabled by default). If enabled, the vcpkg registry is updated before building (using `git pull`). + + If `VCPKG_REV` is set to a specific commit sha, no rebuilds are triggered. + If `VCPKG_REV` is not specified or is a branch, enabling `ENABLE_VCPKG_UPDATE` will rebuild your updated vcpkg dependencies. + +Named String: + +- `VCPKG_DIR`: (Defaults to `~/vcpkg`). You can provide the vcpkg installation directory using this optional parameter. + If the directory does not exist, it will automatically install vcpkg in this directory. + +- `VCPKG_URL`: (Defaults to `https://github.com/microsoft/vcpkg.git`). This option allows setting the URL of the vcpkg repository. By default, the official vcpkg repository is used. + +- `VCPKG_REV`: This option allows checking out a specific branch name or a commit sha. +If `VCPKG_REV` is set to a specific commit sha, the builds will become reproducible because that exact commit is always used for the builds. To make sure that this commit sha is pulled, enable `ENABLE_VCPKG_UPDATE` diff --git a/docs/src/target_disable_static_analysis.md b/docs/src/target_disable_static_analysis.md new file mode 100644 index 00000000..a69d1702 --- /dev/null +++ b/docs/src/target_disable_static_analysis.md @@ -0,0 +1,13 @@ +# `target_disable_static_analysis` function + +This function disables static analysis for the given target: + +```cmake +target_disable_static_analysis(some_external_target) +``` + +There is also individual functions to disable a specific analysis for the target: + +- `target_disable_cpp_check(target)` +- `target_disable_vs_analysis(target)` +- `target_disable_clang_tidy(target)` diff --git a/docs/src/target_include_system_directories.md b/docs/src/target_include_system_directories.md new file mode 100644 index 00000000..91e51857 --- /dev/null +++ b/docs/src/target_include_system_directories.md @@ -0,0 +1,5 @@ +# `target_include_system_directories` function + +Include a system directory (which suppresses its warnings). + +The function accepts the same arguments as `target_include_directories`. It has the mentioned features of `target_link_system_libraries`. diff --git a/docs/src/target_link_cuda.md b/docs/src/target_link_cuda.md new file mode 100644 index 00000000..faa2f761 --- /dev/null +++ b/docs/src/target_link_cuda.md @@ -0,0 +1,10 @@ +# `target_link_cuda` function + +Link Cuda to the given target. + +```cmake +add_executable(main_cuda main.cu) +target_compile_features(main_cuda PRIVATE cxx_std_17) +target_link_libraries(main_cuda PRIVATE project_options project_warnings) +target_link_cuda(main_cuda) +``` diff --git a/docs/src/target_link_system_libraries.md b/docs/src/target_link_system_libraries.md new file mode 100644 index 00000000..88bc08ba --- /dev/null +++ b/docs/src/target_link_system_libraries.md @@ -0,0 +1,8 @@ +# `target_link_system_libraries` function + +Link multiple library targets as system libraries (which suppresses their warnings). + +The function accepts the same arguments as `target_link_libraries`. It has the following features: + +- The include directories of the library are included as `SYSTEM` to suppress their warnings. This helps in enabling `WARNINGS_AS_ERRORS` for your own source code. +- For installation of the package, the includes are considered to be at `${CMAKE_INSTALL_INCLUDEDIR}`. diff --git a/src/Cuda.cmake b/src/Cuda.cmake index 1fc16073..178ed13b 100644 --- a/src/Cuda.cmake +++ b/src/Cuda.cmake @@ -1,14 +1,11 @@ include_guard() -# ! target_link_cuda -# A function that links Cuda to the given target -# -# # Example -# add_executable(main_cuda main.cu) -# target_compile_features(main_cuda PRIVATE cxx_std_17) -# target_link_libraries(main_cuda PRIVATE project_options project_warnings) -# target_link_cuda(main_cuda) -# +#[[.rst: + +.. include:: ../../docs/src/target_link_cuda.md + :parser: myst_parser.sphinx_ + +#]] macro(target_link_cuda target) # optional named CUDA_WARNINGS set(oneValueArgs CUDA_WARNINGS) diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 8e5f4386..49e8276e 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -1,26 +1,11 @@ include_guard() -# ENABLE_DEVELOPER_MODE: sets defaults appropriate for developers, this is defaulted to ON -# * WARNINGS_AS_ERRORS: ON -# * ENABLE_SANITIZER_ADDRESS: ON -# * ENABLE_CLANG_TIDY: ON for Ninja/Makefiles -# * ENABLE_SANITIZER_UNDEFINED: ON for Compilers that support it -# * ENABLE_CPPCHECK: ON for Ninja/Makefiles -# -# For non-developer builds -# -DENABLE_DEVELOPER_MODE:BOOL=OFF -# Is recommended -# -# In developer mode, all features have options that show up in the CMake GUI tools -# -# dynamic_project_options() macro enables all recommended defaults with appropriately -# applied options from the GUI which are set -# -# Any default can be overridden -# set(_DEFAULT ) - set default for both user and developer modes -# set(_DEVELOPER_DEFAULT ) - set default for developer mode -# set(_USER_DEFAULT ) - set default for user mode -# +#[[.rst: + +.. include:: ../../docs/src/dynamic_project_options.md + :parser: myst_parser.sphinx_ + +#]] macro(dynamic_project_options) option(ENABLE_DEVELOPER_MODE "Set up defaults for a developer of the project, and let developer change options" OFF) if(NOT ${ENABLE_DEVELOPER_MODE}) diff --git a/src/Index.cmake b/src/Index.cmake index 4061a5fe..13dfee44 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -1,10 +1,3 @@ -#[=======================================================================[.rst: - -.. include:: ../../README.md - :parser: myst_parser.sphinx_ - -#]=======================================================================] - cmake_minimum_required(VERSION 3.20) # 3.20 is required by the windows toolchain and cmake_path. It also has a more reliable building functionality. # 3.18 required by package_project and interprocedural optimization. It also has a more reliable building functionality (no errors during the linking stage). @@ -44,37 +37,13 @@ msvc_toolchain() include("${CMAKE_CURRENT_LIST_DIR}/Conan.cmake") include("${CMAKE_CURRENT_LIST_DIR}/Vcpkg.cmake") -# -# Params: -# - PREFIX: the optional prefix to be prepended to the `project_options` and `project_warnings` targets when the function is used in a multi-project fashion. -# - WARNINGS_AS_ERRORS: Treat compiler warnings as errors -# - ENABLE_CPPCHECK: Enable static analysis with cppcheck -# - ENABLE_CLANG_TIDY: Enable static analysis with clang-tidy -# - ENABLE_INCLUDE_WHAT_YOU_USE: Enable static analysis with include-what-you-use -# - ENABLE_COVERAGE: Enable coverage reporting for gcc/clang -# - ENABLE_CACHE: Enable cache if available -# - ENABLE_PCH: Enable Precompiled Headers -# - PCH_HEADERS: the list of the headers to precompile -# - ENABLE_CONAN: Use Conan for dependency management -# - ENABLE_DOXYGEN: Enable doxygen doc builds of source -# - DOXYGEN_THEME: the name of the Doxygen theme to use. Supported themes: `awesome-sidebar` (default), `awesome` and `original`. -# - ENABLE_INTERPROCEDURAL_OPTIMIZATION: Enable Interprocedural Optimization, aka Link Time Optimization (LTO) -# - ENABLE_NATIVE_OPTIMIZATION: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). -# - ENABLE_BUILD_WITH_TIME_TRACE: Enable -ftime-trace to generate time tracing .json files on clang -# - ENABLE_UNITY: Enable Unity builds of projects -# - ENABLE_SANITIZER_ADDRESS: Enable address sanitizer -# - ENABLE_SANITIZER_LEAK: Enable leak sanitizer -# - ENABLE_SANITIZER_UNDEFINED_BEHAVIOR: Enable undefined behavior sanitizer -# - ENABLE_SANITIZER_THREAD: Enable thread sanitizer -# - ENABLE_SANITIZER_MEMORY: Enable memory sanitizer -# - LINKER: choose a specific linker (e.g. lld, gold, bfd). If set to OFF (default), the linker is automatically chosen. -# - MSVC_WARNINGS: Override the defaults for the MSVC warnings -# - CLANG_WARNINGS: Override the defaults for the CLANG warnings -# - GCC_WARNINGS: Override the defaults for the GCC warnings -# - CUDA_WARNINGS: Override the defaults for the CUDA warnings -# - CPPCHECK_OPTIONS: Override the defaults for CppCheck settings -# - CONAN_OPTIONS: Extra Conan options -# + +#[[.rst: + +.. include:: ../../docs/src/project_options.md + :parser: myst_parser.sphinx_ + +#]] # NOTE: cmake-lint [C0103] Invalid macro name "project_options" doesn't match `[0-9A-Z_]+` macro(project_options) set(options diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 68a0d76b..d566dda5 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -2,8 +2,12 @@ include_guard() # Uses ycm (permissive BSD-3-Clause license) and ForwardArguments (permissive MIT license) -# A function that packages the project for external usage (e.g. from vcpkg, Conan, etc). -# See the [README.md] for more details +#[[.rst: + +.. include:: ../../docs/src/package_project.md + :parser: myst_parser.sphinx_ + +#]] function(package_project) # default to false set(_options ARCH_INDEPENDENT) diff --git a/src/StaticAnalyzers.cmake b/src/StaticAnalyzers.cmake index f1703467..bf224d25 100644 --- a/src/StaticAnalyzers.cmake +++ b/src/StaticAnalyzers.cmake @@ -191,7 +191,12 @@ macro(target_disable_vs_analysis TARGET) endif() endmacro() -# Disable static analysis for target +#[[.rst: + +.. include:: ../../docs/src/target_disable_static_analysis.md + :parser: myst_parser.sphinx_ + +#]] macro(target_disable_static_analysis TARGET) if(NOT CMAKE_GENERATOR diff --git a/src/SystemLink.cmake b/src/SystemLink.cmake index 62227f0d..bdb4b920 100644 --- a/src/SystemLink.cmake +++ b/src/SystemLink.cmake @@ -1,6 +1,12 @@ include_guard() -# Include a system directory (which suppresses its warnings). +# +#[[.rst: + +.. include:: ../../docs/src/target_include_system_directories.md + :parser: myst_parser.sphinx_ + +#]] function(target_include_system_directories target) set(multiValueArgs INTERFACE PUBLIC PRIVATE) cmake_parse_arguments( @@ -66,7 +72,12 @@ function( target_link_libraries(${target} ${scope} ${lib}) endfunction() -# Link multiple library targets as system libraries (which suppresses their warnings). +#[[.rst: + +.. include:: ../../docs/src/target_link_system_libraries.md + :parser: myst_parser.sphinx_ + +#]] function(target_link_system_libraries target) set(multiValueArgs INTERFACE PUBLIC PRIVATE) cmake_parse_arguments( diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index f73abe48..164d7888 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -2,7 +2,12 @@ include_guard() include(FetchContent) -# Install vcpkg and vcpkg dependencies: - should be called before defining project() +#[[.rst: + +.. include:: ../../docs/src/run_vcpkg.md + :parser: myst_parser.sphinx_ + +#]] macro(run_vcpkg) # named boolean ENABLE_VCPKG_UPDATE arguments set(options ENABLE_VCPKG_UPDATE) @@ -132,7 +137,7 @@ macro(run_vcpkg) else() get_toolchain_file(_toolchain_file) endif() - + if(NOT "${_toolchain_file}" STREQUAL "") set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${_toolchain_file} From afb3a3464a4de0dd85a1d479c2e578d8186e0d7e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 20:19:51 -0800 Subject: [PATCH 058/139] docs: move the examples to the project_options file --- README.md | 191 +---------------------------------- docs/src/index.rst | 2 - docs/src/project_options.md | 194 +++++++++++++++++++++++++++++++++++- 3 files changed, 197 insertions(+), 190 deletions(-) diff --git a/README.md b/README.md index 62d1b965..042e7e27 100644 --- a/README.md +++ b/README.md @@ -29,193 +29,10 @@ A general-purpose CMake library that provides functions that improve the CMake e See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. -Here is a full example: +## Documentation -```cmake -cmake_minimum_required(VERSION 3.20) +See the [docs](./docs) folder. -# set a default CXX standard for the tools and targets that do not specify them. -# If commented, the latest supported standard for your compiler is automatically set. -# set(CMAKE_CXX_STANDARD 20) +## License -# Add project_options v0.26.3 -# https://github.com/aminya/project_options -# Change the version in the following URL to update the package (watch the releases of the repository for future updates) -include(FetchContent) -FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) -FetchContent_MakeAvailable(_project_options) -include(${_project_options_SOURCE_DIR}/Index.cmake) - -# install vcpkg dependencies: - should be called before defining project() -run_vcpkg() - -# Set the project name and language -project(myproject LANGUAGES CXX C) - -# Build Features -option(FEATURE_TESTS "Enable the tests" OFF) -if(FEATURE_TESTS) - list(APPEND VCPKG_MANIFEST_FEATURES "tests") -endif() - -option(FEATURE_DOCS "Enable the docs" OFF) - -# Enable sanitizers and static analyzers when running the tests -set(ENABLE_CLANG_TIDY OFF) -set(ENABLE_CPPCHECK OFF) -set(ENABLE_SANITIZER_ADDRESS OFF) -set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) -set(ENABLE_COVERAGE OFF) - -if(FEATURE_TESTS) - set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") - set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") - set(ENABLE_COVERAGE "ENABLE_COVERAGE") - - if(NOT - "${CMAKE_SYSTEM_NAME}" - STREQUAL - "Windows") - set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") - set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") - else() - # or it is MSVC and has run vcvarsall - string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) - if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") - set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") - endif() - endif() -endif() - -if(FEATURE_DOCS) - set(ENABLE_DOXYGEN "ENABLE_DOXYGEN") -else() - set(ENABLE_DOXYGEN OFF) -endif() - -# Initialize project_options variable related to this project -# This overwrites `project_options` and sets `project_warnings` -# uncomment to enable the options. Some of them accept one or more inputs: -project_options( - ENABLE_CACHE - ${ENABLE_CPPCHECK} - ${ENABLE_CLANG_TIDY} - ENABLE_VS_ANALYSIS - # ENABLE_CONAN - # ENABLE_INTERPROCEDURAL_OPTIMIZATION - # ENABLE_NATIVE_OPTIMIZATION - ${ENABLE_DOXYGEN} - ${ENABLE_COVERAGE} - ${ENABLE_SANITIZER_ADDRESS} - ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} - # ENABLE_SANITIZER_THREAD - # ENABLE_SANITIZER_MEMORY - # ENABLE_PCH - # PCH_HEADERS - # WARNINGS_AS_ERRORS - # ENABLE_INCLUDE_WHAT_YOU_USE - # ENABLE_BUILD_WITH_TIME_TRACE - # ENABLE_UNITY - # LINKER "lld" - # CONAN_PROFILE ${profile_path} # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html -) -``` - -Then add the executables or libraries to the project: - -[An executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe): - -```cmake -add_executable(main main.cpp) -target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings - -# Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() - -# Link dependencies -target_link_system_libraries( - main - PRIVATE - fmt::fmt - Eigen3::Eigen -) - -# Package the project -package_project(TARGETS main) -``` - -[A header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib): - -```cmake -add_library(my_header_lib INTERFACE) -target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings - -# Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_header_lib INTERFACE "$" - "$") - -# Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() - -# Link dependencies: -target_link_system_libraries( - my_header_lib - INTERFACE - fmt::fmt - Eigen3::Eigen -) - -# Package the project -package_project( - TARGETS my_header_lib project_options project_warnings - INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} - INTERFACE_INCLUDES ${INCLUDE_DIR} -) -``` - -[A library with separate header and source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) - -```cmake -add_library(my_lib "./src/my_lib/lib.cpp") -target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings - -# Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_lib PUBLIC "$" - "$") - -# Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() - -# Link dependencies: -target_link_system_libraries( - my_lib - PRIVATE - fmt::fmt - Eigen3::Eigen -) - -# Package the project -package_project( - TARGETS my_lib - PUBLIC_INCLUDES ${INCLUDE_DIR} -) -``` - - -# License - -This project can be used under the terms of either the [MIT license](./LICENSE.txt) or the [Unlicense](./Unlicense.txt) depending on your choice (as you wish). Both are permissive open-source licenses that allow any usage, commercial or non-commercial, copying, distribution, publishing, modification, etc. Feel free to choose whichever is more suitable for you. +This project can be used under the terms of either the [MIT license](./LICENSE.txt) or the [Unlicense](./Unlicense.txt) depending on your choice (as you wish). diff --git a/docs/src/index.rst b/docs/src/index.rst index de1ca11a..ffdfc840 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -3,8 +3,6 @@ Functions ************* -Here is a list of functions included in this project: - .. cmake-module:: ../../src/Index.cmake .. cmake-module:: ../../src/Vcpkg.cmake .. cmake-module:: ../../src/PackageProject.cmake diff --git a/docs/src/project_options.md b/docs/src/project_options.md index 7a8d2bc5..1d084b2d 100644 --- a/docs/src/project_options.md +++ b/docs/src/project_options.md @@ -1,6 +1,198 @@ # `project_options` function -It accepts the following named flags: +## Example + +See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. + +Here is a full example: + +```cmake +cmake_minimum_required(VERSION 3.20) + +# set a default CXX standard for the tools and targets that do not specify them. +# If commented, the latest supported standard for your compiler is automatically set. +# set(CMAKE_CXX_STANDARD 20) + +# Add project_options v0.26.3 +# https://github.com/aminya/project_options +# Change the version in the following URL to update the package (watch the releases of the repository for future updates) +include(FetchContent) +FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) +FetchContent_MakeAvailable(_project_options) +include(${_project_options_SOURCE_DIR}/Index.cmake) + +# install vcpkg dependencies: - should be called before defining project() +run_vcpkg() + +# Set the project name and language +project(myproject LANGUAGES CXX C) + +# Build Features +option(FEATURE_TESTS "Enable the tests" OFF) +if(FEATURE_TESTS) + list(APPEND VCPKG_MANIFEST_FEATURES "tests") +endif() + +option(FEATURE_DOCS "Enable the docs" OFF) + +# Enable sanitizers and static analyzers when running the tests +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) + +if(FEATURE_TESTS) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() +endif() + +if(FEATURE_DOCS) + set(ENABLE_DOXYGEN "ENABLE_DOXYGEN") +else() + set(ENABLE_DOXYGEN OFF) +endif() + +# Initialize project_options variable related to this project +# This overwrites `project_options` and sets `project_warnings` +# uncomment to enable the options. Some of them accept one or more inputs: +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ENABLE_VS_ANALYSIS + # ENABLE_CONAN + # ENABLE_INTERPROCEDURAL_OPTIMIZATION + # ENABLE_NATIVE_OPTIMIZATION + ${ENABLE_DOXYGEN} + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + # ENABLE_SANITIZER_THREAD + # ENABLE_SANITIZER_MEMORY + # ENABLE_PCH + # PCH_HEADERS + # WARNINGS_AS_ERRORS + # ENABLE_INCLUDE_WHAT_YOU_USE + # ENABLE_BUILD_WITH_TIME_TRACE + # ENABLE_UNITY + # LINKER "lld" + # CONAN_PROFILE ${profile_path} # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html +) +``` + +Then add the executables or libraries to the project: + +[An executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe): + +```cmake +add_executable(main main.cpp) +target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies +target_link_system_libraries( + main + PRIVATE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project(TARGETS main) +``` + +[A header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib): + +```cmake +add_library(my_header_lib INTERFACE) +target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings + +# Includes +set(INCLUDE_DIR "include") # must be relative paths +target_include_directories(my_header_lib INTERFACE "$" + "$") + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies: +target_link_system_libraries( + my_header_lib + INTERFACE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project( + TARGETS my_header_lib project_options project_warnings + INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} + INTERFACE_INCLUDES ${INCLUDE_DIR} +) +``` + +[A library with separate header and source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) + +```cmake +add_library(my_lib "./src/my_lib/lib.cpp") +target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings + +# Includes +set(INCLUDE_DIR "include") # must be relative paths +target_include_directories(my_lib PUBLIC "$" + "$") + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies: +target_link_system_libraries( + my_lib + PRIVATE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project( + TARGETS my_lib + PUBLIC_INCLUDES ${INCLUDE_DIR} +) +``` + +## API + +`project_options` function accepts the following named flags: - `ENABLE_CACHE`: Enable cache if available - `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck From db1d46d9815e3a74d7b4b760baab44f1ab5e8058 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 20:26:16 -0800 Subject: [PATCH 059/139] docs: generate docs on tags --- .github/workflows/docs.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..c3dceab8 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,39 @@ +name: docs +on: + push: + tags: + - "*" + +jobs: + Test: + if: "!contains(github.event.head_commit.message, '[ci skip]')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: true + + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + cmake: true + ninja: true + task: true + doxygen: true + + - name: Build Documentation + run: task docs + + - name: Deploy Documentation + uses: Cecilapp/GitHub-Pages-deploy@v3 + with: + build_dir: docs/build/html/ + branch: gh-pages + email: aminyahyaabadi74@gmail.com + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From bdb30f6213a549103e45aa7616b7beea11238f5b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 20:37:07 -0800 Subject: [PATCH 060/139] docs: trigger doc generation [skip ci] --- .github/workflows/ci.cross.arm.yml | 4 ++-- .github/workflows/ci.cross.mingw.yml | 4 ++-- .github/workflows/ci.emscripten.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/docs.yml | 2 +- README.md | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.cross.arm.yml b/.github/workflows/ci.cross.arm.yml index 58e5a870..d7fdbb43 100644 --- a/.github/workflows/ci.cross.arm.yml +++ b/.github/workflows/ci.cross.arm.yml @@ -8,7 +8,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -26,7 +26,7 @@ jobs: - rpi4-vcpkg:build.cross include: - task: rpi3:build.cross - install-cross-compiler: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + install-cross-compiler: gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf target: arm-linux-gnueabi - task: rpi3:build.cross.bare-metal install-cross-compiler: gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi diff --git a/.github/workflows/ci.cross.mingw.yml b/.github/workflows/ci.cross.mingw.yml index d001371a..da48ef9e 100644 --- a/.github/workflows/ci.cross.mingw.yml +++ b/.github/workflows/ci.cross.mingw.yml @@ -8,7 +8,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -57,7 +57,7 @@ jobs: task: true doxygen: true powershell: true - + - name: Setup MinGW uses: egor-tensin/setup-mingw@v2 with: diff --git a/.github/workflows/ci.emscripten.yml b/.github/workflows/ci.emscripten.yml index bdae61a4..0b739dc9 100644 --- a/.github/workflows/ci.emscripten.yml +++ b/.github/workflows/ci.emscripten.yml @@ -8,7 +8,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -46,7 +46,7 @@ jobs: clangtidy: true task: true doxygen: true - + - name: Setup emscripten uses: mymindstorm/setup-emsdk@v11 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfd2cdbf..7af9aa86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c3dceab8..34f0454d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,7 +6,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/README.md b/README.md index 042e7e27..43033e86 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ See `project_options()` in action in [this template repository](https://github.c ## Documentation -See the [docs](./docs) folder. +See the [docs](./docs/src/project_options.md) folder. ## License From ddc32a945bec854e9cf2d074abc4f8d3f73ae92a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 20:38:39 -0800 Subject: [PATCH 061/139] ci: fix doc trigger on [skip ci] --- .github/workflows/docs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 34f0454d..070b76d3 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,7 +6,6 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ${{ matrix.os }} strategy: fail-fast: false From 69ae2370073246e0f107ad5f1d2e027089a32190 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 21:15:44 -0800 Subject: [PATCH 062/139] docs: add the docs link [skip ci] --- README.md | 10 +++++++--- docs/Taskfile.yml | 7 +++++++ package.json | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 package.json diff --git a/README.md b/README.md index 43033e86..9177867b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ A general-purpose CMake library that provides functions that improve the CMake experience following the best practices. +[![documentation](https://img.shields.io/badge/documentation-blue?style=flat&logo=docs.rs&link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/) + +[![ci](https://github.com/aminya/project_options/actions/workflows/ci.yml/badge.svg)](https://github.com/aminya/project_options/actions/workflows/ci.yml) + ## Features - `project_options`: @@ -23,15 +27,15 @@ A general-purpose CMake library that provides functions that improve the CMake e - `target_link_system_libraries` and `target_include_system_directories`: linking/including external dependencies/headers without warnings - `target_link_cuda`: linking Cuda to a target -[![ci](https://github.com/aminya/project_options/actions/workflows/ci.yml/badge.svg)](https://github.com/aminya/project_options/actions/workflows/ci.yml) - ## Usage See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. ## Documentation -See the [docs](./docs/src/project_options.md) folder. +The documentation is available [here](https://aminya.github.io/project_options/): + +[![documentation](https://img.shields.io/badge/documentation-blue?style=flat&logo=docs.rs&link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/) ## License diff --git a/docs/Taskfile.yml b/docs/Taskfile.yml index 27e360df..68eec294 100644 --- a/docs/Taskfile.yml +++ b/docs/Taskfile.yml @@ -11,3 +11,10 @@ tasks: cmds: - cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release - cmake --build ./build --config Release + - touch ./build/.nojekyll + + docs.deploy: + deps: + - docs + cmds: + - npx gh-pages -d ./build/ -t true diff --git a/package.json b/package.json new file mode 100644 index 00000000..9468670d --- /dev/null +++ b/package.json @@ -0,0 +1,4 @@ +{ + "name": "project_options", + "homepage": "http://aminya.github.io/project_options" +} From 658277b38021e587b2fcc9270d0bdb2ceb1bc388 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 22:18:46 -0800 Subject: [PATCH 063/139] docs: improve the documentation format [skip ci] --- README.md | 250 ++++++++++++++++-- docs/CMakeLists.txt | 8 +- docs/README.md | 7 + docs/Taskfile.yml | 9 +- docs/index.rst | 22 +- docs/src/License.md | 3 + docs/src/Readme_top.md | 34 +++ docs/src/dynamic_project_oprions.md | 2 +- docs/src/index.rst | 3 - docs/src/package_project.md | 2 +- docs/src/project_options.rst | 5 + docs/src/project_options_api.md | 39 +++ ..._options.md => project_options_example.md} | 54 +--- docs/src/run_vcpkg.md | 2 +- docs/src/target_disable_static_analysis.md | 2 +- docs/src/target_include_system_directories.md | 2 +- docs/src/target_link_cuda.md | 2 +- docs/src/target_link_system_libraries.md | 2 +- src/Index.cmake | 3 +- 19 files changed, 352 insertions(+), 99 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/src/License.md create mode 100644 docs/src/Readme_top.md create mode 100644 docs/src/project_options.rst create mode 100644 docs/src/project_options_api.md rename docs/src/{project_options.md => project_options_example.md} (63%) diff --git a/README.md b/README.md index 9177867b..701ec1a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # project_options -A general-purpose CMake library that provides functions that improve the CMake experience following the best practices. +A general-purpose CMake library that provides functions that improve the +CMake experience following the best practices. [![documentation](https://img.shields.io/badge/documentation-blue?style=flat&logo=docs.rs&link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/) @@ -8,35 +9,236 @@ A general-purpose CMake library that provides functions that improve the CMake e ## Features -- `project_options`: - - compiler warnings, - - compiler optimizations (intraprocedural, native), - - caching (ccache, sccache), - - sanitizers, - - static code analyzers (clang-tidy, cppcheck, visual studio, include-what-you-use), - - document generation (doxygen), - - test coverage analysis, - - precompiled headers, - - build time measurement, - - unity builds - - using custom linkers (e.g. lld) -- `package_project`: automatic packaging/installation of the project for seamless usage via find_package/target_link through CMake's FetchContent, vcpkg, etc. -- `run_vcpkg`: automatic installation of vcpkg and the project dependencies -- `ENABLE_CONAN` in `project_options`: automatic installation of Conan and the project dependencies -- `dynamic_project_options`: a wrapper around `project_options` to change the options on the fly dynamically -- `target_link_system_libraries` and `target_include_system_directories`: linking/including external dependencies/headers without warnings -- `target_link_cuda`: linking Cuda to a target +- `project_options`: + - compiler warnings, + - compiler optimizations (intraprocedural, native), + - caching (ccache, sccache), + - sanitizers, + - static code analyzers (clang-tidy, cppcheck, visual studio, + include-what-you-use), + - document generation (doxygen), + - test coverage analysis, + - precompiled headers, + - build time measurement, + - unity builds + - using custom linkers (e.g. lld) +- `package_project`: automatic packaging/installation of the project + for seamless usage via find_package/target_link through CMake's + FetchContent, vcpkg, etc. +- `run_vcpkg`: automatic installation of vcpkg and the project + dependencies +- `ENABLE_CONAN` in `project_options`: automatic installation of Conan + and the project dependencies +- `dynamic_project_options`: a wrapper around `project_options` to + change the options on the fly dynamically +- `target_link_system_libraries` and + `target_include_system_directories`: linking/including external + dependencies/headers without warnings +- `target_link_cuda`: linking Cuda to a target + +## Documentation + +The full documentation is available here: + + ## Usage -See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. +# `project_options` {#project_options} -## Documentation +See `project_options()` in action in [this template +repository](https://github.com/aminya/cpp_vcpkg_project). +[cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has +prepared all the best practices for a production-ready C++ project. -The documentation is available [here](https://aminya.github.io/project_options/): +Here is a full example. -[![documentation](https://img.shields.io/badge/documentation-blue?style=flat&logo=docs.rs&link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/) +``` cmake +cmake_minimum_required(VERSION 3.20) + +# set a default CXX standard for the tools and targets that do not specify them. +# If commented, the latest supported standard for your compiler is automatically set. +# set(CMAKE_CXX_STANDARD 20) + +# Add project_options v0.26.3 +# https://github.com/aminya/project_options +# Change the version in the following URL to update the package (watch the releases of the repository for future updates) +include(FetchContent) +FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) +FetchContent_MakeAvailable(_project_options) +include(${_project_options_SOURCE_DIR}/Index.cmake) + +# install vcpkg dependencies: - should be called before defining project() +run_vcpkg() + +# Set the project name and language +project(myproject LANGUAGES CXX C) + +# Build Features +option(FEATURE_TESTS "Enable the tests" OFF) +if(FEATURE_TESTS) + list(APPEND VCPKG_MANIFEST_FEATURES "tests") +endif() + +option(FEATURE_DOCS "Enable the docs" OFF) + +# Enable sanitizers and static analyzers when running the tests +set(ENABLE_CLANG_TIDY OFF) +set(ENABLE_CPPCHECK OFF) +set(ENABLE_SANITIZER_ADDRESS OFF) +set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF) +set(ENABLE_COVERAGE OFF) + +if(FEATURE_TESTS) + set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY") + set(ENABLE_CPPCHECK "ENABLE_CPPCHECK") + set(ENABLE_COVERAGE "ENABLE_COVERAGE") + + if(NOT + "${CMAKE_SYSTEM_NAME}" + STREQUAL + "Windows") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR") + else() + # or it is MSVC and has run vcvarsall + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if(MSVC AND "${index_of_vs_install_dir}" STREQUAL "-1") + set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS") + endif() + endif() +endif() + +if(FEATURE_DOCS) + set(ENABLE_DOXYGEN "ENABLE_DOXYGEN") +else() + set(ENABLE_DOXYGEN OFF) +endif() + +# Initialize project_options variable related to this project +# This overwrites `project_options` and sets `project_warnings` +# uncomment to enable the options. Some of them accept one or more inputs: +project_options( + ENABLE_CACHE + ${ENABLE_CPPCHECK} + ${ENABLE_CLANG_TIDY} + ENABLE_VS_ANALYSIS + # ENABLE_CONAN + # ENABLE_INTERPROCEDURAL_OPTIMIZATION + # ENABLE_NATIVE_OPTIMIZATION + ${ENABLE_DOXYGEN} + ${ENABLE_COVERAGE} + ${ENABLE_SANITIZER_ADDRESS} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + # ENABLE_SANITIZER_THREAD + # ENABLE_SANITIZER_MEMORY + # ENABLE_PCH + # PCH_HEADERS + # WARNINGS_AS_ERRORS + # ENABLE_INCLUDE_WHAT_YOU_USE + # ENABLE_BUILD_WITH_TIME_TRACE + # ENABLE_UNITY + # LINKER "lld" + # CONAN_PROFILE ${profile_path} # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html +) +``` + +Then add the executables or libraries to the project: + +#### [Executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe) + +``` cmake +add_executable(main main.cpp) +target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies +target_link_system_libraries( + main + PRIVATE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project(TARGETS main) +``` + +#### [Header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib) + +``` cmake +add_library(my_header_lib INTERFACE) +target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings + +# Includes +set(INCLUDE_DIR "include") # must be relative paths +target_include_directories(my_header_lib INTERFACE "$" + "$") + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies: +target_link_system_libraries( + my_header_lib + INTERFACE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project( + TARGETS my_header_lib project_options project_warnings + INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} + INTERFACE_INCLUDES ${INCLUDE_DIR} +) +``` + +#### [Library with source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) + +``` cmake +add_library(my_lib "./src/my_lib/lib.cpp") +target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings + +# Includes +set(INCLUDE_DIR "include") # must be relative paths +target_include_directories(my_lib PUBLIC "$" + "$") + +# Find dependencies: +set(DEPENDENCIES_CONFIGURED fmt Eigen3) + +foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) + find_package(${DEPENDENCY} CONFIG REQUIRED) +endforeach() + +# Link dependencies: +target_link_system_libraries( + my_lib + PRIVATE + fmt::fmt + Eigen3::Eigen +) + +# Package the project +package_project( + TARGETS my_lib + PUBLIC_INCLUDES ${INCLUDE_DIR} +) +``` ## License -This project can be used under the terms of either the [MIT license](./LICENSE.txt) or the [Unlicense](./Unlicense.txt) depending on your choice (as you wish). +This project can be used under the terms of either the [MIT +license](../../LICENSE.txt) or the [Unlicense](../../Unlicense.txt) +depending on your choice. diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 9590f7cf..cb69a39c 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.25) project( project_options_docs - VERSION 0.1.0 + VERSION 0.26.3 DESCRIPTION "Documentation" LANGUAGES NONE) @@ -49,9 +49,9 @@ set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}") # Location of your conf.py set(conf_out_path "${CMAKE_CURRENT_BINARY_DIR}") # Location of the output directory set(conf_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(conf_release "${PROJECT_VERSION}") -set(conf_name "CMake Spinx Documentation") -set(conf_author "Firstname Lastname") -set(conf_brief "TODO some brief description.") +set(conf_name "project_options") +set(conf_author "Amin Yahyaabadi") +set(conf_brief "A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.") set(conf_doxygen_input "\ \"${CMAKE_SOURCE_DIR}/include\" \ diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..115e10e4 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,7 @@ +!include ./src/Readme_top.md + +## Usage + +!include ./src/project_options_example.md + +!include ./src/License.md diff --git a/docs/Taskfile.yml b/docs/Taskfile.yml index 68eec294..62778fc3 100644 --- a/docs/Taskfile.yml +++ b/docs/Taskfile.yml @@ -2,16 +2,17 @@ version: 3 tasks: - docs-deps: - - pip install -U GitPython sphinx-rtd-theme breathe sphinx-sitemap sphinxcontrib-moderncmakedomain myst-parser + readme: + - pip install -U pandoc-include + - pandoc -s --filter pandoc-include -o ../README.md ./README.md docs: - deps: - - docs-deps cmds: + - pip install -U GitPython sphinx-rtd-theme breathe sphinx-sitemap sphinxcontrib-moderncmakedomain myst-parser pandoc-include - cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release - cmake --build ./build --config Release - touch ./build/.nojekyll + - task: readme docs.deploy: deps: diff --git a/docs/index.rst b/docs/index.rst index 4c436fb1..1c2da140 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,9 +1,19 @@ -project_options +Usage ====================================================== -.. include:: ../README.md +.. include:: ./src/Readme_top.md :parser: myst_parser.sphinx_ +Usage +------ + +.. include:: ./src/project_options_example.md + :parser: myst_parser.sphinx_ + +.. include:: ./src/License.md + :parser: myst_parser.sphinx_ + + Table of Contents ================== @@ -13,9 +23,9 @@ Table of Contents self src/index -Indices -================== +.. Indices +.. ================== -* :ref:`genindex` +.. * :ref:`genindex` .. * :ref:`modindex` -* :ref:`search` +.. * :ref:`search` diff --git a/docs/src/License.md b/docs/src/License.md new file mode 100644 index 00000000..4196238d --- /dev/null +++ b/docs/src/License.md @@ -0,0 +1,3 @@ +## License + +This project can be used under the terms of either the [MIT license](../../LICENSE.txt) or the [Unlicense](../../Unlicense.txt) depending on your choice. diff --git a/docs/src/Readme_top.md b/docs/src/Readme_top.md new file mode 100644 index 00000000..7c32b683 --- /dev/null +++ b/docs/src/Readme_top.md @@ -0,0 +1,34 @@ +# project_options + +A general-purpose CMake library that provides functions that improve the CMake experience following the best practices. + +[![documentation](https://img.shields.io/badge/documentation-blue?style=flat&logo=docs.rs&link=https://aminya.github.io/project_options/)](https://aminya.github.io/project_options/) + +[![ci](https://github.com/aminya/project_options/actions/workflows/ci.yml/badge.svg)](https://github.com/aminya/project_options/actions/workflows/ci.yml) + +## Features + +- `project_options`: + - compiler warnings, + - compiler optimizations (intraprocedural, native), + - caching (ccache, sccache), + - sanitizers, + - static code analyzers (clang-tidy, cppcheck, visual studio, include-what-you-use), + - document generation (doxygen), + - test coverage analysis, + - precompiled headers, + - build time measurement, + - unity builds + - using custom linkers (e.g. lld) +- `package_project`: automatic packaging/installation of the project for seamless usage via find_package/target_link through CMake's FetchContent, vcpkg, etc. +- `run_vcpkg`: automatic installation of vcpkg and the project dependencies +- `ENABLE_CONAN` in `project_options`: automatic installation of Conan and the project dependencies +- `dynamic_project_options`: a wrapper around `project_options` to change the options on the fly dynamically +- `target_link_system_libraries` and `target_include_system_directories`: linking/including external dependencies/headers without warnings +- `target_link_cuda`: linking Cuda to a target + +## Documentation + +The full documentation is available here: + +[https://aminya.github.io/project_options/](https://aminya.github.io/project_options/) diff --git a/docs/src/dynamic_project_oprions.md b/docs/src/dynamic_project_oprions.md index 108816d7..6fbb0eb2 100644 --- a/docs/src/dynamic_project_oprions.md +++ b/docs/src/dynamic_project_oprions.md @@ -1,4 +1,4 @@ -# `dynamic_project_options` function +# `dynamic_project_options` During the test and development, it can be useful to change options on the fly. For example, to enable sanitizers when running tests. You can include `DynamicOptions.cmake`, which imports the `dynamic_project_options` function. diff --git a/docs/src/index.rst b/docs/src/index.rst index ffdfc840..f3cb3dab 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -1,8 +1,5 @@ .. cmake-manual-description: CMake Modules Reference -Functions -************* - .. cmake-module:: ../../src/Index.cmake .. cmake-module:: ../../src/Vcpkg.cmake .. cmake-module:: ../../src/PackageProject.cmake diff --git a/docs/src/package_project.md b/docs/src/package_project.md index 7b6ba01e..16404430 100644 --- a/docs/src/package_project.md +++ b/docs/src/package_project.md @@ -1,4 +1,4 @@ -# `package_project` function +# `package_project` A function that packages the project for external usage (e.g. from vcpkg, Conan, etc). diff --git a/docs/src/project_options.rst b/docs/src/project_options.rst new file mode 100644 index 00000000..5f626723 --- /dev/null +++ b/docs/src/project_options.rst @@ -0,0 +1,5 @@ +.. include:: ./project_options_example.md + :parser: myst_parser.sphinx_ + +.. include:: ./project_options_api.md + :parser: myst_parser.sphinx_ diff --git a/docs/src/project_options_api.md b/docs/src/project_options_api.md new file mode 100644 index 00000000..1a8003cf --- /dev/null +++ b/docs/src/project_options_api.md @@ -0,0 +1,39 @@ +`project_options` function accepts the following named flags: + +- `ENABLE_CACHE`: Enable cache if available +- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck +- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy +- `ENABLE_VS_ANALYSIS`: Enable Visual Studio IDE code analysis if the generator is Visual Studio. +- `ENABLE_CONAN`: Use Conan for dependency management +- `ENABLE_INTERPROCEDURAL_OPTIMIZATION`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build +- `ENABLE_NATIVE_OPTIMIZATION`: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). +- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang +- `ENABLE_DOXYGEN`: Enable Doxygen documentation. The added `doxygen-docs` target can be built via `cmake --build ./build --target doxygen-docs`. +- `WARNINGS_AS_ERRORS`: Treat compiler and static code analyzer warnings as errors. This also affects CMake warnings related to those. +- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer +- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer +- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer +- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer +- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer +- `ENABLE_PCH`: Enable Precompiled Headers +- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use +- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang +- `ENABLE_UNITY`: Enable Unity builds of projects + +It gets the following named parameters that can have different values in front of them: + +- `PREFIX`: the optional prefix that is used to define `${PREFIX}_project_options` and `${PREFIX}_project_warnings` targets when the function is used in a multi-project fashion. +- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: + - `awesome-sidebar` (default) + - `awesome` + - `original` + - Alternatively you can supply a list of css files to be added to [DOXYGEN_HTML_EXTRA_STYLESHEET](https://www.doxygen.nl/manual/config.html#cfg_html_extra_stylesheet) +- `LINKER`: choose a specific linker (e.g. lld, gold, bfd). If set to OFF (default), the linker is automatically chosen. +- `PCH_HEADERS`: the list of the headers to precompile +- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings +- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings +- `GCC_WARNINGS`: Override the defaults for the GCC warnings +- `CUDA_WARNINGS`: Override the defaults for the CUDA warnings +- `CPPCHECK_OPTIONS`: Override the defaults for the options passed to cppcheck +- `VS_ANALYSIS_RULESET`: Override the defaults for the code analysis rule set in Visual Studio. +- `CONAN_OPTIONS`: Extra Conan options diff --git a/docs/src/project_options.md b/docs/src/project_options_example.md similarity index 63% rename from docs/src/project_options.md rename to docs/src/project_options_example.md index 1d084b2d..55922275 100644 --- a/docs/src/project_options.md +++ b/docs/src/project_options_example.md @@ -1,10 +1,8 @@ -# `project_options` function - -## Example +# `project_options` See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. -Here is a full example: +Here is a full example. ```cmake cmake_minimum_required(VERSION 3.20) @@ -98,7 +96,7 @@ project_options( Then add the executables or libraries to the project: -[An executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe): +#### [Executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe) ```cmake add_executable(main main.cpp) @@ -123,7 +121,7 @@ target_link_system_libraries( package_project(TARGETS main) ``` -[A header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib): +#### [Header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib) ```cmake add_library(my_header_lib INTERFACE) @@ -157,7 +155,7 @@ package_project( ) ``` -[A library with separate header and source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) +#### [Library with source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) ```cmake add_library(my_lib "./src/my_lib/lib.cpp") @@ -189,45 +187,3 @@ package_project( PUBLIC_INCLUDES ${INCLUDE_DIR} ) ``` - -## API - -`project_options` function accepts the following named flags: - -- `ENABLE_CACHE`: Enable cache if available -- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck -- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy -- `ENABLE_VS_ANALYSIS`: Enable Visual Studio IDE code analysis if the generator is Visual Studio. -- `ENABLE_CONAN`: Use Conan for dependency management -- `ENABLE_INTERPROCEDURAL_OPTIMIZATION`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build -- `ENABLE_NATIVE_OPTIMIZATION`: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.). -- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang -- `ENABLE_DOXYGEN`: Enable Doxygen documentation. The added `doxygen-docs` target can be built via `cmake --build ./build --target doxygen-docs`. -- `WARNINGS_AS_ERRORS`: Treat compiler and static code analyzer warnings as errors. This also affects CMake warnings related to those. -- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer -- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer -- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer -- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer -- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer -- `ENABLE_PCH`: Enable Precompiled Headers -- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use -- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang -- `ENABLE_UNITY`: Enable Unity builds of projects - -It gets the following named parameters that can have different values in front of them: - -- `PREFIX`: the optional prefix that is used to define `${PREFIX}_project_options` and `${PREFIX}_project_warnings` targets when the function is used in a multi-project fashion. -- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: - - `awesome-sidebar` (default) - - `awesome` - - `original` - - Alternatively you can supply a list of css files to be added to [DOXYGEN_HTML_EXTRA_STYLESHEET](https://www.doxygen.nl/manual/config.html#cfg_html_extra_stylesheet) -- `LINKER`: choose a specific linker (e.g. lld, gold, bfd). If set to OFF (default), the linker is automatically chosen. -- `PCH_HEADERS`: the list of the headers to precompile -- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings -- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings -- `GCC_WARNINGS`: Override the defaults for the GCC warnings -- `CUDA_WARNINGS`: Override the defaults for the CUDA warnings -- `CPPCHECK_OPTIONS`: Override the defaults for the options passed to cppcheck -- `VS_ANALYSIS_RULESET`: Override the defaults for the code analysis rule set in Visual Studio. -- `CONAN_OPTIONS`: Extra Conan options diff --git a/docs/src/run_vcpkg.md b/docs/src/run_vcpkg.md index 74bad991..387465a3 100644 --- a/docs/src/run_vcpkg.md +++ b/docs/src/run_vcpkg.md @@ -1,4 +1,4 @@ -# `run_vcpkg` function +# `run_vcpkg` Install vcpkg and vcpkg dependencies: diff --git a/docs/src/target_disable_static_analysis.md b/docs/src/target_disable_static_analysis.md index a69d1702..d599433b 100644 --- a/docs/src/target_disable_static_analysis.md +++ b/docs/src/target_disable_static_analysis.md @@ -1,4 +1,4 @@ -# `target_disable_static_analysis` function +# `target_disable_static_analysis` This function disables static analysis for the given target: diff --git a/docs/src/target_include_system_directories.md b/docs/src/target_include_system_directories.md index 91e51857..83e5f0a7 100644 --- a/docs/src/target_include_system_directories.md +++ b/docs/src/target_include_system_directories.md @@ -1,4 +1,4 @@ -# `target_include_system_directories` function +# `target_include_system_directories` Include a system directory (which suppresses its warnings). diff --git a/docs/src/target_link_cuda.md b/docs/src/target_link_cuda.md index faa2f761..d3a17d3d 100644 --- a/docs/src/target_link_cuda.md +++ b/docs/src/target_link_cuda.md @@ -1,4 +1,4 @@ -# `target_link_cuda` function +# `target_link_cuda` Link Cuda to the given target. diff --git a/docs/src/target_link_system_libraries.md b/docs/src/target_link_system_libraries.md index 88bc08ba..8560edea 100644 --- a/docs/src/target_link_system_libraries.md +++ b/docs/src/target_link_system_libraries.md @@ -1,4 +1,4 @@ -# `target_link_system_libraries` function +# `target_link_system_libraries` Link multiple library targets as system libraries (which suppresses their warnings). diff --git a/src/Index.cmake b/src/Index.cmake index 13dfee44..b9021e7c 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -40,8 +40,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/Vcpkg.cmake") #[[.rst: -.. include:: ../../docs/src/project_options.md - :parser: myst_parser.sphinx_ +.. include:: ../../docs/src/project_options.rst #]] # NOTE: cmake-lint [C0103] Invalid macro name "project_options" doesn't match `[0-9A-Z_]+` From 0aae24f7ac01d262055079d6ddca7070506082af Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 30 Jan 2023 22:24:32 -0800 Subject: [PATCH 064/139] docs: fix the project_options header in the docs [skip ci] --- README.md | 6 ++---- docs/src/project_options.rst | 3 +++ docs/src/project_options_example.md | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 701ec1a1..ed4e119c 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,12 @@ The full documentation is available here: ## Usage -# `project_options` {#project_options} - -See `project_options()` in action in [this template +See the `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. -Here is a full example. +Here is an example of the usage: ``` cmake cmake_minimum_required(VERSION 3.20) diff --git a/docs/src/project_options.rst b/docs/src/project_options.rst index 5f626723..b59808f3 100644 --- a/docs/src/project_options.rst +++ b/docs/src/project_options.rst @@ -1,3 +1,6 @@ +project_options +------------------- + .. include:: ./project_options_example.md :parser: myst_parser.sphinx_ diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 55922275..b7f85eea 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -1,8 +1,6 @@ -# `project_options` +See the `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. -See `project_options()` in action in [this template repository](https://github.com/aminya/cpp_vcpkg_project). [cpp_vcpkg_project](https://github.com/aminya/cpp_vcpkg_project) has prepared all the best practices for a production-ready C++ project. - -Here is a full example. +Here is an example of the usage: ```cmake cmake_minimum_required(VERSION 3.20) From 8092ca1d1a9a4d277a5b66a84aeafe9ce2163b66 Mon Sep 17 00:00:00 2001 From: bogdan-lab Date: Thu, 9 Feb 2023 10:23:46 +0300 Subject: [PATCH 065/139] Add target disable macro for include-what-you-use --- docs/src/target_disable_static_analysis.md | 1 + src/StaticAnalyzers.cmake | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/src/target_disable_static_analysis.md b/docs/src/target_disable_static_analysis.md index d599433b..8da31a96 100644 --- a/docs/src/target_disable_static_analysis.md +++ b/docs/src/target_disable_static_analysis.md @@ -11,3 +11,4 @@ There is also individual functions to disable a specific analysis for the target - `target_disable_cpp_check(target)` - `target_disable_vs_analysis(target)` - `target_disable_clang_tidy(target)` +- `target_disable_include_what_you_use(target)` diff --git a/src/StaticAnalyzers.cmake b/src/StaticAnalyzers.cmake index bf224d25..ce7fdd20 100644 --- a/src/StaticAnalyzers.cmake +++ b/src/StaticAnalyzers.cmake @@ -191,6 +191,15 @@ macro(target_disable_vs_analysis TARGET) endif() endmacro() +# Disable include-what-you-use for target +macro(target_disable_include_what_you_use TARGET) + find_program(INCLUDE_WHAT_YOU_USE include-what-you-use) + if(INCLUDE_WHAT_YOU_USE) + set_target_properties(${TARGET} PROPERTIES C_INCLUDE_WHAT_YOU_USE "") + set_target_properties(${TARGET} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "") + endif() +endmacro() + #[[.rst: .. include:: ../../docs/src/target_disable_static_analysis.md @@ -206,4 +215,5 @@ macro(target_disable_static_analysis TARGET) target_disable_cpp_check(${TARGET}) endif() target_disable_vs_analysis(${TARGET}) + target_disable_include_what_you_use(${TARGET}) endmacro() From b9442ae83f9d807cd65ca6dbc7af5bebbe41ad0a Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 11:03:00 +0800 Subject: [PATCH 066/139] Complete `target_include_header_directory` --- src/PackageProject.cmake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index d566dda5..203da39c 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -207,3 +207,26 @@ function(package_project) include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") endfunction() + +# A function that includes ${CMAKE_CURRENT_SOURCE_DIR}/include as the header directory of the target. +# A variable `_HEADER_DIRECTORY` will be created to represent the header directory path. +function(target_include_header_directory target) + # CACHE and FORCE to use it as a global variable + set(${target}_HEADER_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) + + get_target_property(sources ${target} SOURCES) + + if(NOT sources) # header-only library, aka `add_library(target INTERFACE)` + target_include_directories(${target} + INTERFACE + $ + $ + ) + else() + target_include_directories(${target} + PUBLIC + $ + $ + ) + endif() +endfunction() \ No newline at end of file From 516fa49498966faceb7d84eec0d31190251f1d59 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 11:03:47 +0800 Subject: [PATCH 067/139] Complete `target_configure_dependencies` --- src/PackageProject.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 203da39c..59f5f111 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -229,4 +229,23 @@ function(target_include_header_directory target) $ ) endif() +endfunction() + +# A function that `find_package(${dependency} CONFIG REQUIRED)` for all dependencies required and binds them to the target. +# Variables `__DEPENDENCIES` will be created to represent corresponding dependencies. +function(target_configure_dependencies target) + set(options) + set(one_value_args) + set(multi_value_args PRIVATE PUBLIC INTERFACE) + + cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + + # CACHE and FORCE to use it as a global variable + set(${target}_PRIVATE_DEPENDENCIES ${args_PRIVATE} CACHE STRING "" FORCE) + set(${target}_PUBLIC_DEPENDENCIES ${args_PUBLIC} CACHE STRING "" FORCE) + set(${target}_INTERFACE_DEPENDENCIES ${args_INTERFACE} CACHE STRING "" FORCE) + + foreach(dependency IN LISTS args_PRIVATE args_PUBLIC args_INTERFACE) + find_package(${dependency} CONFIG REQUIRED) + endforeach() endfunction() \ No newline at end of file From e61d8ad92bf65128cd34d6bd267a2c36a810f87e Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 13:08:20 +0800 Subject: [PATCH 068/139] Complete documentation Make examples simpler with helper functions Using `target_include_interface_directory` and `target_find_dependencies` to simplify the examples in README. --- README.md | 63 ++++++++++----------- docs/src/project_options_example.md | 57 +++++++++---------- docs/src/target_configure_dependencies.md | 31 ++++++++++ docs/src/target_include_header_directory.md | 22 +++++++ src/PackageProject.cmake | 16 ++++-- 5 files changed, 122 insertions(+), 67 deletions(-) create mode 100644 docs/src/target_configure_dependencies.md create mode 100644 docs/src/target_include_header_directory.md diff --git a/README.md b/README.md index ed4e119c..d4184e64 100644 --- a/README.md +++ b/README.md @@ -145,20 +145,19 @@ Then add the executables or libraries to the project: #### [Executable](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_exe) -``` cmake +```cmake add_executable(main main.cpp) target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_find_dependencies(main + PRIVATE + fmt + Eigen3 +) # Link dependencies -target_link_system_libraries( - main +target_link_system_libraries(main PRIVATE fmt::fmt Eigen3::Eigen @@ -170,25 +169,22 @@ package_project(TARGETS main) #### [Header-only library](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_header_lib) -``` cmake +```cmake add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings # Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_header_lib INTERFACE "$" - "$") +target_include_interface_directory(my_header_lib) # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_find_dependencies(my_header_lib + INTERFACE + fmt + Eigen3 +) # Link dependencies: -target_link_system_libraries( - my_header_lib +target_link_system_libraries(my_header_lib INTERFACE fmt::fmt Eigen3::Eigen @@ -197,32 +193,30 @@ target_link_system_libraries( # Package the project package_project( TARGETS my_header_lib project_options project_warnings - INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} - INTERFACE_INCLUDES ${INCLUDE_DIR} + # Just add these no matter whether dependencies exist. + INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} + INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} ) ``` #### [Library with source files](https://github.com/aminya/cpp_vcpkg_project/tree/main/my_lib) -``` cmake +```cmake add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings # Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_lib PUBLIC "$" - "$") +target_include_interface_directory(my_lib) # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_find_dependencies(my_lib + PRIVATE + fmt + Eigen3 +) # Link dependencies: -target_link_system_libraries( - my_lib +target_link_system_libraries(my_lib PRIVATE fmt::fmt Eigen3::Eigen @@ -231,7 +225,10 @@ target_link_system_libraries( # Package the project package_project( TARGETS my_lib - PUBLIC_INCLUDES ${INCLUDE_DIR} + # Just add these no matter whether dependencies exist. + INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} + PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} + PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index b7f85eea..02d32348 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -101,15 +101,14 @@ add_executable(main main.cpp) target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_configure_dependencies(main + PRIVATE + fmt + Eigen3 +) # Link dependencies -target_link_system_libraries( - main +target_link_system_libraries(main PRIVATE fmt::fmt Eigen3::Eigen @@ -126,20 +125,17 @@ add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings # Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_header_lib INTERFACE "$" - "$") +target_include_header_directory(my_header_lib) # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_configure_dependencies(my_header_lib + INTERFACE + fmt + Eigen3 +) # Link dependencies: -target_link_system_libraries( - my_header_lib +target_link_system_libraries(my_header_lib INTERFACE fmt::fmt Eigen3::Eigen @@ -148,8 +144,9 @@ target_link_system_libraries( # Package the project package_project( TARGETS my_header_lib project_options project_warnings - INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} - INTERFACE_INCLUDES ${INCLUDE_DIR} + # Just add these no matter whether dependencies exist. + INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} + INTERFACE_INCLUDES ${my_header_lib_HEADER_DIRECTORY} ) ``` @@ -160,20 +157,17 @@ add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings # Includes -set(INCLUDE_DIR "include") # must be relative paths -target_include_directories(my_lib PUBLIC "$" - "$") +target_include_header_directory(my_lib) # Find dependencies: -set(DEPENDENCIES_CONFIGURED fmt Eigen3) - -foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) - find_package(${DEPENDENCY} CONFIG REQUIRED) -endforeach() +target_configure_dependencies(my_lib + PRIVATE + fmt + Eigen3 +) # Link dependencies: -target_link_system_libraries( - my_lib +target_link_system_libraries(my_lib PRIVATE fmt::fmt Eigen3::Eigen @@ -182,6 +176,9 @@ target_link_system_libraries( # Package the project package_project( TARGETS my_lib - PUBLIC_INCLUDES ${INCLUDE_DIR} + # Just add these no matter whether dependencies exist. + INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} + PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} + PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} ) ``` diff --git a/docs/src/target_configure_dependencies.md b/docs/src/target_configure_dependencies.md new file mode 100644 index 00000000..47ef574d --- /dev/null +++ b/docs/src/target_configure_dependencies.md @@ -0,0 +1,31 @@ +# `target_configure_dependencies` function + +This function `find_package(${dependency} CONFIG REQUIRED)` for all dependencies required and binds them to the target. + +Variables `__DEPENDENCIES` will be created to represent corresponding dependencies. + +```cmake +add_library(my_lib) +target_sources(my_lib PRIVATE function.cpp) +target_include_header_directory(my_header_lib) + +target_configure_dependencies(my_lib + PUBLIC + fmt + PRIVATE + range-v3 +) + +target_link_system_libraries(my_lib + PUBLIC + fmt::fmt + PRIVATE + range-v3::range-v3 +) + +package_project( + TARGETS my_lib + PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} + PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} +) +``` diff --git a/docs/src/target_include_header_directory.md b/docs/src/target_include_header_directory.md new file mode 100644 index 00000000..deb7151e --- /dev/null +++ b/docs/src/target_include_header_directory.md @@ -0,0 +1,22 @@ +# `target_include_header_directory` function + +This function that includes `${CMAKE_CURRENT_SOURCE_DIR}/include` +(i.e. the `include` directory under the path of CMakeLists.txt which calls the function) +as the header directory of the target. + +A variable `_HEADER_DIRECTORY` will be created to represent the header directory path. + +```cmake +add_library(my_header_lib INTERFACE) +target_include_header_directory(my_header_lib) + +add_library(my_lib) +target_sources(my_lib PRIVATE function.cpp) +target_include_header_directory(my_lib) + +package_project( + TARGETS my_header_lib my_lib + PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} + INTERFACE_INCLUDES ${my_header_lib_HEADER_DIRECTORY} +) +``` diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 59f5f111..c5d421aa 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -208,8 +208,12 @@ function(package_project) include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") endfunction() -# A function that includes ${CMAKE_CURRENT_SOURCE_DIR}/include as the header directory of the target. -# A variable `_HEADER_DIRECTORY` will be created to represent the header directory path. +#[[.rst: + +.. include:: ../../docs/src/target_include_header_directory.md + :parser: myst_parser.sphinx_ + +#]] function(target_include_header_directory target) # CACHE and FORCE to use it as a global variable set(${target}_HEADER_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) @@ -231,8 +235,12 @@ function(target_include_header_directory target) endif() endfunction() -# A function that `find_package(${dependency} CONFIG REQUIRED)` for all dependencies required and binds them to the target. -# Variables `__DEPENDENCIES` will be created to represent corresponding dependencies. +#[[.rst: + +.. include:: ../../docs/src/target_configure_dependencies.md + :parser: myst_parser.sphinx_ + +#]] function(target_configure_dependencies target) set(options) set(one_value_args) From 0ac118188bb3b651e71a5cf475443d23c2960663 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 13:12:12 +0800 Subject: [PATCH 069/139] Rename `target_configure_dependencies` Rename `target_configure_dependencies` to `target_find_dependencies` as `configure` is usually used by CMake for the `.in` files. Revert unintended format change --- docs/src/project_options_example.md | 6 +++--- ...onfigure_dependencies.md => target_find_dependencies.md} | 4 ++-- src/PackageProject.cmake | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename docs/src/{target_configure_dependencies.md => target_find_dependencies.md} (88%) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 02d32348..ed092274 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -101,7 +101,7 @@ add_executable(main main.cpp) target_link_libraries(main PRIVATE project_options project_warnings) # link project_options/warnings # Find dependencies: -target_configure_dependencies(main +target_find_dependencies(main PRIVATE fmt Eigen3 @@ -128,7 +128,7 @@ target_link_libraries(my_header_lib INTERFACE project_options project_warnings) target_include_header_directory(my_header_lib) # Find dependencies: -target_configure_dependencies(my_header_lib +target_find_dependencies(my_header_lib INTERFACE fmt Eigen3 @@ -160,7 +160,7 @@ target_link_libraries(my_lib PRIVATE project_options project_warnings) # link pr target_include_header_directory(my_lib) # Find dependencies: -target_configure_dependencies(my_lib +target_find_dependencies(my_lib PRIVATE fmt Eigen3 diff --git a/docs/src/target_configure_dependencies.md b/docs/src/target_find_dependencies.md similarity index 88% rename from docs/src/target_configure_dependencies.md rename to docs/src/target_find_dependencies.md index 47ef574d..cf388e77 100644 --- a/docs/src/target_configure_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -1,4 +1,4 @@ -# `target_configure_dependencies` function +# `target_find_dependencies` function This function `find_package(${dependency} CONFIG REQUIRED)` for all dependencies required and binds them to the target. @@ -9,7 +9,7 @@ add_library(my_lib) target_sources(my_lib PRIVATE function.cpp) target_include_header_directory(my_header_lib) -target_configure_dependencies(my_lib +target_find_dependencies(my_lib PUBLIC fmt PRIVATE diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index c5d421aa..1ff0aba5 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -237,11 +237,11 @@ endfunction() #[[.rst: -.. include:: ../../docs/src/target_configure_dependencies.md +.. include:: ../../docs/src/target_find_dependencies.md :parser: myst_parser.sphinx_ #]] -function(target_configure_dependencies target) +function(target_find_dependencies target) set(options) set(one_value_args) set(multi_value_args PRIVATE PUBLIC INTERFACE) From 1e75eea5db20ae186246a040b365898ebaee0afc Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 15:12:37 +0800 Subject: [PATCH 070/139] Rename `target_include_header_directory` Rename `target_include_header_directory` to `target_include_interface_directory`. --- docs/src/project_options_example.md | 4 +- docs/src/target_find_dependencies.md | 2 +- ... => target_include_interface_directory.md} | 6 +- src/PackageProject.cmake | 116 +++++++++++------- 4 files changed, 78 insertions(+), 50 deletions(-) rename docs/src/{target_include_header_directory.md => target_include_interface_directory.md} (79%) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index ed092274..6e6771d3 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -125,7 +125,7 @@ add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings # Includes -target_include_header_directory(my_header_lib) +target_include_interface_directory(my_header_lib) # Find dependencies: target_find_dependencies(my_header_lib @@ -157,7 +157,7 @@ add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings # Includes -target_include_header_directory(my_lib) +target_include_interface_directory(my_lib) # Find dependencies: target_find_dependencies(my_lib diff --git a/docs/src/target_find_dependencies.md b/docs/src/target_find_dependencies.md index cf388e77..d10f4159 100644 --- a/docs/src/target_find_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -7,7 +7,7 @@ Variables `__DEPENDENCIES` will be create ```cmake add_library(my_lib) target_sources(my_lib PRIVATE function.cpp) -target_include_header_directory(my_header_lib) +target_include_interface_directory(my_header_lib) target_find_dependencies(my_lib PUBLIC diff --git a/docs/src/target_include_header_directory.md b/docs/src/target_include_interface_directory.md similarity index 79% rename from docs/src/target_include_header_directory.md rename to docs/src/target_include_interface_directory.md index deb7151e..97ccb53e 100644 --- a/docs/src/target_include_header_directory.md +++ b/docs/src/target_include_interface_directory.md @@ -1,4 +1,4 @@ -# `target_include_header_directory` function +# `target_include_interface_directory` function This function that includes `${CMAKE_CURRENT_SOURCE_DIR}/include` (i.e. the `include` directory under the path of CMakeLists.txt which calls the function) @@ -8,11 +8,11 @@ A variable `_HEADER_DIRECTORY` will be created to represent the hea ```cmake add_library(my_header_lib INTERFACE) -target_include_header_directory(my_header_lib) +target_include_interface_directory(my_header_lib) add_library(my_lib) target_sources(my_lib PRIVATE function.cpp) -target_include_header_directory(my_lib) +target_include_interface_directory(my_lib) package_project( TARGETS my_header_lib my_lib diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 1ff0aba5..f1f11e8a 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -12,34 +12,45 @@ function(package_project) # default to false set(_options ARCH_INDEPENDENT) set(_oneValueArgs - # default to the project_name: - NAME - COMPONENT - # default to project version: - VERSION - # default to semver - COMPATIBILITY - # default to ${CMAKE_BINARY_DIR}/${NAME} - CONFIG_EXPORT_DESTINATION - # default to ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${NAME} suitable for vcpkg, etc. - CONFIG_INSTALL_DESTINATION) + + # default to the project_name: + NAME + COMPONENT + + # default to project version: + VERSION + + # default to semver + COMPATIBILITY + + # default to ${CMAKE_BINARY_DIR}/${NAME} + CONFIG_EXPORT_DESTINATION + + # default to ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${NAME} suitable for vcpkg, etc. + CONFIG_INSTALL_DESTINATION) set(_multiValueArgs - # recursively found for the current folder if not specified - TARGETS - # a list of public/interface include directories or files - INTERFACE_INCLUDES - PUBLIC_INCLUDES - # the names of the INTERFACE/PUBLIC dependencies that are found using `CONFIG` - INTERFACE_DEPENDENCIES_CONFIGURED - PUBLIC_DEPENDENCIES_CONFIGURED - # the INTERFACE/PUBLIC dependencies that are found by any means using `find_dependency`. - # the arguments must be specified within double quotes (e.g. " 1.0.0 EXACT" or " CONFIG"). - INTERFACE_DEPENDENCIES - PUBLIC_DEPENDENCIES - # the names of the PRIVATE dependencies that are found using `CONFIG`. Only included when BUILD_SHARED_LIBS is OFF. - PRIVATE_DEPENDENCIES_CONFIGURED - # PRIVATE dependencies that are only included when BUILD_SHARED_LIBS is OFF - PRIVATE_DEPENDENCIES) + + # recursively found for the current folder if not specified + TARGETS + + # a list of public/interface include directories or files + INTERFACE_INCLUDES + PUBLIC_INCLUDES + + # the names of the INTERFACE/PUBLIC dependencies that are found using `CONFIG` + INTERFACE_DEPENDENCIES_CONFIGURED + PUBLIC_DEPENDENCIES_CONFIGURED + + # the INTERFACE/PUBLIC dependencies that are found by any means using `find_dependency`. + # the arguments must be specified within double quotes (e.g. " 1.0.0 EXACT" or " CONFIG"). + INTERFACE_DEPENDENCIES + PUBLIC_DEPENDENCIES + + # the names of the PRIVATE dependencies that are found using `CONFIG`. Only included when BUILD_SHARED_LIBS is OFF. + PRIVATE_DEPENDENCIES_CONFIGURED + + # PRIVATE dependencies that are only included when BUILD_SHARED_LIBS is OFF + PRIVATE_DEPENDENCIES) cmake_parse_arguments( _PackageProject @@ -61,6 +72,7 @@ function(package_project) if("${_PackageProject_NAME}" STREQUAL "") set(_PackageProject_NAME ${PROJECT_NAME}) endif() + # ycm args set(_PackageProject_NAMESPACE "${_PackageProject_NAME}::") set(_PackageProject_VARS_PREFIX ${_PackageProject_NAME}) @@ -80,26 +92,30 @@ function(package_project) if("${_PackageProject_CONFIG_EXPORT_DESTINATION}" STREQUAL "") set(_PackageProject_CONFIG_EXPORT_DESTINATION "${CMAKE_BINARY_DIR}/${_PackageProject_NAME}") endif() + set(_PackageProject_EXPORT_DESTINATION "${_PackageProject_CONFIG_EXPORT_DESTINATION}") # use datadir (works better with vcpkg, etc) if("${_PackageProject_CONFIG_INSTALL_DESTINATION}" STREQUAL "") set(_PackageProject_CONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${_PackageProject_NAME}") endif() + # ycm args set(_PackageProject_INSTALL_DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") # Installation of the public/interface includes set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}") + if(NOT - "${_PackageProject_PUBLIC_INCLUDES}" - STREQUAL - "") + "${_PackageProject_PUBLIC_INCLUDES}" + STREQUAL + "") foreach(_INC ${_PackageProject_PUBLIC_INCLUDES}) # make include absolute if(NOT IS_ABSOLUTE ${_INC}) set(_INC "${CMAKE_CURRENT_SOURCE_DIR}/${_INC}") endif() + # install include if(IS_DIRECTORY ${_INC}) # the include directories are directly installed to the install destination. If you want an `include` folder in the install destination, name your include directory as `include` (or install it manually using `install()` command). @@ -112,30 +128,36 @@ function(package_project) # Append the configured public dependencies set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}") + "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}") + if(NOT - "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - STREQUAL - "") + "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" + STREQUAL + "") set(_PUBLIC_DEPENDENCIES_CONFIG) + foreach(DEP ${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}) list(APPEND _PUBLIC_DEPENDENCIES_CONFIG "${DEP} CONFIG") endforeach() endif() + list(APPEND _PackageProject_PUBLIC_DEPENDENCIES ${_PUBLIC_DEPENDENCIES_CONFIG}) + # ycm arg set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} ${_PackageProject_INTERFACE_DEPENDENCIES}) # Append the configured private dependencies if(NOT - "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" - STREQUAL - "") + "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" + STREQUAL + "") set(_PRIVATE_DEPENDENCIES_CONFIG) + foreach(DEP ${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}) list(APPEND _PRIVATE_DEPENDENCIES_CONFIG "${DEP} CONFIG") endforeach() endif() + # ycm arg list(APPEND _PackageProject_PRIVATE_DEPENDENCIES ${_PRIVATE_DEPENDENCIES_CONFIG}) @@ -155,16 +177,18 @@ function(package_project) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin PUBLIC_HEADER - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" - COMPONENT dev - ${FILE_SET_ARGS}) + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" + COMPONENT dev + ${FILE_SET_ARGS}) # download ForwardArguments FetchContent_Declare(_fargs URL https://github.com/polysquare/cmake-forward-arguments/archive/refs/tags/v1.0.0.zip) FetchContent_GetProperties(_fargs) + if(NOT _fargs_POPULATED) FetchContent_Populate(_fargs) endif() + include("${_fargs_SOURCE_DIR}/ForwardArguments.cmake") # prepare the forward arguments for ycm @@ -182,27 +206,31 @@ function(package_project) # download ycm FetchContent_Declare(_ycm URL https://github.com/robotology/ycm/archive/refs/tags/v0.13.0.zip) FetchContent_GetProperties(_ycm) + if(NOT _ycm_POPULATED) FetchContent_Populate(_ycm) endif() + include("${_ycm_SOURCE_DIR}/modules/InstallBasicPackageFiles.cmake") install_basic_package_files(${_PackageProject_NAME} "${_FARGS_LIST}") # install the usage file set(_targets_str "") + foreach(_target ${_targets_list}) set(_targets_str "${_targets_str} ${_PackageProject_NAMESPACE}${_target}") endforeach() + set(USAGE_FILE_CONTENT - "# The package ${_PackageProject_NAME} provides the following CMake targets: + "# The package ${_PackageProject_NAME} provides the following CMake targets: find_package(${_PackageProject_NAME} CONFIG REQUIRED) target_link_libraries(main PRIVATE ${_targets_str}) ") file(WRITE "${_PackageProject_EXPORT_DESTINATION}/usage" "${USAGE_FILE_CONTENT}") install(FILES "${_PackageProject_EXPORT_DESTINATION}/usage" - DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") + DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") install(CODE "MESSAGE(STATUS \"${USAGE_FILE_CONTENT}\")") include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") @@ -210,11 +238,11 @@ endfunction() #[[.rst: -.. include:: ../../docs/src/target_include_header_directory.md +.. include:: ../../docs/src/target_include_interface_directory.md :parser: myst_parser.sphinx_ #]] -function(target_include_header_directory target) +function(target_include_interface_directory target) # CACHE and FORCE to use it as a global variable set(${target}_HEADER_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) From 372f458441c68119142801bb4247f83c942bd61d Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Tue, 31 Jan 2023 15:18:33 +0800 Subject: [PATCH 071/139] fix: rename `_HEADER_DIRECTORY` Rename `_HEADER_DIRECTORY` to `_INTERFACE_DIRECTORY` as `target_include_header_directory` renamed to `target_include_interface_directory` Revert uninteded format change Add newline at end of cmake file --- docs/src/project_options_example.md | 4 +- docs/src/target_find_dependencies.md | 2 +- .../src/target_include_interface_directory.md | 6 +- src/PackageProject.cmake | 120 +++++++----------- 4 files changed, 52 insertions(+), 80 deletions(-) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 6e6771d3..7442160f 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -146,7 +146,7 @@ package_project( TARGETS my_header_lib project_options project_warnings # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} - INTERFACE_INCLUDES ${my_header_lib_HEADER_DIRECTORY} + INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} ) ``` @@ -179,6 +179,6 @@ package_project( # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} - PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} + PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/docs/src/target_find_dependencies.md b/docs/src/target_find_dependencies.md index d10f4159..205b2a05 100644 --- a/docs/src/target_find_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -26,6 +26,6 @@ target_link_system_libraries(my_lib package_project( TARGETS my_lib PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} - PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} + PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/docs/src/target_include_interface_directory.md b/docs/src/target_include_interface_directory.md index 97ccb53e..15bbd562 100644 --- a/docs/src/target_include_interface_directory.md +++ b/docs/src/target_include_interface_directory.md @@ -4,7 +4,7 @@ This function that includes `${CMAKE_CURRENT_SOURCE_DIR}/include` (i.e. the `include` directory under the path of CMakeLists.txt which calls the function) as the header directory of the target. -A variable `_HEADER_DIRECTORY` will be created to represent the header directory path. +A variable `_INTERFACE_DIRECTORY` will be created to represent the header directory path. ```cmake add_library(my_header_lib INTERFACE) @@ -16,7 +16,7 @@ target_include_interface_directory(my_lib) package_project( TARGETS my_header_lib my_lib - PUBLIC_INCLUDES ${my_lib_HEADER_DIRECTORY} - INTERFACE_INCLUDES ${my_header_lib_HEADER_DIRECTORY} + PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} + INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index f1f11e8a..db3283ee 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -12,45 +12,34 @@ function(package_project) # default to false set(_options ARCH_INDEPENDENT) set(_oneValueArgs - - # default to the project_name: - NAME - COMPONENT - - # default to project version: - VERSION - - # default to semver - COMPATIBILITY - - # default to ${CMAKE_BINARY_DIR}/${NAME} - CONFIG_EXPORT_DESTINATION - - # default to ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${NAME} suitable for vcpkg, etc. - CONFIG_INSTALL_DESTINATION) + # default to the project_name: + NAME + COMPONENT + # default to project version: + VERSION + # default to semver + COMPATIBILITY + # default to ${CMAKE_BINARY_DIR}/${NAME} + CONFIG_EXPORT_DESTINATION + # default to ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${NAME} suitable for vcpkg, etc. + CONFIG_INSTALL_DESTINATION) set(_multiValueArgs - - # recursively found for the current folder if not specified - TARGETS - - # a list of public/interface include directories or files - INTERFACE_INCLUDES - PUBLIC_INCLUDES - - # the names of the INTERFACE/PUBLIC dependencies that are found using `CONFIG` - INTERFACE_DEPENDENCIES_CONFIGURED - PUBLIC_DEPENDENCIES_CONFIGURED - - # the INTERFACE/PUBLIC dependencies that are found by any means using `find_dependency`. - # the arguments must be specified within double quotes (e.g. " 1.0.0 EXACT" or " CONFIG"). - INTERFACE_DEPENDENCIES - PUBLIC_DEPENDENCIES - - # the names of the PRIVATE dependencies that are found using `CONFIG`. Only included when BUILD_SHARED_LIBS is OFF. - PRIVATE_DEPENDENCIES_CONFIGURED - - # PRIVATE dependencies that are only included when BUILD_SHARED_LIBS is OFF - PRIVATE_DEPENDENCIES) + # recursively found for the current folder if not specified + TARGETS + # a list of public/interface include directories or files + INTERFACE_INCLUDES + PUBLIC_INCLUDES + # the names of the INTERFACE/PUBLIC dependencies that are found using `CONFIG` + INTERFACE_DEPENDENCIES_CONFIGURED + PUBLIC_DEPENDENCIES_CONFIGURED + # the INTERFACE/PUBLIC dependencies that are found by any means using `find_dependency`. + # the arguments must be specified within double quotes (e.g. " 1.0.0 EXACT" or " CONFIG"). + INTERFACE_DEPENDENCIES + PUBLIC_DEPENDENCIES + # the names of the PRIVATE dependencies that are found using `CONFIG`. Only included when BUILD_SHARED_LIBS is OFF. + PRIVATE_DEPENDENCIES_CONFIGURED + # PRIVATE dependencies that are only included when BUILD_SHARED_LIBS is OFF + PRIVATE_DEPENDENCIES) cmake_parse_arguments( _PackageProject @@ -72,7 +61,6 @@ function(package_project) if("${_PackageProject_NAME}" STREQUAL "") set(_PackageProject_NAME ${PROJECT_NAME}) endif() - # ycm args set(_PackageProject_NAMESPACE "${_PackageProject_NAME}::") set(_PackageProject_VARS_PREFIX ${_PackageProject_NAME}) @@ -92,30 +80,26 @@ function(package_project) if("${_PackageProject_CONFIG_EXPORT_DESTINATION}" STREQUAL "") set(_PackageProject_CONFIG_EXPORT_DESTINATION "${CMAKE_BINARY_DIR}/${_PackageProject_NAME}") endif() - set(_PackageProject_EXPORT_DESTINATION "${_PackageProject_CONFIG_EXPORT_DESTINATION}") # use datadir (works better with vcpkg, etc) if("${_PackageProject_CONFIG_INSTALL_DESTINATION}" STREQUAL "") set(_PackageProject_CONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${_PackageProject_NAME}") endif() - # ycm args set(_PackageProject_INSTALL_DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") # Installation of the public/interface includes set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}") - if(NOT - "${_PackageProject_PUBLIC_INCLUDES}" - STREQUAL - "") + "${_PackageProject_PUBLIC_INCLUDES}" + STREQUAL + "") foreach(_INC ${_PackageProject_PUBLIC_INCLUDES}) # make include absolute if(NOT IS_ABSOLUTE ${_INC}) set(_INC "${CMAKE_CURRENT_SOURCE_DIR}/${_INC}") endif() - # install include if(IS_DIRECTORY ${_INC}) # the include directories are directly installed to the install destination. If you want an `include` folder in the install destination, name your include directory as `include` (or install it manually using `install()` command). @@ -128,36 +112,30 @@ function(package_project) # Append the configured public dependencies set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}") - + "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}") if(NOT - "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - STREQUAL - "") + "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" + STREQUAL + "") set(_PUBLIC_DEPENDENCIES_CONFIG) - foreach(DEP ${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}) list(APPEND _PUBLIC_DEPENDENCIES_CONFIG "${DEP} CONFIG") endforeach() endif() - list(APPEND _PackageProject_PUBLIC_DEPENDENCIES ${_PUBLIC_DEPENDENCIES_CONFIG}) - # ycm arg set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} ${_PackageProject_INTERFACE_DEPENDENCIES}) # Append the configured private dependencies if(NOT - "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" - STREQUAL - "") + "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" + STREQUAL + "") set(_PRIVATE_DEPENDENCIES_CONFIG) - foreach(DEP ${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}) list(APPEND _PRIVATE_DEPENDENCIES_CONFIG "${DEP} CONFIG") endforeach() endif() - # ycm arg list(APPEND _PackageProject_PRIVATE_DEPENDENCIES ${_PRIVATE_DEPENDENCIES_CONFIG}) @@ -177,18 +155,16 @@ function(package_project) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin PUBLIC_HEADER - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" - COMPONENT dev - ${FILE_SET_ARGS}) + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" + COMPONENT dev + ${FILE_SET_ARGS}) # download ForwardArguments FetchContent_Declare(_fargs URL https://github.com/polysquare/cmake-forward-arguments/archive/refs/tags/v1.0.0.zip) FetchContent_GetProperties(_fargs) - if(NOT _fargs_POPULATED) FetchContent_Populate(_fargs) endif() - include("${_fargs_SOURCE_DIR}/ForwardArguments.cmake") # prepare the forward arguments for ycm @@ -206,31 +182,27 @@ function(package_project) # download ycm FetchContent_Declare(_ycm URL https://github.com/robotology/ycm/archive/refs/tags/v0.13.0.zip) FetchContent_GetProperties(_ycm) - if(NOT _ycm_POPULATED) FetchContent_Populate(_ycm) endif() - include("${_ycm_SOURCE_DIR}/modules/InstallBasicPackageFiles.cmake") install_basic_package_files(${_PackageProject_NAME} "${_FARGS_LIST}") # install the usage file set(_targets_str "") - foreach(_target ${_targets_list}) set(_targets_str "${_targets_str} ${_PackageProject_NAMESPACE}${_target}") endforeach() - set(USAGE_FILE_CONTENT - "# The package ${_PackageProject_NAME} provides the following CMake targets: + "# The package ${_PackageProject_NAME} provides the following CMake targets: find_package(${_PackageProject_NAME} CONFIG REQUIRED) target_link_libraries(main PRIVATE ${_targets_str}) ") file(WRITE "${_PackageProject_EXPORT_DESTINATION}/usage" "${USAGE_FILE_CONTENT}") install(FILES "${_PackageProject_EXPORT_DESTINATION}/usage" - DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") + DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") install(CODE "MESSAGE(STATUS \"${USAGE_FILE_CONTENT}\")") include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") @@ -244,20 +216,20 @@ endfunction() #]] function(target_include_interface_directory target) # CACHE and FORCE to use it as a global variable - set(${target}_HEADER_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) + set(${target}_INTERFACE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) get_target_property(sources ${target} SOURCES) if(NOT sources) # header-only library, aka `add_library(target INTERFACE)` target_include_directories(${target} INTERFACE - $ + $ $ ) else() target_include_directories(${target} PUBLIC - $ + $ $ ) endif() @@ -284,4 +256,4 @@ function(target_find_dependencies target) foreach(dependency IN LISTS args_PRIVATE args_PUBLIC args_INTERFACE) find_package(${dependency} CONFIG REQUIRED) endforeach() -endfunction() \ No newline at end of file +endfunction() From 93a8bbcd898b29ff67404cbdadb325a6f684ad87 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 1 Feb 2023 17:49:36 +0800 Subject: [PATCH 072/139] Hint to export project_options/warings in examples --- README.md | 6 ++++-- docs/src/project_options_example.md | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d4184e64..0b9a4409 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,8 @@ target_link_system_libraries(my_header_lib # Package the project package_project( - TARGETS my_header_lib project_options project_warnings + # Note that you must export `project_options` and `project_warnings` for `my_header_lib` + TARGETS my_header_lib project_options project_warnings # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} @@ -224,7 +225,8 @@ target_link_system_libraries(my_lib # Package the project package_project( - TARGETS my_lib + # Note that you must export `project_options` and `project_warnings` for `my_lib` + TARGETS my_lib project_options project_warnings # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 7442160f..ac622292 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -143,6 +143,7 @@ target_link_system_libraries(my_header_lib # Package the project package_project( + # Note that you must export `project_options` and `project_warnings` for `my_header_lib` TARGETS my_header_lib project_options project_warnings # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} @@ -175,7 +176,8 @@ target_link_system_libraries(my_lib # Package the project package_project( - TARGETS my_lib + # Note that you must export `project_options` and `project_warnings` for `my_lib` + TARGETS my_lib project_options project_warnings # Just add these no matter whether dependencies exist. INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} From 21209042e668fd2b8e7d87e1f8840276a07eca2e Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Mon, 6 Mar 2023 19:17:00 +0800 Subject: [PATCH 073/139] Change to find dependencies in Module mode If dependencies are not found in Module mode, the search falls back to Config mode. However, when explicitly use find_package( Config) as we used to do. The search won't fall back to Module mode. If Config mode is preferred, use CMAKE_FIND_PACKAGE_PREFER_CONFIG to change the behaviour. typo: `my_header_lib` -> `my_lib` --- docs/src/target_find_dependencies.md | 4 ++-- src/PackageProject.cmake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/target_find_dependencies.md b/docs/src/target_find_dependencies.md index 205b2a05..b005bfeb 100644 --- a/docs/src/target_find_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -1,13 +1,13 @@ # `target_find_dependencies` function -This function `find_package(${dependency} CONFIG REQUIRED)` for all dependencies required and binds them to the target. +This function `find_package(${dependency} REQUIRED)` for all dependencies required and binds them to the target. Variables `__DEPENDENCIES` will be created to represent corresponding dependencies. ```cmake add_library(my_lib) target_sources(my_lib PRIVATE function.cpp) -target_include_interface_directory(my_header_lib) +target_include_interface_directory(my_lib) target_find_dependencies(my_lib PUBLIC diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index db3283ee..ebadd620 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -254,6 +254,6 @@ function(target_find_dependencies target) set(${target}_INTERFACE_DEPENDENCIES ${args_INTERFACE} CACHE STRING "" FORCE) foreach(dependency IN LISTS args_PRIVATE args_PUBLIC args_INTERFACE) - find_package(${dependency} CONFIG REQUIRED) + find_package(${dependency} REQUIRED) endforeach() endfunction() From e80417cf6b77d98f0a5c1eb66c72ca78068b00d8 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 15:26:44 +0800 Subject: [PATCH 074/139] Use target properties instead of force cache --- src/PackageProject.cmake | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index ebadd620..dbce4107 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -214,22 +214,30 @@ endfunction() :parser: myst_parser.sphinx_ #]] -function(target_include_interface_directory target) - # CACHE and FORCE to use it as a global variable - set(${target}_INTERFACE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "" FORCE) +function(target_include_interface_directory target include_dir) + # Make include_dir absolute + cmake_path(IS_RELATIVE include_dir is_relative) + if(is_relative) + set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}") + endif() - get_target_property(sources ${target} SOURCES) + # Append include_dir to target property PROJECT_OPTIONS_INTERFACE_DIRECTORY + set_target_properties(${target} PROPERTIES + PROJECT_OPTIONS_INTERFACE_DIRECTORY ${include_dir} + ) - if(NOT sources) # header-only library, aka `add_library(target INTERFACE)` + # Include the interface directory + get_target_property(has_source_files ${target} SOURCES) + if(NOT has_source_files) # header-only library, aka `add_library( INTERFACE)` target_include_directories(${target} INTERFACE - $ + $ $ ) else() target_include_directories(${target} PUBLIC - $ + $ $ ) endif() @@ -245,15 +253,16 @@ function(target_find_dependencies target) set(options) set(one_value_args) set(multi_value_args PRIVATE PUBLIC INTERFACE) - cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) - # CACHE and FORCE to use it as a global variable - set(${target}_PRIVATE_DEPENDENCIES ${args_PRIVATE} CACHE STRING "" FORCE) - set(${target}_PUBLIC_DEPENDENCIES ${args_PUBLIC} CACHE STRING "" FORCE) - set(${target}_INTERFACE_DEPENDENCIES ${args_INTERFACE} CACHE STRING "" FORCE) - + # Call find_package to all newly added dependencies foreach(dependency IN LISTS args_PRIVATE args_PUBLIC args_INTERFACE) find_package(${dependency} REQUIRED) endforeach() + + set_target_properties(${target} PROPERTIES + PROJECT_OPTIONS_PRIVATE_DEPENDENCIES "${args_PRIVATE}" + PROJECT_OPTIONS_PUBLIC_DEPENDENCIES "${args_PUBLIC}" + PROJECT_OPTIONS_INTERFACE_DEPENDENCIES "${args_INTERFACE}" + ) endfunction() From 33df76e0e09823f83d8e6b645b6c565d30b8f5e5 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 15:27:06 +0800 Subject: [PATCH 075/139] Enable multiple calls --- src/PackageProject.cmake | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index dbce4107..5f282c01 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -208,6 +208,20 @@ function(package_project) include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") endfunction() +function(set_or_append_target_property target property new_values) + get_target_property(all_values ${target} ${property}) + + if(NOT all_values) # If the property hasn't set + set(all_values "${new_values}") + else() + list(APPEND all_values ${new_values}) + endif() + + set_target_properties(${target} + PROPERTIES ${property} "${all_values}" + ) +endfunction() + #[[.rst: .. include:: ../../docs/src/target_include_interface_directory.md @@ -222,8 +236,8 @@ function(target_include_interface_directory target include_dir) endif() # Append include_dir to target property PROJECT_OPTIONS_INTERFACE_DIRECTORY - set_target_properties(${target} PROPERTIES - PROJECT_OPTIONS_INTERFACE_DIRECTORY ${include_dir} + set_or_append_target_property(${target} + "PROJECT_OPTIONS_INTERFACE_DIRECTORY" ${include_dir} ) # Include the interface directory @@ -260,9 +274,13 @@ function(target_find_dependencies target) find_package(${dependency} REQUIRED) endforeach() - set_target_properties(${target} PROPERTIES - PROJECT_OPTIONS_PRIVATE_DEPENDENCIES "${args_PRIVATE}" - PROJECT_OPTIONS_PUBLIC_DEPENDENCIES "${args_PUBLIC}" - PROJECT_OPTIONS_INTERFACE_DEPENDENCIES "${args_INTERFACE}" + set_or_append_target_property(${target} + "PROJECT_OPTIONS_PRIVATE_DEPENDENCIES" "${args_PRIVATE}" + ) + set_or_append_target_property(${target} + "PROJECT_OPTIONS_PUBLIC_DEPENDENCIES" "${args_PUBLIC}" + ) + set_or_append_target_property(${target} + "PROJECT_OPTIONS_INTERFACE_DEPENDENCIES" "${args_INTERFACE}" ) endfunction() From fb5b4b53286e7c193d77290bb4b76af472d1dd01 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 15:43:49 +0800 Subject: [PATCH 076/139] Package includes and dependencies in property --- src/PackageProject.cmake | 49 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 5f282c01..8dd90631 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -2,6 +2,22 @@ include_guard() # Uses ycm (permissive BSD-3-Clause license) and ForwardArguments (permissive MIT license) +function(get_property_of_targets) + set(options) + set(one_value_args OUTPUT PROPERTY) + set(multi_value_args TARGETS) + cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + + set(value) + foreach(target IN LISTS args_TARGETS) + get_target_property(current_property ${target} ${args_PROPERTY}) + if (current_property) + list(APPEND value ${current_property}) + endif() + endforeach() + set(${args_OUTPUT} ${value}) +endfunction() + #[[.rst: .. include:: ../../docs/src/package_project.md @@ -89,8 +105,16 @@ function(package_project) # ycm args set(_PackageProject_INSTALL_DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") + # includes in target properties + get_property_of_targets(TARGETS ${_PackageProject_TARGETS} + PROPERTY PROJECT_OPTIONS_INTERFACE_DIRECTORY + OUTPUT _PackageProject_PROPERTY_INTERFACE_DIRECTORY + ) + # Installation of the public/interface includes - set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}") + set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" + "${_PackageProject_INTERFACE_INCLUDES}" + "${_PackageProject_PROPERTY_INTERFACE_DIRECTORY}") if(NOT "${_PackageProject_PUBLIC_INCLUDES}" STREQUAL @@ -110,9 +134,22 @@ function(package_project) endforeach() endif() + # public dependencies in target properties + get_property_of_targets(TARGETS ${_PackageProject_TARGETS} + PROPERTY PROJECT_OPTIONS_PUBLIC_DEPENDENCIES + OUTPUT _PackageProject_PROPERTY_PUBLIC_DEPENDENCIES + ) + # interface dependencies in target properties + get_property_of_targets(TARGETS ${_PackageProject_TARGETS} + PROPERTY PROJECT_OPTIONS_INTERFACE_DEPENDENCIES + OUTPUT _PackageProject_PROPERTY_INTERFACE_DEPENDENCIES + ) + # Append the configured public dependencies set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}") + "${_PackageProject_PROPERTY_PUBLIC_DEPENDENCIES}" + "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}" + "${_PackageProject_PROPERTY_INTERFACE_DEPENDENCIES}") if(NOT "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" STREQUAL @@ -126,7 +163,15 @@ function(package_project) # ycm arg set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} ${_PackageProject_INTERFACE_DEPENDENCIES}) + # private dependencies in target properties + get_property_of_targets(TARGETS ${_PackageProject_TARGETS} + PROPERTY PROJECT_OPTIONS_PRIVATE_DEPENDENCIES + OUTPUT _PackageProject_PROPERTY_PRIVATE_DEPENDENCIES + ) + # Append the configured private dependencies + set(_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" + "${_PackageProject_PROPERTY_PRIVATE_DEPENDENCIES}") if(NOT "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" STREQUAL From 271ca02eef2da0f34ad289c14a1a42e6e5d6f6fd Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 16:01:22 +0800 Subject: [PATCH 077/139] Enable include multiple directories in one call Fix OUTPUT to set in PARENT_SCOPE --- src/PackageProject.cmake | 66 ++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 8dd90631..61a6aa0a 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -15,7 +15,7 @@ function(get_property_of_targets) list(APPEND value ${current_property}) endif() endforeach() - set(${args_OUTPUT} ${value}) + set(${args_OUTPUT} ${value} PARENT_SCOPE) endfunction() #[[.rst: @@ -107,14 +107,14 @@ function(package_project) # includes in target properties get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY PROJECT_OPTIONS_INTERFACE_DIRECTORY - OUTPUT _PackageProject_PROPERTY_INTERFACE_DIRECTORY + PROPERTY PROJECT_OPTIONS_INTERFACE_DIRECTORIES + OUTPUT _PackageProject_PROPERTY_INTERFACE_DIRECTORIES ) # Installation of the public/interface includes set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}" - "${_PackageProject_PROPERTY_INTERFACE_DIRECTORY}") + "${_PackageProject_PROPERTY_INTERFACE_DIRECTORIES}") if(NOT "${_PackageProject_PUBLIC_INCLUDES}" STREQUAL @@ -269,37 +269,43 @@ endfunction() #[[.rst: -.. include:: ../../docs/src/target_include_interface_directory.md +.. include:: ../../docs/src/target_include_interface_directories.md :parser: myst_parser.sphinx_ #]] -function(target_include_interface_directory target include_dir) - # Make include_dir absolute - cmake_path(IS_RELATIVE include_dir is_relative) - if(is_relative) - set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}") - endif() - - # Append include_dir to target property PROJECT_OPTIONS_INTERFACE_DIRECTORY - set_or_append_target_property(${target} - "PROJECT_OPTIONS_INTERFACE_DIRECTORY" ${include_dir} - ) +function(target_include_interface_directories target) + function(target_include_interface_directory target include_dir) + # Make include_dir absolute + cmake_path(IS_RELATIVE include_dir is_relative) + if(is_relative) + set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}") + endif() - # Include the interface directory - get_target_property(has_source_files ${target} SOURCES) - if(NOT has_source_files) # header-only library, aka `add_library( INTERFACE)` - target_include_directories(${target} - INTERFACE - $ - $ - ) - else() - target_include_directories(${target} - PUBLIC - $ - $ + # Append include_dir to target property PROJECT_OPTIONS_INTERFACE_DIRECTORIES + set_or_append_target_property(${target} + "PROJECT_OPTIONS_INTERFACE_DIRECTORIES" ${include_dir} ) - endif() + + # Include the interface directory + get_target_property(has_source_files ${target} SOURCES) + if(NOT has_source_files) # header-only library, aka `add_library( INTERFACE)` + target_include_directories(${target} + INTERFACE + $ + $ + ) + else() + target_include_directories(${target} + PUBLIC + $ + $ + ) + endif() + endfunction() + + foreach(include_dir IN LISTS ARGN) + target_include_interface_directory(${target} ${include_dir}) + endforeach() endfunction() #[[.rst: From b12f62b13dfdb2f4e6d547202315bf83560f0ad9 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 16:25:51 +0800 Subject: [PATCH 078/139] Update docs to property version --- README.md | 11 ++------ docs/src/project_options_example.md | 11 ++------ docs/src/target_find_dependencies.md | 28 +++++++++++++------ .../target_include_interface_directories.md | 26 +++++++++++++++++ .../src/target_include_interface_directory.md | 22 --------------- 5 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 docs/src/target_include_interface_directories.md delete mode 100644 docs/src/target_include_interface_directory.md diff --git a/README.md b/README.md index 0b9a4409..8534b1e1 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings # Includes -target_include_interface_directory(my_header_lib) +target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_header_lib @@ -194,9 +194,6 @@ target_link_system_libraries(my_header_lib package_project( # Note that you must export `project_options` and `project_warnings` for `my_header_lib` TARGETS my_header_lib project_options project_warnings - # Just add these no matter whether dependencies exist. - INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} - INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} ) ``` @@ -207,7 +204,7 @@ add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings # Includes -target_include_interface_directory(my_lib) +target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_lib @@ -227,10 +224,6 @@ target_link_system_libraries(my_lib package_project( # Note that you must export `project_options` and `project_warnings` for `my_lib` TARGETS my_lib project_options project_warnings - # Just add these no matter whether dependencies exist. - INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} - PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} - PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index ac622292..a353ed9e 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -125,7 +125,7 @@ add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings # Includes -target_include_interface_directory(my_header_lib) +target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_header_lib @@ -145,9 +145,6 @@ target_link_system_libraries(my_header_lib package_project( # Note that you must export `project_options` and `project_warnings` for `my_header_lib` TARGETS my_header_lib project_options project_warnings - # Just add these no matter whether dependencies exist. - INTERFACE_DEPENDENCIES_CONFIGURED ${my_header_lib_INTERFACE_DEPENDENCIES} - INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} ) ``` @@ -158,7 +155,7 @@ add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings # Includes -target_include_interface_directory(my_lib) +target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_lib @@ -178,9 +175,5 @@ target_link_system_libraries(my_lib package_project( # Note that you must export `project_options` and `project_warnings` for `my_lib` TARGETS my_lib project_options project_warnings - # Just add these no matter whether dependencies exist. - INTERFACE_DEPENDENCIES_CONFIGURED ${my_lib_INTERFACE_DEPENDENCIES} - PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} - PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} ) ``` diff --git a/docs/src/target_find_dependencies.md b/docs/src/target_find_dependencies.md index b005bfeb..d5fdba4e 100644 --- a/docs/src/target_find_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -1,17 +1,32 @@ # `target_find_dependencies` function -This function `find_package(${dependency} REQUIRED)` for all dependencies required and binds them to the target. +```cmake +target_find_dependencies( + [INTERFACE [dependency ...]] + [PUBLIC [dependency ...]] + [PRIVATE [dependency ...]] +) +``` + +This function calls `find_package(${dependency} REQUIRED)` for all dependencies required and binds them to the target. + +Properties named `PROJECT_OPTIONS__DEPENDENCIES` will be created in `target_name` to represent corresponding dependencies. +When adding the target to `package_project`, directories in this property will be automatically added. -Variables `__DEPENDENCIES` will be created to represent corresponding dependencies. +You can call this function with the same `target_name` multiple times to add more dependencies. ```cmake add_library(my_lib) target_sources(my_lib PRIVATE function.cpp) -target_include_interface_directory(my_lib) +target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") target_find_dependencies(my_lib PUBLIC fmt + PRIVATE + Microsoft.GSL +) +target_find_dependencies(my_lib PRIVATE range-v3 ) @@ -20,12 +35,9 @@ target_link_system_libraries(my_lib PUBLIC fmt::fmt PRIVATE + Microsoft.GSL::GSL range-v3::range-v3 ) -package_project( - TARGETS my_lib - PUBLIC_DEPENDENCIES_CONFIGURED ${my_lib_PUBLIC_DEPENDENCIES} - PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} -) +package_project(TARGETS my_lib) ``` diff --git a/docs/src/target_include_interface_directories.md b/docs/src/target_include_interface_directories.md new file mode 100644 index 00000000..f94bccf3 --- /dev/null +++ b/docs/src/target_include_interface_directories.md @@ -0,0 +1,26 @@ +# `target_include_interface_directories` function + +```cmake +target_include_interface_directories( [ ...]) +``` + +This function includes `include_dir` as the header interface directory of `target_name`. +If the given `include_dir` path is relative, the function assumes the path is `${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}` +(i.e. the path is related to the path of CMakeLists.txt which calls the function). + +A property named `PROJECT_OPTIONS_INTERFACE_DIRECTORIES` will be created in `target_name` to represent the header directory path. +When adding the target to `package_project`, directories in this property will be automatically added. + +You can call this function with the same `target_name` multiple times to add more header interface directories. + +```cmake +add_library(my_header_lib INTERFACE) +target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_include_interface_directories(my_header_lib ../include) + +add_library(my_lib) +target_sources(my_lib PRIVATE function.cpp) +target_include_interface_directories(my_lib include ../include) + +package_project(TARGETS my_header_lib my_lib) +``` diff --git a/docs/src/target_include_interface_directory.md b/docs/src/target_include_interface_directory.md deleted file mode 100644 index 15bbd562..00000000 --- a/docs/src/target_include_interface_directory.md +++ /dev/null @@ -1,22 +0,0 @@ -# `target_include_interface_directory` function - -This function that includes `${CMAKE_CURRENT_SOURCE_DIR}/include` -(i.e. the `include` directory under the path of CMakeLists.txt which calls the function) -as the header directory of the target. - -A variable `_INTERFACE_DIRECTORY` will be created to represent the header directory path. - -```cmake -add_library(my_header_lib INTERFACE) -target_include_interface_directory(my_header_lib) - -add_library(my_lib) -target_sources(my_lib PRIVATE function.cpp) -target_include_interface_directory(my_lib) - -package_project( - TARGETS my_header_lib my_lib - PUBLIC_INCLUDES ${my_lib_INTERFACE_DIRECTORY} - INTERFACE_INCLUDES ${my_header_lib_INTERFACE_DIRECTORY} -) -``` From 420fd14f124ec7f44c85628dc48d1c5390e55392 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 16:40:24 +0800 Subject: [PATCH 079/139] Remove duplicated includes and dependencies Fix indentation Remove duplicates after group together --- src/PackageProject.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 61a6aa0a..ccc0fd6d 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -15,6 +15,7 @@ function(get_property_of_targets) list(APPEND value ${current_property}) endif() endforeach() + list(REMOVE_DUPLICATES current_property) set(${args_OUTPUT} ${value} PARENT_SCOPE) endfunction() @@ -150,6 +151,7 @@ function(package_project) "${_PackageProject_PROPERTY_PUBLIC_DEPENDENCIES}" "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}" "${_PackageProject_PROPERTY_INTERFACE_DEPENDENCIES}") + list(REMOVE_DUPLICATES _PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED) if(NOT "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" STREQUAL @@ -170,8 +172,9 @@ function(package_project) ) # Append the configured private dependencies - set(_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_PROPERTY_PRIVATE_DEPENDENCIES}") + set(_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" + "${_PackageProject_PROPERTY_PRIVATE_DEPENDENCIES}") + list(REMOVE_DUPLICATES _PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED) if(NOT "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" STREQUAL @@ -261,6 +264,7 @@ function(set_or_append_target_property target property new_values) else() list(APPEND all_values ${new_values}) endif() + list(REMOVE_DUPLICATES all_values) set_target_properties(${target} PROPERTIES ${property} "${all_values}" From ca03545692b383a5e6446011a8799a2cdc65123e Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 17:38:20 +0800 Subject: [PATCH 080/139] Seperate find_packge config and model mode Make comments more consistent --- README.md | 10 +-- docs/src/project_options_example.md | 10 +-- docs/src/target_find_dependencies.md | 13 ++-- src/PackageProject.cmake | 93 +++++++++++++++------------- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 8534b1e1..0dcf3f2e 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ target_link_libraries(main PRIVATE project_options project_warnings) # link proj # Find dependencies: target_find_dependencies(main - PRIVATE + PRIVATE_CONFIG fmt Eigen3 ) @@ -173,12 +173,12 @@ package_project(TARGETS main) add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings -# Includes +# Includes: target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_header_lib - INTERFACE + INTERFACE_CONFIG fmt Eigen3 ) @@ -203,12 +203,12 @@ package_project( add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings -# Includes +# Includes: target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_lib - PRIVATE + PRIVATE_CONFIG fmt Eigen3 ) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index a353ed9e..06e32f0c 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -102,7 +102,7 @@ target_link_libraries(main PRIVATE project_options project_warnings) # link proj # Find dependencies: target_find_dependencies(main - PRIVATE + PRIVATE_CONFIG fmt Eigen3 ) @@ -124,12 +124,12 @@ package_project(TARGETS main) add_library(my_header_lib INTERFACE) target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings -# Includes +# Includes: target_include_interface_directories(my_header_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_header_lib - INTERFACE + INTERFACE_CONFIG fmt Eigen3 ) @@ -154,12 +154,12 @@ package_project( add_library(my_lib "./src/my_lib/lib.cpp") target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings -# Includes +# Includes: target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") # Find dependencies: target_find_dependencies(my_lib - PRIVATE + PRIVATE_CONFIG fmt Eigen3 ) diff --git a/docs/src/target_find_dependencies.md b/docs/src/target_find_dependencies.md index d5fdba4e..036c72d8 100644 --- a/docs/src/target_find_dependencies.md +++ b/docs/src/target_find_dependencies.md @@ -5,12 +5,15 @@ target_find_dependencies( [INTERFACE [dependency ...]] [PUBLIC [dependency ...]] [PRIVATE [dependency ...]] + [INTERFACE_CONFIG [dependency ...]] + [PUBLIC_CONFIG [dependency ...]] + [PRIVATE_CONFIG [dependency ...]] ) ``` -This function calls `find_package(${dependency} REQUIRED)` for all dependencies required and binds them to the target. +This function calls `find_package(${dependency} [CONFIG] REQUIRED)` for all dependencies required and binds them to the target. -Properties named `PROJECT_OPTIONS__DEPENDENCIES` will be created in `target_name` to represent corresponding dependencies. +Properties named `PROJECT_OPTIONS_[_CONFIG]_DEPENDENCIES` will be created in `target_name` to represent corresponding dependencies. When adding the target to `package_project`, directories in this property will be automatically added. You can call this function with the same `target_name` multiple times to add more dependencies. @@ -21,13 +24,13 @@ target_sources(my_lib PRIVATE function.cpp) target_include_interface_directories(my_lib "${CMAKE_CURRENT_SOURCE_DIR}/include") target_find_dependencies(my_lib - PUBLIC + PUBLIC_CONFIG fmt - PRIVATE + PRIVATE_CONFIG Microsoft.GSL ) target_find_dependencies(my_lib - PRIVATE + PRIVATE_CONFIG range-v3 ) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index ccc0fd6d..649f2266 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -106,16 +106,25 @@ function(package_project) # ycm args set(_PackageProject_INSTALL_DESTINATION "${_PackageProject_CONFIG_INSTALL_DESTINATION}") - # includes in target properties - get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY PROJECT_OPTIONS_INTERFACE_DIRECTORIES - OUTPUT _PackageProject_PROPERTY_INTERFACE_DIRECTORIES - ) + # target properties + macro(_Get_property property) + get_property_of_targets(TARGETS ${_PackageProject_TARGETS} + PROPERTY "PROJECT_OPTIONS_${property}" + OUTPUT "PROPERTY_${property}" + ) + endmacro() + _Get_property(INTERFACE_INCLUDES) + _Get_property(INTERFACE_DEPENDENCIES) + _Get_property(PUBLIC_DEPENDENCIES) + _Get_property(PRIVATE_DEPENDENCIES) + _Get_property(INTERFACE_CONFIG_DEPENDENCIES) + _Get_property(PUBLIC_CONFIG_DEPENDENCIES) + _Get_property(PRIVATE_CONFIG_DEPENDENCIES) # Installation of the public/interface includes set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}" - "${_PackageProject_PROPERTY_INTERFACE_DIRECTORIES}") + "${PROPERTY_INTERFACE_DIRECTORIES}") if(NOT "${_PackageProject_PUBLIC_INCLUDES}" STREQUAL @@ -135,22 +144,11 @@ function(package_project) endforeach() endif() - # public dependencies in target properties - get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY PROJECT_OPTIONS_PUBLIC_DEPENDENCIES - OUTPUT _PackageProject_PROPERTY_PUBLIC_DEPENDENCIES - ) - # interface dependencies in target properties - get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY PROJECT_OPTIONS_INTERFACE_DEPENDENCIES - OUTPUT _PackageProject_PROPERTY_INTERFACE_DEPENDENCIES - ) - # Append the configured public dependencies set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_PROPERTY_PUBLIC_DEPENDENCIES}" + "${PROPERTY_PUBLIC_CONFIG_DEPENDENCIES}" "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_PROPERTY_INTERFACE_DEPENDENCIES}") + "${PROPERTY_INTERFACE_CONFIG_DEPENDENCIES}") list(REMOVE_DUPLICATES _PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED) if(NOT "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" @@ -161,19 +159,18 @@ function(package_project) list(APPEND _PUBLIC_DEPENDENCIES_CONFIG "${DEP} CONFIG") endforeach() endif() - list(APPEND _PackageProject_PUBLIC_DEPENDENCIES ${_PUBLIC_DEPENDENCIES_CONFIG}) + + list(APPEND _PackageProject_PUBLIC_DEPENDENCIES ${_PUBLIC_DEPENDENCIES_CONFIG} + ${PROPERTY_PUBLIC_DEPENDENCIES}) + # ycm arg - set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} ${_PackageProject_INTERFACE_DEPENDENCIES}) + set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} + ${_PackageProject_INTERFACE_DEPENDENCIES} + ${PROPERTY_INTERFACE_DEPENDENCIES}) - # private dependencies in target properties - get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY PROJECT_OPTIONS_PRIVATE_DEPENDENCIES - OUTPUT _PackageProject_PROPERTY_PRIVATE_DEPENDENCIES - ) - # Append the configured private dependencies set(_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" - "${_PackageProject_PROPERTY_PRIVATE_DEPENDENCIES}") + "${PROPERTY_PRIVATE_CONFIG_DEPENDENCIES}") list(REMOVE_DUPLICATES _PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED) if(NOT "${_PackageProject_PRIVATE_DEPENDENCIES_CONFIGURED}" @@ -185,7 +182,8 @@ function(package_project) endforeach() endif() # ycm arg - list(APPEND _PackageProject_PRIVATE_DEPENDENCIES ${_PRIVATE_DEPENDENCIES_CONFIG}) + list(APPEND _PackageProject_PRIVATE_DEPENDENCIES ${_PRIVATE_DEPENDENCIES_CONFIG} + ${PROPERTY_PRIVATE_DEPENDENCIES}) # Installation of package (compatible with vcpkg, etc) set(_targets_list ${_PackageProject_TARGETS}) @@ -321,21 +319,30 @@ endfunction() function(target_find_dependencies target) set(options) set(one_value_args) - set(multi_value_args PRIVATE PUBLIC INTERFACE) + set(multi_value_args PRIVATE PUBLIC INTERFACE PRIVATE_CONFIG PUBLIC_CONFIG INTERFACE_CONFIG) cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) - # Call find_package to all newly added dependencies - foreach(dependency IN LISTS args_PRIVATE args_PUBLIC args_INTERFACE) - find_package(${dependency} REQUIRED) - endforeach() + macro(_Property_for property) + # Call find_package to all newly added dependencies + foreach(dependency IN LISTS args_${property}) + if (${property} MATCHES ".*CONFIG") + find_package(${dependency} CONFIG REQUIRED) + else() + include(CMakeFindDependencyMacro) + find_dependency(${dependency}) + endif() + endforeach() - set_or_append_target_property(${target} - "PROJECT_OPTIONS_PRIVATE_DEPENDENCIES" "${args_PRIVATE}" - ) - set_or_append_target_property(${target} - "PROJECT_OPTIONS_PUBLIC_DEPENDENCIES" "${args_PUBLIC}" - ) - set_or_append_target_property(${target} - "PROJECT_OPTIONS_INTERFACE_DEPENDENCIES" "${args_INTERFACE}" - ) + # Append to target property + set_or_append_target_property(${target} + "PROJECT_OPTIONS_${property}_DEPENDENCIES" "${args_${property}}" + ) + endmacro() + + _Property_for(PRIVATE) + _Property_for(PUBLIC) + _Property_for(INTERFACE) + _Property_for(PRIVATE_CONFIG) + _Property_for(PUBLIC_CONFIG) + _Property_for(INTERFACE_CONFIG) endfunction() From fc15e80a4d2e4b918726d468ebf4f31ccf1d0fe2 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 29 Mar 2023 18:04:46 +0800 Subject: [PATCH 081/139] Resort the project's name convension --- src/PackageProject.cmake | 62 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 649f2266..ae624161 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -3,20 +3,20 @@ include_guard() # Uses ycm (permissive BSD-3-Clause license) and ForwardArguments (permissive MIT license) function(get_property_of_targets) - set(options) - set(one_value_args OUTPUT PROPERTY) - set(multi_value_args TARGETS) - cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) - - set(value) - foreach(target IN LISTS args_TARGETS) - get_target_property(current_property ${target} ${args_PROPERTY}) - if (current_property) - list(APPEND value ${current_property}) + set(_options) + set(_oneValueArgs OUTPUT PROPERTY) + set(_multiValueArgs TARGETS) + cmake_parse_arguments(args "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) + + set(_Value) + foreach(_Target IN LISTS args_TARGETS) + get_target_property(_Current_roperty ${_Target} ${args_PROPERTY}) + if (_Current_roperty) + list(APPEND _Value ${_Current_roperty}) endif() endforeach() - list(REMOVE_DUPLICATES current_property) - set(${args_OUTPUT} ${value} PARENT_SCOPE) + list(REMOVE_DUPLICATES _Current_roperty) + set(${args_OUTPUT} ${_Value} PARENT_SCOPE) endfunction() #[[.rst: @@ -255,17 +255,17 @@ function(package_project) endfunction() function(set_or_append_target_property target property new_values) - get_target_property(all_values ${target} ${property}) + get_target_property(_AllValues ${target} ${property}) - if(NOT all_values) # If the property hasn't set - set(all_values "${new_values}") + if(NOT _AllValues) # If the property hasn't set + set(_AllValues "${new_values}") else() - list(APPEND all_values ${new_values}) + list(APPEND _AllValues ${new_values}) endif() - list(REMOVE_DUPLICATES all_values) + list(REMOVE_DUPLICATES _AllValues) set_target_properties(${target} - PROPERTIES ${property} "${all_values}" + PROPERTIES ${property} "${_AllValues}" ) endfunction() @@ -278,8 +278,8 @@ endfunction() function(target_include_interface_directories target) function(target_include_interface_directory target include_dir) # Make include_dir absolute - cmake_path(IS_RELATIVE include_dir is_relative) - if(is_relative) + cmake_path(IS_RELATIVE include_dir _IsRelative) + if(_IsRelative) set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}") endif() @@ -289,8 +289,8 @@ function(target_include_interface_directories target) ) # Include the interface directory - get_target_property(has_source_files ${target} SOURCES) - if(NOT has_source_files) # header-only library, aka `add_library( INTERFACE)` + get_target_property(_HasSourceFiles ${target} SOURCES) + if(NOT _HasSourceFiles) # header-only library, aka `add_library( INTERFACE)` target_include_directories(${target} INTERFACE $ @@ -305,8 +305,8 @@ function(target_include_interface_directories target) endif() endfunction() - foreach(include_dir IN LISTS ARGN) - target_include_interface_directory(${target} ${include_dir}) + foreach(_IncludeDir IN LISTS ARGN) + target_include_interface_directory(${target} ${_IncludeDir}) endforeach() endfunction() @@ -317,19 +317,19 @@ endfunction() #]] function(target_find_dependencies target) - set(options) - set(one_value_args) - set(multi_value_args PRIVATE PUBLIC INTERFACE PRIVATE_CONFIG PUBLIC_CONFIG INTERFACE_CONFIG) - cmake_parse_arguments(args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + set(_options) + set(_oneValueArgs) + set(_MultiValueArgs PRIVATE PUBLIC INTERFACE PRIVATE_CONFIG PUBLIC_CONFIG INTERFACE_CONFIG) + cmake_parse_arguments(args "${_options}" "${_oneValueArgs}" "${_MultiValueArgs}" ${ARGN}) macro(_Property_for property) # Call find_package to all newly added dependencies - foreach(dependency IN LISTS args_${property}) + foreach(_Dependency IN LISTS args_${property}) if (${property} MATCHES ".*CONFIG") - find_package(${dependency} CONFIG REQUIRED) + find_package(${_Dependency} CONFIG REQUIRED) else() include(CMakeFindDependencyMacro) - find_dependency(${dependency}) + find_dependency(${_Dependency}) endif() endforeach() From 758c49fd9a8a3890b5c1a64f333a73cfe8d50957 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 30 Mar 2023 22:20:24 -0700 Subject: [PATCH 082/139] fix: fix the linting errors --- Taskfile.yml | 11 +- cspell.config.yaml | 17 ++- docker/Taskfile.yml | 10 +- docs/CMakeLists.txt | 4 +- docs/cmake/FindSphinx.cmake | 2 +- src/Common.cmake | 31 ++-- src/CrossCompiler.cmake | 66 ++++++--- src/Index.cmake | 1 - src/PackageProject.cmake | 136 ++++++++++-------- src/Vcpkg.cmake | 25 +++- src/toolchains/aarch64-linux.toolchain.cmake | 15 +- src/toolchains/arm-linux.toolchain.cmake | 15 +- src/toolchains/arm.toolchain.cmake | 15 +- src/toolchains/arm64-linux.toolchain.cmake | 15 +- .../i686-w64-mingw32.toolchain.cmake | 20 ++- .../x86_64-w64-mingw32.toolchain.cmake | 20 ++- tests/rpi3/CMakeLists.txt | 20 ++- tests/rpi3/main.c | 14 +- tests/rpi4-vcpkg/Taskfile.yml | 2 +- tests/rpi4/CMakeLists.txt | 18 ++- 20 files changed, 309 insertions(+), 148 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 736fbb9c..0b6eb85a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -60,11 +60,12 @@ tasks: - lint.cspell - lint.clang-format - lint.cmake - - myproj:lint - - install:lint - - minimal:lint - - emscripten:lint - - rpi4-vcpkg:lint + cmds: + - task: myproj:lint + - task: install:lint + - task: minimal:lint + - task: emscripten:lint + - task: rpi4-vcpkg:lint clean: - cmd: powershell -c 'function rmrf($path) { if (test-path $path) { rm -r -force $path }}; rmrf ./install' diff --git a/cspell.config.yaml b/cspell.config.yaml index 578690f5..a6f389a6 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -10,8 +10,6 @@ language: en, en-GB allowCompoundWords: true enableGlobDot: true words: - - awalsh - - pkgs - aarch - aminya - Amnet @@ -20,6 +18,7 @@ words: - ARGN - armv - asan + - awalsh - buildtools - ccache - ccmake @@ -42,11 +41,13 @@ words: - DDEFAULT_TRIPLET - deps - DOPT + - DVCPKG - dyld - dylib - eabi - egor-tensin - Eigen + - elif - emcc - emcmake - emscripten @@ -72,9 +73,11 @@ words: - LPWSTR - lrdimon - lstdc + - mathjax - mcpu - mdfile - mfpu + - moderncmakedomain - msbuild - msvc - msys @@ -87,13 +90,20 @@ words: - myprogram - myproj - myproject + - mypy - mythirdpartylib + - nojekyll + - nosys - nothrow - nvcc - Opencppcoverage - pargs + - pkgs - pnpm + - POSIX - pwsh + - qthelp + - riscv - rmrf - rpath - rtti @@ -103,9 +113,11 @@ words: - suppr - SYSROOT - tecolicom + - texi - TOLOWER - TOUPPER - ubsan + - undoc - vcpkg - vcvarsall - visualc @@ -131,5 +143,6 @@ words: - Wsign - Wunused - Wuseless + - Xcompiler - xcrun - Yahyaabadi diff --git a/docker/Taskfile.yml b/docker/Taskfile.yml index f0ace602..3330e0f6 100644 --- a/docker/Taskfile.yml +++ b/docker/Taskfile.yml @@ -17,7 +17,7 @@ tasks: - docker-compose up --build minimal-build-mingw-x64-from-triplet - docker-compose up --build minimal-build-mingw-x86 - docker-compose down - + emscripten: - docker-compose up --build build-emscripten - docker-compose down @@ -33,7 +33,7 @@ tasks: rpi3.bare-metal: - docker-compose up --build build-rpi3-bare-metal - docker-compose down - + rpi4: - docker-compose up --build build-rpi4 - docker-compose down @@ -49,7 +49,7 @@ tasks: rpi4.custom: - docker-compose up --build build-rpi4-custom - docker-compose down - + rpi4.aarch64: - docker-compose up --build build-rpi4-aarch64 - docker-compose down @@ -58,6 +58,6 @@ tasks: - docker-compose up --build build-rpi4-vcpkg - docker-compose down - rpi4.vcpkg-custsom: + rpi4.vcpkg-custom: - docker-compose up --build build-rpi4-vcpkg-custom - - docker-compose down \ No newline at end of file + - docker-compose down diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index cb69a39c..ca153cbd 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -51,7 +51,9 @@ set(conf_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VE set(conf_release "${PROJECT_VERSION}") set(conf_name "project_options") set(conf_author "Amin Yahyaabadi") -set(conf_brief "A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.") +set(conf_brief + "A general-purpose CMake library that provides functions that improve the CMake experience following the best practices." +) set(conf_doxygen_input "\ \"${CMAKE_SOURCE_DIR}/include\" \ diff --git a/docs/cmake/FindSphinx.cmake b/docs/cmake/FindSphinx.cmake index 0213242b..d1f67009 100644 --- a/docs/cmake/FindSphinx.cmake +++ b/docs/cmake/FindSphinx.cmake @@ -29,7 +29,7 @@ if(NOT SPHINX_EXECUTABLE) find_program( SPHINX_EXECUTABLE NAMES ${_sphinx_NAMES} - PATHS /usr/bin /usr/local/bin /opt/loca/bin + PATHS /usr/bin /usr/local/bin /opt/local/bin DOC "Sphinx documentation generator") endforeach() endif() diff --git a/src/Common.cmake b/src/Common.cmake index 8c985daf..13733f8f 100644 --- a/src/Common.cmake +++ b/src/Common.cmake @@ -80,26 +80,33 @@ macro(common_project_options) execute_process( COMMAND reg query "HKU\\S-1-5-19" ERROR_VARIABLE IS_NONADMINISTRATOR - OUTPUT_QUIET - ) + OUTPUT_QUIET) else() set(IS_NONADMINISTRATOR "") endif() if(IS_NONADMINISTRATOR) # For non-administrator, create an auxiliary target and ask user to run it - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/compile_commands.json - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json - DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json - VERBATIM - ) - add_custom_target(_copy_compile_commands - DEPENDS ${CMAKE_SOURCE_DIR}/compile_commands.json - VERBATIM + add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/compile_commands.json + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json + VERBATIM) + add_custom_target( + _copy_compile_commands + DEPENDS ${CMAKE_SOURCE_DIR}/compile_commands.json + VERBATIM) + message( + STATUS + "compile_commands.json was not symlinked to the root. Run `cmake --build -t _copy_compile_commands` if needed." ) - message(STATUS "compile_commands.json was not symlinked to the root. Run `cmake --build -t _copy_compile_commands` if needed.") else() - file(CREATE_LINK ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json SYMBOLIC) + file( + CREATE_LINK + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + SYMBOLIC) message(TRACE "compile_commands.json was symlinked to the root.") endif() diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index ba6c4370..0e6a25d4 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -18,12 +18,15 @@ macro(enable_cross_compiler) "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - + include("${ProjectOptions_SRC_DIR}/Utilities.cmake") detect_architecture(_arch) set(_default_triplet ${DEFAULT_TRIPLET}) - if(NOT "${EnableCrossCompiler_DEFAULT_TRIPLET}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_DEFAULT_TRIPLET}" + STREQUAL + "") set(_default_triplet ${EnableCrossCompiler_DEFAULT_TRIPLET}) endif() @@ -32,25 +35,40 @@ macro(enable_cross_compiler) endif() set(_cc ${CMAKE_C_COMPILER}) set(_cxx ${CMAKE_CXX_COMPILER}) - if(NOT "${EnableCrossCompiler_CC}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_CC}" + STREQUAL + "") set(_cc ${EnableCrossCompiler_CC}) endif() - if(NOT "${EnableCrossCompiler_CXX}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_CXX}" + STREQUAL + "") set(_cxx ${EnableCrossCompiler_CXX}) endif() set(_target_architecture ${TARGET_ARCHITECTURE}) - if(NOT "${EnableCrossCompiler_TARGET_ARCHITECTURE}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_TARGET_ARCHITECTURE}" + STREQUAL + "") set(_target_architecture ${EnableCrossCompiler_TARGET_ARCHITECTURE}) endif() - + set(_cross_root ${CROSS_ROOT}) - if(NOT "${EnableCrossCompiler_CROSS_ROOT}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_CROSS_ROOT}" + STREQUAL + "") set(_cross_root ${EnableCrossCompiler_CROSS_ROOT}) endif() - + set(_cross_triplet ${CROSS_TRIPLET}) - if(NOT "${EnableCrossCompiler_CROSS_TRIPLET}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_CROSS_TRIPLET}" + STREQUAL + "") set(_cross_triplet ${EnableCrossCompiler_CROSS_TRIPLET}) endif() @@ -176,7 +194,7 @@ macro(enable_cross_compiler) set(LIBRARY_LINKAGE "static") endif() endif() - + if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") if("${_cross_root}" STREQUAL "") set(_cross_root "/usr/x86_64-w64-mingw32") @@ -221,7 +239,11 @@ macro(enable_cross_compiler) set(USE_CROSSCOMPILER_ARM_NONE TRUE) endif() # TODO: check if path is right, check for header files or something - if(NOT "${_cross_root}" STREQUAL "" AND "${_cross_triplet}" STREQUAL "") + if(NOT + "${_cross_root}" + STREQUAL + "" + AND "${_cross_triplet}" STREQUAL "") message(WARNING "CROSS_ROOT (${_cross_root}) is set, but CROSS_TRIPLET is not") endif() @@ -270,7 +292,10 @@ macro(enable_cross_compiler) endif() set(_toolchain_file) - if(NOT "${EnableCrossCompiler_TOOLCHAIN_FILE}" STREQUAL "") + if(NOT + "${EnableCrossCompiler_TOOLCHAIN_FILE}" + STREQUAL + "") set(_toolchain_file ${EnableCrossCompiler_TOOLCHAIN_FILE}) else() get_toolchain_file(_toolchain_file) @@ -283,7 +308,7 @@ macro(enable_cross_compiler) set(CROSS_TOOLCHAIN_FILE ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}) endif() else() - set(CROSS_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}) + set(CROSS_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}) endif() set(CROSSCOMPILING TRUE) @@ -302,16 +327,25 @@ macro(enable_cross_compiler) #message(STATUS "EMSDK: $ENV{EMSDK}") message(STATUS "use emscripten cross-compiler emulator: ${CMAKE_CROSSCOMPILING_EMULATOR}") else() - if(NOT "${CROSS_ROOT}" STREQUAL "") + if(NOT + "${CROSS_ROOT}" + STREQUAL + "") message(STATUS "use SYSROOT: ${CROSS_ROOT}") endif() endif() message(STATUS "Target Architecture: ${TARGET_ARCHITECTURE}") - if(NOT "${DEFAULT_TRIPLET}" STREQUAL "") + if(NOT + "${DEFAULT_TRIPLET}" + STREQUAL + "") message(STATUS "Default Triplet: ${DEFAULT_TRIPLET}") endif() message(STATUS "Host Triplet: ${HOST_TRIPLET}") - if(NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") + if(NOT + "${CMAKE_TOOLCHAIN_FILE}" + STREQUAL + "") message(STATUS "Toolchain File: ${CMAKE_TOOLCHAIN_FILE}") else() if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) diff --git a/src/Index.cmake b/src/Index.cmake index b9021e7c..b5a3e374 100644 --- a/src/Index.cmake +++ b/src/Index.cmake @@ -37,7 +37,6 @@ msvc_toolchain() include("${CMAKE_CURRENT_LIST_DIR}/Conan.cmake") include("${CMAKE_CURRENT_LIST_DIR}/Vcpkg.cmake") - #[[.rst: .. include:: ../../docs/src/project_options.rst diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index ae624161..71ee0c15 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -6,17 +6,24 @@ function(get_property_of_targets) set(_options) set(_oneValueArgs OUTPUT PROPERTY) set(_multiValueArgs TARGETS) - cmake_parse_arguments(args "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) + cmake_parse_arguments( + args + "${_options}" + "${_oneValueArgs}" + "${_multiValueArgs}" + ${ARGN}) set(_Value) foreach(_Target IN LISTS args_TARGETS) - get_target_property(_Current_roperty ${_Target} ${args_PROPERTY}) - if (_Current_roperty) - list(APPEND _Value ${_Current_roperty}) + get_target_property(_Current_property ${_Target} ${args_PROPERTY}) + if(_Current_property) + list(APPEND _Value ${_Current_property}) endif() endforeach() - list(REMOVE_DUPLICATES _Current_roperty) - set(${args_OUTPUT} ${_Value} PARENT_SCOPE) + list(REMOVE_DUPLICATES _Current_property) + set(${args_OUTPUT} + ${_Value} + PARENT_SCOPE) endfunction() #[[.rst: @@ -108,22 +115,24 @@ function(package_project) # target properties macro(_Get_property property) - get_property_of_targets(TARGETS ${_PackageProject_TARGETS} - PROPERTY "PROJECT_OPTIONS_${property}" - OUTPUT "PROPERTY_${property}" - ) + get_property_of_targets( + TARGETS + ${_PackageProject_TARGETS} + PROPERTY + "PROJECT_OPTIONS_${property}" + OUTPUT + "PROPERTY_${property}") endmacro() - _Get_property(INTERFACE_INCLUDES) - _Get_property(INTERFACE_DEPENDENCIES) - _Get_property(PUBLIC_DEPENDENCIES) - _Get_property(PRIVATE_DEPENDENCIES) - _Get_property(INTERFACE_CONFIG_DEPENDENCIES) - _Get_property(PUBLIC_CONFIG_DEPENDENCIES) - _Get_property(PRIVATE_CONFIG_DEPENDENCIES) + _get_property(INTERFACE_INCLUDES) + _get_property(INTERFACE_DEPENDENCIES) + _get_property(PUBLIC_DEPENDENCIES) + _get_property(PRIVATE_DEPENDENCIES) + _get_property(INTERFACE_CONFIG_DEPENDENCIES) + _get_property(PUBLIC_CONFIG_DEPENDENCIES) + _get_property(PRIVATE_CONFIG_DEPENDENCIES) # Installation of the public/interface includes - set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" - "${_PackageProject_INTERFACE_INCLUDES}" + set(_PackageProject_PUBLIC_INCLUDES "${_PackageProject_PUBLIC_INCLUDES}" "${_PackageProject_INTERFACE_INCLUDES}" "${PROPERTY_INTERFACE_DIRECTORIES}") if(NOT "${_PackageProject_PUBLIC_INCLUDES}" @@ -145,10 +154,11 @@ function(package_project) endif() # Append the configured public dependencies - set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" - "${PROPERTY_PUBLIC_CONFIG_DEPENDENCIES}" - "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}" - "${PROPERTY_INTERFACE_CONFIG_DEPENDENCIES}") + set(_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED + "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" + "${PROPERTY_PUBLIC_CONFIG_DEPENDENCIES}" + "${_PackageProject_INTERFACE_DEPENDENCIES_CONFIGURED}" + "${PROPERTY_INTERFACE_CONFIG_DEPENDENCIES}") list(REMOVE_DUPLICATES _PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED) if(NOT "${_PackageProject_PUBLIC_DEPENDENCIES_CONFIGURED}" @@ -160,12 +170,14 @@ function(package_project) endforeach() endif() - list(APPEND _PackageProject_PUBLIC_DEPENDENCIES ${_PUBLIC_DEPENDENCIES_CONFIG} - ${PROPERTY_PUBLIC_DEPENDENCIES}) + list( + APPEND + _PackageProject_PUBLIC_DEPENDENCIES + ${_PUBLIC_DEPENDENCIES_CONFIG} + ${PROPERTY_PUBLIC_DEPENDENCIES}) # ycm arg - set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} - ${_PackageProject_INTERFACE_DEPENDENCIES} + set(_PackageProject_DEPENDENCIES ${_PackageProject_PUBLIC_DEPENDENCIES} ${_PackageProject_INTERFACE_DEPENDENCIES} ${PROPERTY_INTERFACE_DEPENDENCIES}) # Append the configured private dependencies @@ -182,8 +194,11 @@ function(package_project) endforeach() endif() # ycm arg - list(APPEND _PackageProject_PRIVATE_DEPENDENCIES ${_PRIVATE_DEPENDENCIES_CONFIG} - ${PROPERTY_PRIVATE_DEPENDENCIES}) + list( + APPEND + _PackageProject_PRIVATE_DEPENDENCIES + ${_PRIVATE_DEPENDENCIES_CONFIG} + ${PROPERTY_PRIVATE_DEPENDENCIES}) # Installation of package (compatible with vcpkg, etc) set(_targets_list ${_PackageProject_TARGETS}) @@ -254,7 +269,11 @@ function(package_project) include("${_ycm_SOURCE_DIR}/modules/AddUninstallTarget.cmake") endfunction() -function(set_or_append_target_property target property new_values) +function( + set_or_append_target_property + target + property + new_values) get_target_property(_AllValues ${target} ${property}) if(NOT _AllValues) # If the property hasn't set @@ -264,9 +283,7 @@ function(set_or_append_target_property target property new_values) endif() list(REMOVE_DUPLICATES _AllValues) - set_target_properties(${target} - PROPERTIES ${property} "${_AllValues}" - ) + set_target_properties(${target} PROPERTIES ${property} "${_AllValues}") endfunction() #[[.rst: @@ -284,24 +301,16 @@ function(target_include_interface_directories target) endif() # Append include_dir to target property PROJECT_OPTIONS_INTERFACE_DIRECTORIES - set_or_append_target_property(${target} - "PROJECT_OPTIONS_INTERFACE_DIRECTORIES" ${include_dir} - ) - + set_or_append_target_property(${target} "PROJECT_OPTIONS_INTERFACE_DIRECTORIES" ${include_dir}) + # Include the interface directory get_target_property(_HasSourceFiles ${target} SOURCES) if(NOT _HasSourceFiles) # header-only library, aka `add_library( INTERFACE)` - target_include_directories(${target} - INTERFACE - $ - $ - ) + target_include_directories(${target} INTERFACE $ + $) else() - target_include_directories(${target} - PUBLIC - $ - $ - ) + target_include_directories(${target} PUBLIC $ + $) endif() endfunction() @@ -319,13 +328,24 @@ endfunction() function(target_find_dependencies target) set(_options) set(_oneValueArgs) - set(_MultiValueArgs PRIVATE PUBLIC INTERFACE PRIVATE_CONFIG PUBLIC_CONFIG INTERFACE_CONFIG) - cmake_parse_arguments(args "${_options}" "${_oneValueArgs}" "${_MultiValueArgs}" ${ARGN}) + set(_MultiValueArgs + PRIVATE + PUBLIC + INTERFACE + PRIVATE_CONFIG + PUBLIC_CONFIG + INTERFACE_CONFIG) + cmake_parse_arguments( + args + "${_options}" + "${_oneValueArgs}" + "${_MultiValueArgs}" + ${ARGN}) macro(_Property_for property) # Call find_package to all newly added dependencies foreach(_Dependency IN LISTS args_${property}) - if (${property} MATCHES ".*CONFIG") + if(${property} MATCHES ".*CONFIG") find_package(${_Dependency} CONFIG REQUIRED) else() include(CMakeFindDependencyMacro) @@ -334,15 +354,13 @@ function(target_find_dependencies target) endforeach() # Append to target property - set_or_append_target_property(${target} - "PROJECT_OPTIONS_${property}_DEPENDENCIES" "${args_${property}}" - ) + set_or_append_target_property(${target} "PROJECT_OPTIONS_${property}_DEPENDENCIES" "${args_${property}}") endmacro() - _Property_for(PRIVATE) - _Property_for(PUBLIC) - _Property_for(INTERFACE) - _Property_for(PRIVATE_CONFIG) - _Property_for(PUBLIC_CONFIG) - _Property_for(INTERFACE_CONFIG) + _property_for(PRIVATE) + _property_for(PUBLIC) + _property_for(INTERFACE) + _property_for(PRIVATE_CONFIG) + _property_for(PUBLIC_CONFIG) + _property_for(INTERFACE_CONFIG) endfunction() diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 164d7888..945ef229 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -119,26 +119,41 @@ macro(run_vcpkg) if(CROSSCOMPILING) if(NOT MINGW) - if(NOT "${TARGET_ARCHITECTURE}" STREQUAL "") + if(NOT + "${TARGET_ARCHITECTURE}" + STREQUAL + "") set(VCPKG_TARGET_TRIPLET "${TARGET_ARCHITECTURE}") endif() - if(NOT "${DEFAULT_TRIPLET}" STREQUAL "") + if(NOT + "${DEFAULT_TRIPLET}" + STREQUAL + "") set(VCPKG_DEFAULT_TRIPLET "${DEFAULT_TRIPLET}") endif() - if(NOT "${LIBRARY_LINKAGE}" STREQUAL "") + if(NOT + "${LIBRARY_LINKAGE}" + STREQUAL + "") set(VCPKG_LIBRARY_LINKAGE "${LIBRARY_LINKAGE}") endif() endif() if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) set(_toolchain_file) - if(NOT "${CROSS_TOOLCHAIN_FILE}" STREQUAL "") + if(NOT + "${CROSS_TOOLCHAIN_FILE}" + STREQUAL + "") set(_toolchain_file ${CROSS_TOOLCHAIN_FILE}) else() get_toolchain_file(_toolchain_file) endif() - if(NOT "${_toolchain_file}" STREQUAL "") + if(NOT + "${_toolchain_file}" + STREQUAL + "") set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${_toolchain_file} CACHE STRING "vcpkg chainload toolchain file" FORCE) diff --git a/src/toolchains/aarch64-linux.toolchain.cmake b/src/toolchains/aarch64-linux.toolchain.cmake index 48c8f095..9375b6d4 100644 --- a/src/toolchains/aarch64-linux.toolchain.cmake +++ b/src/toolchains/aarch64-linux.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +14,18 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) diff --git a/src/toolchains/arm-linux.toolchain.cmake b/src/toolchains/arm-linux.toolchain.cmake index 08d19d62..d825c7b1 100644 --- a/src/toolchains/arm-linux.toolchain.cmake +++ b/src/toolchains/arm-linux.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +14,18 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) diff --git a/src/toolchains/arm.toolchain.cmake b/src/toolchains/arm.toolchain.cmake index e3f1962c..1d3021ee 100644 --- a/src/toolchains/arm.toolchain.cmake +++ b/src/toolchains/arm.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +14,18 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) diff --git a/src/toolchains/arm64-linux.toolchain.cmake b/src/toolchains/arm64-linux.toolchain.cmake index c23aef9c..6b5eb479 100644 --- a/src/toolchains/arm64-linux.toolchain.cmake +++ b/src/toolchains/arm64-linux.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm64) -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,12 +14,18 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/${CROSS_TRIPLET}) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER ${CROSS_TRIPLET}-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER ${CROSS_TRIPLET}-g++) diff --git a/src/toolchains/i686-w64-mingw32.toolchain.cmake b/src/toolchains/i686-w64-mingw32.toolchain.cmake index 9c807703..ac8139cb 100644 --- a/src/toolchains/i686-w64-mingw32.toolchain.cmake +++ b/src/toolchains/i686-w64-mingw32.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "i686") -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,17 +14,26 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) endif() -if(NOT "${CROSS_RC}" STREQUAL "") +if(NOT + "${CROSS_RC}" + STREQUAL + "") set(CMAKE_RC_COMPILER ${CROSS_RC}) else() set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) diff --git a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake index 243f0c96..6a916324 100644 --- a/src/toolchains/x86_64-w64-mingw32.toolchain.cmake +++ b/src/toolchains/x86_64-w64-mingw32.toolchain.cmake @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR "x64") -if(NOT "${CROSS_ROOT}" STREQUAL "") +if(NOT + "${CROSS_ROOT}" + STREQUAL + "") set(CMAKE_SYSROOT ${CROSS_ROOT}) #set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) elseif("${CMAKE_SYSROOT}" STREQUAL "") @@ -11,17 +14,26 @@ elseif("${CMAKE_SYSROOT}" STREQUAL "") #set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) endif() -if(NOT "${CROSS_C}" STREQUAL "") +if(NOT + "${CROSS_C}" + STREQUAL + "") set(CMAKE_C_COMPILER ${CROSS_C}) else() set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) endif() -if(NOT "${CROSS_CXX}" STREQUAL "") +if(NOT + "${CROSS_CXX}" + STREQUAL + "") set(CMAKE_CXX_COMPILER ${CROSS_CXX}) else() set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) endif() -if(NOT "${CROSS_RC}" STREQUAL "") +if(NOT + "${CROSS_RC}" + STREQUAL + "") set(CMAKE_RC_COMPILER ${CROSS_RC}) else() set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) diff --git a/tests/rpi3/CMakeLists.txt b/tests/rpi3/CMakeLists.txt index bba143c3..e5cd864a 100644 --- a/tests/rpi3/CMakeLists.txt +++ b/tests/rpi3/CMakeLists.txt @@ -16,18 +16,24 @@ include(../../src/Index.cmake) if(ENABLE_BARE_METAL_CROSS_COMPILING) # my custom arm settings enable_cross_compiler( - CC "arm-none-eabi-gcc" - CXX "arm-none-eabi-g++" - TARGET_ARCHITECTURE "arm" - CROSS_ROOT "/usr/arm-none-eabi-gcc" - CROSS_TRIPLET "arm-none-eabi" - ) + CC + "arm-none-eabi-gcc" + CXX + "arm-none-eabi-g++" + TARGET_ARCHITECTURE + "arm" + CROSS_ROOT + "/usr/arm-none-eabi-gcc" + CROSS_TRIPLET + "arm-none-eabi") # some more custom compiler settings # -Wl,--gc-sections Perform the dead code elimination. # --specs=nano.specs Link with newlib-nano. # --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. - set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb" CACHE INTERNAL "Linker options") + set(CMAKE_EXE_LINKER_FLAGS + "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb" + CACHE INTERNAL "Linker options") else() option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) if(ENABLE_CROSS_COMPILING) diff --git a/tests/rpi3/main.c b/tests/rpi3/main.c index 1b12d56d..bfb7d28e 100644 --- a/tests/rpi3/main.c +++ b/tests/rpi3/main.c @@ -5,11 +5,11 @@ char uart_getc() { return 'a'; } void uart_puts(char *s) {} void main() { - uart_init(); - - uart_puts("Hello World!\n"); - - while(1) { - uart_send(uart_getc()); - } + uart_init(); + + uart_puts("Hello World!\n"); + + while (1) { + uart_send(uart_getc()); + } } \ No newline at end of file diff --git a/tests/rpi4-vcpkg/Taskfile.yml b/tests/rpi4-vcpkg/Taskfile.yml index b410198a..b895615d 100644 --- a/tests/rpi4-vcpkg/Taskfile.yml +++ b/tests/rpi4-vcpkg/Taskfile.yml @@ -19,4 +19,4 @@ tasks: CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE={{.CWD}}/tests/rpi4-vcpkg/cmake/my-toolchain.cmake -DDEFAULT_TRIPLET=arm64-linux lint: - - ~/vcpkg/vcpkg format-manifest ./vcpkg.json \ No newline at end of file + - ~/vcpkg/vcpkg format-manifest ./vcpkg.json diff --git a/tests/rpi4/CMakeLists.txt b/tests/rpi4/CMakeLists.txt index b53f000e..71748b41 100644 --- a/tests/rpi4/CMakeLists.txt +++ b/tests/rpi4/CMakeLists.txt @@ -16,12 +16,18 @@ include(../../src/Index.cmake) if(ENABLE_AARCH64_CROSS_COMPILING) # my custom aarch64 settings enable_cross_compiler( - DEFAULT_TRIPLET "arm64-linux" - CC "aarch64-linux-gnu-gcc" - CXX "aarch64-linux-gnu-g++" - TARGET_ARCHITECTURE "arm64-linux" - CROSS_ROOT "/usr/gcc-aarch64-linux-gnu" - CROSS_TRIPLET "aarch64-linux-gnu" + DEFAULT_TRIPLET + "arm64-linux" + CC + "aarch64-linux-gnu-gcc" + CXX + "aarch64-linux-gnu-g++" + TARGET_ARCHITECTURE + "arm64-linux" + CROSS_ROOT + "/usr/gcc-aarch64-linux-gnu" + CROSS_TRIPLET + "aarch64-linux-gnu" #TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/my-toolchain.cmake" ) else() From 8f0296b7479f49874412bebed445f3cbb6855e79 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 30 Mar 2023 22:24:20 -0700 Subject: [PATCH 083/139] fix: improve the version switcher script --- docs/root/index.html | 1 - docs/root/js/version_switcher.js | 68 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/docs/root/index.html b/docs/root/index.html index 156e4991..9d8b0f69 100644 --- a/docs/root/index.html +++ b/docs/root/index.html @@ -14,7 +14,6 @@