From 8187a2c2b00928ec0d8162373a759e03f9d0427a Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 25 Feb 2024 22:40:26 +0100 Subject: [PATCH 01/57] Add GNUmakefile and .CMakeUserPresets.json make format all files --- .CMakeUserPresets.json | 118 +++++++++++++++++++++++++++++++ .envrc | 8 +++ CMakeLists.txt | 57 +++++++-------- CMakePresets.json | 3 +- GNUmakefile | 31 ++++++++ HACKING.md | 23 +++++- cmake/coverage.cmake | 32 +++------ cmake/dev-mode.cmake | 3 +- cmake/docs-ci.cmake | 25 ++++--- cmake/docs.cmake | 31 ++++---- cmake/install-rules.cmake | 63 ++++++----------- cmake/lint-targets.cmake | 44 ++++++------ cmake/lint.cmake | 20 +++--- cmake/prelude.cmake | 9 ++- cmake/project-is-top-level.cmake | 6 +- cmake/spell-targets.cmake | 25 +++---- cmake/spell.cmake | 6 +- cmake/variables.cmake | 12 ++-- conanfile.py | 4 +- example/CMakeLists.txt | 2 +- test/CMakeLists.txt | 6 +- 21 files changed, 320 insertions(+), 208 deletions(-) create mode 100644 .CMakeUserPresets.json create mode 100644 .envrc create mode 100644 GNUmakefile diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json new file mode 100644 index 0000000..4514730 --- /dev/null +++ b/.CMakeUserPresets.json @@ -0,0 +1,118 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 28, + "patch": 0 + }, + "configurePresets": [ + { + "name": "dev-common", + "hidden": true, + "inherits": [ + "dev-mode", + "conan", + "clang-tidy", + "cppcheck" + ], + "generator": "Ninja", + "cacheVariables": { + "BUILD_MCSS_DOCS": false, + "BUILD_SHARED_LIBS": true + } + }, + { + "name": "dev-linux", + "binaryDir": "${sourceDir}/build/dev-linux", + "inherits": [ + "dev-common", + "ci-linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "dev-darwin", + "binaryDir": "${sourceDir}/build/dev-darwin", + "inherits": [ + "dev-common", + "ci-darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "dev-win64", + "binaryDir": "${sourceDir}/build/dev-win64", + "inherits": [ + "dev-common", + "ci-win64" + ], + "environment": { + "UseMultiToolTask": "true", + "EnforceProcessCountAcrossBuilds": "true" + } + }, + { + "name": "dev", + "binaryDir": "${sourceDir}/build/dev", + "generator": "Ninja", + "inherits": "dev-darwin" + }, + { + "name": "dev-coverage", + "binaryDir": "${sourceDir}/build/coverage", + "generator": "Ninja", + "inherits": [ + "dev-mode", + "coverage-linux", + "conan" + ] + } + ], + "buildPresets": [ + { + "name": "dev", + "configurePreset": "dev", + "configuration": "Debug", + "jobs": 12 + } + ], + "testPresets": [ + { + "name": "dev", + "configurePreset": "dev", + "configuration": "Debug", + "output": { + "outputOnFailure": true + }, + "execution": { + "jobs": 12, + "noTestsAction": "error" + } + } + ], + "workflowPresets": [ + { + "name": "dev", + "steps": [ + { + "type": "configure", + "name": "dev" + }, + { + "type": "build", + "name": "dev" + }, + { + "type": "test", + "name": "dev" + } + ] + } + ] +} diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..dbea97b --- /dev/null +++ b/.envrc @@ -0,0 +1,8 @@ +export CMAKE_EXPORT_COMPILE_COMMANDS=YES +export CPM_USE_LOCAL_PACKAGES=YES +export CPM_SOURCE_CACHE="${HOME}/.cache/CPM" + +export PATH="/usr/local/opt/llvm/bin:$PATH" +export CXX=`which clang++-17` +export CC=`which clang-17` + diff --git a/CMakeLists.txt b/CMakeLists.txt index c24065f..49a0e12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,12 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.28) include(cmake/prelude.cmake) -project( - cmake-init-modules - VERSION 0.1.0 - DESCRIPTION "Short description" - HOMEPAGE_URL "https://example.com/" - LANGUAGES CXX +project(cmake-init-modules + VERSION 0.1.0 + DESCRIPTION "Short description" + HOMEPAGE_URL "https://example.com/" + LANGUAGES CXX ) include(cmake/project-is-top-level.cmake) @@ -15,18 +14,18 @@ include(cmake/variables.cmake) # ---- Declare library ---- -add_library( - cmake-init-modules_cmake-init-modules - source/cmake-init-modules.cpp -) +add_library(cmake-init-modules_cmake-init-modules source/cmake-init-modules.cpp) add_library(cmake-init-modules::cmake-init-modules ALIAS cmake-init-modules_cmake-init-modules) include(GenerateExportHeader) generate_export_header( - cmake-init-modules_cmake-init-modules - BASE_NAME cmake-init-modules - EXPORT_FILE_NAME export/cmake-init-modules/cmake-init-modules_export.hpp - CUSTOM_CONTENT_FROM_VARIABLE pragma_suppress_c4251 + cmake-init-modules_cmake-init-modules + BASE_NAME + cmake-init-modules + EXPORT_FILE_NAME + export/cmake-init-modules/cmake-init-modules_export.hpp + CUSTOM_CONTENT_FROM_VARIABLE + pragma_suppress_c4251 ) if(NOT BUILD_SHARED_LIBS) @@ -34,25 +33,21 @@ if(NOT BUILD_SHARED_LIBS) endif() set_target_properties( - cmake-init-modules_cmake-init-modules PROPERTIES - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN YES - VERSION "${PROJECT_VERSION}" - SOVERSION "${PROJECT_VERSION_MAJOR}" - EXPORT_NAME cmake-init-modules - OUTPUT_NAME cmake-init-modules + cmake-init-modules_cmake-init-modules + PROPERTIES CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN YES + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + EXPORT_NAME cmake-init-modules + OUTPUT_NAME cmake-init-modules ) target_include_directories( - cmake-init-modules_cmake-init-modules ${warning_guard} - PUBLIC - "$" + cmake-init-modules_cmake-init-modules ${warning_guard} PUBLIC "$" ) target_include_directories( - cmake-init-modules_cmake-init-modules SYSTEM - PUBLIC - "$" + cmake-init-modules_cmake-init-modules SYSTEM PUBLIC "$" ) target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) @@ -67,6 +62,7 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) endif() # ---- Examples ---- +enable_testing() if(PROJECT_IS_TOP_LEVEL) option(BUILD_EXAMPLES "Build examples tree." "${cmake-init-modules_DEVELOPER_MODE}") @@ -80,10 +76,7 @@ endif() if(NOT cmake-init-modules_DEVELOPER_MODE) return() elseif(NOT PROJECT_IS_TOP_LEVEL) - message( - AUTHOR_WARNING - "Developer mode is intended for developers of cmake-init-modules" - ) + message(AUTHOR_WARNING "Developer mode is intended for developers of cmake-init-modules") endif() include(cmake/dev-mode.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index 133bda3..0c0e634 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,7 +2,7 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 25, + "minor": 28, "patch": 0 }, "configurePresets": [ @@ -33,6 +33,7 @@ "name": "conan", "hidden": true, "cacheVariables": { + "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Release;Debug", "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/conan_toolchain.cmake", "CMAKE_POLICY_DEFAULT_CMP0091": "NEW" } diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..851a0b4 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,31 @@ +# Standard stuff + +.SUFFIXES: +$(VERBOSE).SILENT: + +MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. +MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. +MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk). + +.PHONY: all clean distclean check format + +all: conan + cmake --workflow --preset dev # --fresh + cmake --build --preset dev --target install + +check:all + -run-clang-tidy -p build/dev + +conan: conanfile.py + -conan install . -s build_type=Debug -b missing + +clean: + rm -rf build + +distclean: + rm -rf conan stagedir + # git clean -xdf + +format: + find . -name CMakeLists.txt -o -name '*.cmake' | xargs cmake-format -i + git clang-format master diff --git a/HACKING.md b/HACKING.md index 2825248..5034f12 100644 --- a/HACKING.md +++ b/HACKING.md @@ -31,10 +31,10 @@ the project: ```json { - "version": 2, + "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 14, + "minor": 28, "patch": 0 }, "configurePresets": [ @@ -63,6 +63,25 @@ the project: "outputOnFailure": true } } + ], + "workflowPresets": [ + { + "name": "dev", + "steps": [ + { + "type": "configure", + "name": "dev" + }, + { + "type": "build", + "name": "dev" + }, + { + "type": "test", + "name": "dev" + } + ] + } ] } ``` diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index c89cc16..5f3a32d 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -2,32 +2,22 @@ # We use variables separate from what CTest uses, because those have # customization issues -set( - COVERAGE_TRACE_COMMAND - lcov -c -q - -o "${PROJECT_BINARY_DIR}/coverage.info" - -d "${PROJECT_BINARY_DIR}" - --include "${PROJECT_SOURCE_DIR}/*" - CACHE STRING - "; separated command to generate a trace for the 'coverage' target" +set(COVERAGE_TRACE_COMMAND lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d "${PROJECT_BINARY_DIR}" --include + "${PROJECT_SOURCE_DIR}/*" + CACHE STRING "; separated command to generate a trace for the 'coverage' target" ) -set( - COVERAGE_HTML_COMMAND - genhtml --legend -f -q - "${PROJECT_BINARY_DIR}/coverage.info" - -p "${PROJECT_SOURCE_DIR}" - -o "${PROJECT_BINARY_DIR}/coverage_html" - CACHE STRING - "; separated command to generate an HTML report for the 'coverage' target" +set(COVERAGE_HTML_COMMAND genhtml --legend -f -q "${PROJECT_BINARY_DIR}/coverage.info" -p "${PROJECT_SOURCE_DIR}" -o + "${PROJECT_BINARY_DIR}/coverage_html" + CACHE STRING "; separated command to generate an HTML report for the 'coverage' target" ) # ---- Coverage target ---- add_custom_target( - coverage - COMMAND ${COVERAGE_TRACE_COMMAND} - COMMAND ${COVERAGE_HTML_COMMAND} - COMMENT "Generating coverage report" - VERBATIM + coverage + COMMAND ${COVERAGE_TRACE_COMMAND} + COMMAND ${COVERAGE_HTML_COMMAND} + COMMENT "Generating coverage report" + VERBATIM ) diff --git a/cmake/dev-mode.cmake b/cmake/dev-mode.cmake index 0011f5c..867adec 100644 --- a/cmake/dev-mode.cmake +++ b/cmake/dev-mode.cmake @@ -1,6 +1,7 @@ include(cmake/folders.cmake) -include(CTest) +#XXX include(CTest) +option(BUILD_TESTING "" ${PROJECT_IS_TOP_LEVEL}) if(BUILD_TESTING) add_subdirectory(test) endif() diff --git a/cmake/docs-ci.cmake b/cmake/docs-ci.cmake index ae7f0c7..ca00cee 100644 --- a/cmake/docs-ci.cmake +++ b/cmake/docs-ci.cmake @@ -13,20 +13,14 @@ set(src "${PROJECT_SOURCE_DIR}") set(mcss_SOURCE_DIR "${bin}/docs/.ci") if(NOT IS_DIRECTORY "${mcss_SOURCE_DIR}") file(MAKE_DIRECTORY "${mcss_SOURCE_DIR}") - file( - DOWNLOAD - https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip - "${mcss_SOURCE_DIR}/mcss.zip" - STATUS status - EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f + file(DOWNLOAD https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip "${mcss_SOURCE_DIR}/mcss.zip" + STATUS status EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f ) if(NOT status MATCHES "^0;") message(FATAL_ERROR "Download failed with ${status}") endif() execute_process( - COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip - WORKING_DIRECTORY "${mcss_SOURCE_DIR}" - RESULT_VARIABLE result + COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip WORKING_DIRECTORY "${mcss_SOURCE_DIR}" RESULT_VARIABLE result ) if(NOT result EQUAL "0") message(FATAL_ERROR "Extraction failed with ${result}") @@ -63,7 +57,14 @@ macro(list_pop_front list out) endmacro() function(docs_project name) - cmake_parse_arguments(PARSE_ARGV 1 "" "" "VERSION;DESCRIPTION;HOMEPAGE_URL" LANGUAGES) + cmake_parse_arguments( + PARSE_ARGV + 1 + "" + "" + "VERSION;DESCRIPTION;HOMEPAGE_URL" + LANGUAGES + ) set(PROJECT_NAME "${name}" PARENT_SCOPE) if(DEFINED _VERSION) set(PROJECT_VERSION "${_VERSION}" PARENT_SCOPE) @@ -103,9 +104,7 @@ set(config "${bin}/docs/conf.py") file(REMOVE_RECURSE "${out}/html" "${out}/xml") execute_process( - COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" - WORKING_DIRECTORY "${bin}/docs" - RESULT_VARIABLE result + COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" WORKING_DIRECTORY "${bin}/docs" RESULT_VARIABLE result ) if(NOT result EQUAL "0") message(FATAL_ERROR "m.css returned with ${result}") diff --git a/cmake/docs.cmake b/cmake/docs.cmake index c6cdda6..5f41772 100644 --- a/cmake/docs.cmake +++ b/cmake/docs.cmake @@ -7,12 +7,12 @@ endif() include(FetchContent) FetchContent_Declare( - mcss URL - https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip - URL_MD5 00cd2757ebafb9bcba7f5d399b3bec7f - SOURCE_DIR "${PROJECT_BINARY_DIR}/mcss" - UPDATE_DISCONNECTED YES - ${extract_timestamps} + mcss + URL https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip + URL_MD5 00cd2757ebafb9bcba7f5d399b3bec7f + SOURCE_DIR "${PROJECT_BINARY_DIR}/mcss" + UPDATE_DISCONNECTED YES + ${extract_timestamps} ) FetchContent_MakeAvailable(mcss) @@ -20,10 +20,7 @@ find_package(Python3 3.6 REQUIRED) # ---- Declare documentation target ---- -set( - DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" - CACHE PATH "Path for the generated Doxygen documentation" -) +set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" CACHE PATH "Path for the generated Doxygen documentation") set(working_dir "${PROJECT_BINARY_DIR}/docs") @@ -35,12 +32,10 @@ set(mcss_script "${mcss_SOURCE_DIR}/documentation/doxygen.py") set(config "${working_dir}/conf.py") add_custom_target( - docs - COMMAND "${CMAKE_COMMAND}" -E remove_directory - "${DOXYGEN_OUTPUT_DIRECTORY}/html" - "${DOXYGEN_OUTPUT_DIRECTORY}/xml" - COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" - COMMENT "Building documentation using Doxygen and m.css" - WORKING_DIRECTORY "${working_dir}" - VERBATIM + docs + COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOXYGEN_OUTPUT_DIRECTORY}/html" "${DOXYGEN_OUTPUT_DIRECTORY}/xml" + COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" + COMMENT "Building documentation using Doxygen and m.css" + WORKING_DIRECTORY "${working_dir}" + VERBATIM ) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 4b349ba..1ac4156 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -1,8 +1,5 @@ if(PROJECT_IS_TOP_LEVEL) - set( - CMAKE_INSTALL_INCLUDEDIR "include/cmake-init-modules-${PROJECT_VERSION}" - CACHE PATH "" - ) + set(CMAKE_INSTALL_INCLUDEDIR "include/cmake-init-modules-${PROJECT_VERSION}" CACHE PATH "") endif() include(CMakePackageConfigHelpers) @@ -11,58 +8,40 @@ include(GNUInstallDirs) # find_package() call for consumers to find this project set(package cmake-init-modules) -install( - DIRECTORY - include/ - "${PROJECT_BINARY_DIR}/export/" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT cmake-init-modules_Development +install(DIRECTORY include/ "${PROJECT_BINARY_DIR}/export/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT cmake-init-modules_Development ) -install( - TARGETS cmake-init-modules_cmake-init-modules - EXPORT cmake-init-modulesTargets - RUNTIME # - COMPONENT cmake-init-modules_Runtime - LIBRARY # - COMPONENT cmake-init-modules_Runtime - NAMELINK_COMPONENT cmake-init-modules_Development - ARCHIVE # - COMPONENT cmake-init-modules_Development - INCLUDES # - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +install(TARGETS cmake-init-modules_cmake-init-modules + EXPORT cmake-init-modulesTargets + RUNTIME # + COMPONENT cmake-init-modules_Runtime + LIBRARY # + COMPONENT cmake-init-modules_Runtime NAMELINK_COMPONENT cmake-init-modules_Development + ARCHIVE # + COMPONENT cmake-init-modules_Development + INCLUDES # + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) -write_basic_package_version_file( - "${package}ConfigVersion.cmake" - COMPATIBILITY SameMajorVersion -) +write_basic_package_version_file("${package}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion) # Allow package maintainers to freely override the path for the configs -set( - cmake-init-modules_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" +set(cmake-init-modules_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" CACHE PATH "CMake package config location relative to the install prefix" ) mark_as_advanced(cmake-init-modules_INSTALL_CMAKEDIR) -install( - FILES cmake/install-config.cmake - DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - RENAME "${package}Config.cmake" - COMPONENT cmake-init-modules_Development +install(FILES cmake/install-config.cmake DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" + RENAME "${package}Config.cmake" COMPONENT cmake-init-modules_Development ) -install( - FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake" - DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - COMPONENT cmake-init-modules_Development +install(FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake" DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" + COMPONENT cmake-init-modules_Development ) -install( - EXPORT cmake-init-modulesTargets - NAMESPACE cmake-init-modules:: - DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - COMPONENT cmake-init-modules_Development +install(EXPORT cmake-init-modulesTargets NAMESPACE cmake-init-modules:: + DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" COMPONENT cmake-init-modules_Development ) if(PROJECT_IS_TOP_LEVEL) diff --git a/cmake/lint-targets.cmake b/cmake/lint-targets.cmake index 244d521..1f0324a 100644 --- a/cmake/lint-targets.cmake +++ b/cmake/lint-targets.cmake @@ -1,34 +1,30 @@ -set( - FORMAT_PATTERNS - source/*.cpp source/*.hpp +set(FORMAT_PATTERNS + source/*.cpp + source/*.hpp include/*.hpp - test/*.cpp test/*.hpp - example/*.cpp example/*.hpp - CACHE STRING - "; separated patterns relative to the project source dir to format" + test/*.cpp + test/*.hpp + example/*.cpp + example/*.hpp + CACHE STRING "; separated patterns relative to the project source dir to format" ) set(FORMAT_COMMAND clang-format CACHE STRING "Formatter to use") add_custom_target( - format-check - COMMAND "${CMAKE_COMMAND}" - -D "FORMAT_COMMAND=${FORMAT_COMMAND}" - -D "PATTERNS=${FORMAT_PATTERNS}" - -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMENT "Linting the code" - VERBATIM + format-check + COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -P + "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMENT "Linting the code" + VERBATIM ) add_custom_target( - format-fix - COMMAND "${CMAKE_COMMAND}" - -D "FORMAT_COMMAND=${FORMAT_COMMAND}" - -D "PATTERNS=${FORMAT_PATTERNS}" - -D FIX=YES - -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMENT "Fixing the code" - VERBATIM + format-fix + COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -D FIX=YES -P + "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMENT "Fixing the code" + VERBATIM ) diff --git a/cmake/lint.cmake b/cmake/lint.cmake index c0d2725..3f25809 100644 --- a/cmake/lint.cmake +++ b/cmake/lint.cmake @@ -7,12 +7,14 @@ macro(default name) endmacro() default(FORMAT_COMMAND clang-format) -default( - PATTERNS - source/*.cpp source/*.hpp - include/*.hpp - test/*.cpp test/*.hpp - example/*.cpp example/*.hpp +default(PATTERNS + source/*.cpp + source/*.hpp + include/*.hpp + test/*.cpp + test/*.hpp + example/*.cpp + example/*.hpp ) default(FIX NO) @@ -30,10 +32,8 @@ string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length) foreach(file IN LISTS files) execute_process( - COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result - ${args} + COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE result ${args} ) if(NOT result EQUAL "0") message(FATAL_ERROR "'${file}': formatter returned with ${result}") diff --git a/cmake/prelude.cmake b/cmake/prelude.cmake index c37d590..91bf95b 100644 --- a/cmake/prelude.cmake +++ b/cmake/prelude.cmake @@ -1,10 +1,9 @@ # ---- In-source guard ---- if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) - message( - FATAL_ERROR - "In-source builds are not supported. " - "Please read the BUILDING document before trying to build this project. " - "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." + message(FATAL_ERROR + "In-source builds are not supported. " + "Please read the BUILDING document before trying to build this project. " + "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." ) endif() diff --git a/cmake/project-is-top-level.cmake b/cmake/project-is-top-level.cmake index 3435fc0..0b169e5 100644 --- a/cmake/project-is-top-level.cmake +++ b/cmake/project-is-top-level.cmake @@ -1,6 +1,2 @@ # This variable is set by project() in CMake 3.21+ -string( - COMPARE EQUAL - "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" - PROJECT_IS_TOP_LEVEL -) +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" PROJECT_IS_TOP_LEVEL) diff --git a/cmake/spell-targets.cmake b/cmake/spell-targets.cmake index 0c21cab..c919f95 100644 --- a/cmake/spell-targets.cmake +++ b/cmake/spell-targets.cmake @@ -1,22 +1,17 @@ set(SPELL_COMMAND codespell CACHE STRING "Spell checker to use") add_custom_target( - spell-check - COMMAND "${CMAKE_COMMAND}" - -D "SPELL_COMMAND=${SPELL_COMMAND}" - -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMENT "Checking spelling" - VERBATIM + spell-check + COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMENT "Checking spelling" + VERBATIM ) add_custom_target( - spell-fix - COMMAND "${CMAKE_COMMAND}" - -D "SPELL_COMMAND=${SPELL_COMMAND}" - -D FIX=YES - -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - COMMENT "Fixing spelling errors" - VERBATIM + spell-fix + COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -D FIX=YES -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMENT "Fixing spelling errors" + VERBATIM ) diff --git a/cmake/spell.cmake b/cmake/spell.cmake index e05ecd7..e1dfb70 100644 --- a/cmake/spell.cmake +++ b/cmake/spell.cmake @@ -14,11 +14,7 @@ if(FIX) set(flag -w) endif() -execute_process( - COMMAND "${SPELL_COMMAND}" ${flag} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result -) +execute_process(COMMAND "${SPELL_COMMAND}" ${flag} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE result) if(result EQUAL "65") message(FATAL_ERROR "Run again with FIX=YES to fix these errors.") diff --git a/cmake/variables.cmake b/cmake/variables.cmake index c9452ad..5905157 100644 --- a/cmake/variables.cmake +++ b/cmake/variables.cmake @@ -12,14 +12,16 @@ endif() # ---- Suppress C4251 on Windows ---- # Please see include/cmake-init-modules/cmake-init-modules.hpp for more details -set(pragma_suppress_c4251 " +set(pragma_suppress_c4251 + " /* This needs to suppress only for MSVC */ #if defined(_MSC_VER) && !defined(__ICL) # define CMAKE_INIT_MODULES_SUPPRESS_C4251 _Pragma(\"warning(suppress:4251)\") #else # define CMAKE_INIT_MODULES_SUPPRESS_C4251 #endif -") +" +) # ---- Warning guard ---- @@ -29,10 +31,8 @@ set(pragma_suppress_c4251 " # add_subdirectory or FetchContent is used to consume this project set(warning_guard "") if(NOT PROJECT_IS_TOP_LEVEL) - option( - cmake-init-modules_INCLUDES_WITH_SYSTEM - "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" - ON + option(cmake-init-modules_INCLUDES_WITH_SYSTEM + "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" ON ) mark_as_advanced(cmake-init-modules_INCLUDES_WITH_SYSTEM) if(cmake-init-modules_INCLUDES_WITH_SYSTEM) diff --git a/conanfile.py b/conanfile.py index ac1e4bf..07313e9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,7 +9,7 @@ def layout(self): self.folders.generators = "conan" def requirements(self): - self.requires("fmt/10.0.0") + self.requires("fmt/10.2.1") def build_requirements(self): - self.test_requires("catch2/3.3.2") + self.test_requires("catch2/3.5.2") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 36cb59b..6b63452 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.28) project(cmake-init-modulesExamples CXX) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 754f06d..47aa8d3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,11 +18,7 @@ include(Catch) # ---- Tests ---- add_executable(cmake-init-modules_test source/cmake-init-modules_test.cpp) -target_link_libraries( - cmake-init-modules_test PRIVATE - cmake-init-modules::cmake-init-modules - Catch2::Catch2WithMain -) +target_link_libraries(cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules Catch2::Catch2WithMain) target_compile_features(cmake-init-modules_test PRIVATE cxx_std_20) catch_discover_tests(cmake-init-modules_test) From 2d622526c50f873c3691d7e397a11cd5c2ba73ca Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 26 Feb 2024 08:19:22 +0100 Subject: [PATCH 02/57] I use git flow, develop is the default branch --- .envrc | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.envrc b/.envrc index dbea97b..453a95a 100644 --- a/.envrc +++ b/.envrc @@ -3,6 +3,6 @@ export CPM_USE_LOCAL_PACKAGES=YES export CPM_SOURCE_CACHE="${HOME}/.cache/CPM" export PATH="/usr/local/opt/llvm/bin:$PATH" -export CXX=`which clang++-17` +export CXX=`which clang++` export CC=`which clang-17` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84b8307..e06ca44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,10 @@ on: push: branches: - master + - develop pull_request: branches: - - master - develop jobs: From eef3d937e5a2de6cd88b925f8ec5480230f4733a Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 26 Feb 2024 10:18:16 +0100 Subject: [PATCH 03/57] Use conan profile in GNUmakefile create conan profile if missing update conan profile from GNUmakefile if needed --- .gitignore | 1 + .notes.txt | 26 ++++++++++++++++++++++++++ GNUmakefile | 27 ++++++++++++++++++++++----- HACKING.md | 1 + 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .notes.txt diff --git a/.gitignore b/.gitignore index d0d6dae..e036a5f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build/ cmake-build-*/ conan/ prefix/ +stagedir/ .clangd CMakeLists.txt.user CMakeUserPresets.json diff --git a/.notes.txt b/.notes.txt new file mode 100644 index 0000000..e224806 --- /dev/null +++ b/.notes.txt @@ -0,0 +1,26 @@ +bash-5.2$ cmake-init -s -p conan --std 20 --examples cmake-init-modules +Initialized empty Git repository in /Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/cmake-init-modules/.git/ + +The project is ready to be used with git. If you are using GitHub, you may +push the project with the following commands from the project directory: + + git add . + git commit -m "Initial commit" + git flow init -d + git remote add origin https://github.com//.git + git push -u origin master + +To get started with developing the project, make sure you read the generated +HACKING.md and BUILDING.md files for how to build the project as a developer or +as a user respectively. There are also some details you may want to fill in in +the README.md, CONTRIBUTING.md and .github/workflows/ci.yml files. + +Now make sure you have at least CMake 3.20 installed for local development, to +make use of all the nice Quality-of-Life improvements in newer releases: +https://cmake.org/download/ + +For more tips, like integration with package managers, please see the Wiki: +https://github.com/friendlyanon/cmake-init/wiki + +You are all set. Have fun programming and create something awesome! +bash-5.2$ diff --git a/GNUmakefile b/GNUmakefile index 851a0b4..de03fe8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,24 +7,41 @@ MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk). +# export CC=gcc-13 +# export CXX=g++-13 +export CC=clang-17 +export CXX=clang++-17 +export CMAKE_EXPORT_COMPILE_COMMANDS=YES + +CONAN_HOME=$(shell conan config home) +# BUILD_TYPE=Release +BUILD_TYPE=Debug + .PHONY: all clean distclean check format all: conan - cmake --workflow --preset dev # --fresh - cmake --build --preset dev --target install + # TODO: if needed: cmake --preset dev --fresh --debug-find-pkg=fmt + cmake --workflow --preset dev # XXX --fresh + cmake --install build/dev --prefix $(CURDIR)/stagedir + # TODO: cpack --list-presets check:all -run-clang-tidy -p build/dev -conan: conanfile.py - -conan install . -s build_type=Debug -b missing +conan: conanfile.py GNUmakefile + conan profile detect -f + # test -e $(CONAN_HOME)/profiles/clang-17 || cp -n $(CONAN_HOME)/profiles/default $(CONAN_HOME)/profiles/clang-17 + test -e $(CONAN_HOME)/profiles/${CC} || \ + perl -p -e 's/(compiler.cppstd)=.*$$/$$1=20/;' -e 's/(build_type)=.*$$/$$1=$(BUILD_TYPE)/;' \ + $(CONAN_HOME)/profiles/default > $(CONAN_HOME)/profiles/${CC} + conan install --profile ${CC} . -s build_type=$(BUILD_TYPE) -b missing clean: rm -rf build distclean: rm -rf conan stagedir - # git clean -xdf + # XXX NO! git clean -xdf format: find . -name CMakeLists.txt -o -name '*.cmake' | xargs cmake-format -i diff --git a/HACKING.md b/HACKING.md index 5034f12..1fc0e99 100644 --- a/HACKING.md +++ b/HACKING.md @@ -41,6 +41,7 @@ the project: { "name": "dev", "binaryDir": "${sourceDir}/build/dev", + "generator": "Ninja", "inherits": ["dev-mode", "conan", "ci-"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" From 03e8c7106972ef9f2dc0c16458ec94bc2c3ad6dc Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 26 Feb 2024 23:23:51 +0100 Subject: [PATCH 04/57] Use PUBLIC FILE_SET HEADERS --- .CMakeUserPresets.json | 4 +-- .github/workflows/ci.yml | 46 ++++++++++++++++---------- CMakeLists.txt | 56 ++++++++++++++++++++------------ CMakePresets.json | 44 ++++++++++++------------- GNUmakefile | 19 ++++++----- cmake/coverage.cmake | 21 +++++++----- cmake/dev-mode.cmake | 2 +- cmake/docs-ci.cmake | 49 ++++++++++++++++------------ cmake/docs.cmake | 13 ++++---- cmake/folders.cmake | 15 +++++++-- cmake/install-rules.cmake | 50 ++++++++++++++++------------ cmake/lint-targets.cmake | 25 +++++++------- cmake/lint.cmake | 24 +++++++------- cmake/prelude.cmake | 10 +++--- cmake/project-is-top-level.cmake | 3 +- cmake/spell-targets.cmake | 16 +++++---- cmake/spell.cmake | 5 ++- cmake/variables.cmake | 22 ++++++------- example/CMakeLists.txt | 11 +++++-- example/empty_example.cpp | 5 +++ test/CMakeLists.txt | 4 ++- 21 files changed, 265 insertions(+), 179 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 4514730..5ca8352 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -12,8 +12,7 @@ "inherits": [ "dev-mode", "conan", - "clang-tidy", - "cppcheck" + "clang-tidy" ], "generator": "Ninja", "cacheVariables": { @@ -50,6 +49,7 @@ "binaryDir": "${sourceDir}/build/dev-win64", "inherits": [ "dev-common", + "cppcheck", "ci-win64" ], "environment": { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e06ca44..c57d1e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-14 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-15 -P cmake/lint.cmake - name: Spell check if: always() @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: | - pip3 install conan + pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -82,7 +82,7 @@ jobs: runs-on: ubuntu-22.04 - env: { CXX: clang++-14 } + env: { CXX: clang++-15 } steps: - uses: actions/checkout@v4 @@ -93,7 +93,7 @@ jobs: - name: Install dependencies run: | - pip3 install conan + pip3 install conan cmake ninja bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -121,7 +121,7 @@ jobs: fail-fast: false matrix: - os: [macos-13, ubuntu-22.04, windows-2022] + os: [macos-14, ubuntu-22.04, windows-2022] type: [shared, static] @@ -134,23 +134,35 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install static analyzers - if: matrix.os == 'ubuntu-22.04' - run: >- - sudo apt-get install clang-tidy-14 cppcheck -y -q - - sudo update-alternatives --install - /usr/bin/clang-tidy clang-tidy - /usr/bin/clang-tidy-14 140 + - name: Setup Cpp + if: matrix.os != 'windows-2022' + uses: aminya/setup-cpp@v1 + with: + compiler: llvm-17.0.6 + vcvarsall: ${{ contains(matrix.os, 'windows') }} + # conan: true + # vcpkg: true + clangformat: true + clangtidy: true + # ... + + # - name: Install static analyzers + # if: matrix.os == 'ubuntu-22.04' + # run: >- + # sudo apt-get install clang-tidy-15 cppcheck -y -q + + # sudo update-alternatives --install + # /usr/bin/clang-tidy clang-tidy + # /usr/bin/clang-tidy-15 140 - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: { python-version: "3.10" } - name: Install dependencies shell: bash run: | - pip3 install conan + pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -204,11 +216,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: { python-version: "3.10" } - name: Install m.css dependencies - run: pip3 install jinja2 Pygments + run: pip3 install jinja2 Pygments cmake ninja - name: Install Doxygen run: sudo apt-get update -q diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a0e12..60128b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.28) include(cmake/prelude.cmake) -project(cmake-init-modules - VERSION 0.1.0 - DESCRIPTION "Short description" - HOMEPAGE_URL "https://example.com/" - LANGUAGES CXX -) +project( + cmake-init-modules + VERSION 0.1.0 + DESCRIPTION "Short description" + HOMEPAGE_URL "https://example.com/" + LANGUAGES CXX) include(cmake/project-is-top-level.cmake) include(cmake/variables.cmake) @@ -15,7 +15,8 @@ include(cmake/variables.cmake) # ---- Declare library ---- add_library(cmake-init-modules_cmake-init-modules source/cmake-init-modules.cpp) -add_library(cmake-init-modules::cmake-init-modules ALIAS cmake-init-modules_cmake-init-modules) +add_library(cmake-init-modules::cmake-init-modules ALIAS + cmake-init-modules_cmake-init-modules) include(GenerateExportHeader) generate_export_header( @@ -25,11 +26,26 @@ generate_export_header( EXPORT_FILE_NAME export/cmake-init-modules/cmake-init-modules_export.hpp CUSTOM_CONTENT_FROM_VARIABLE - pragma_suppress_c4251 + pragma_suppress_c4251) + +configure_file(include/cmake-init-modules/cmake-init-modules.hpp + export/cmake-init-modules/cmake-init-modules.hpp COPYONLY) + +# cmake-format: off +target_sources( + cmake-init-modules_cmake-init-modules + PUBLIC FILE_SET HEADERS + BASE_DIRS + ${PROJECT_BINARY_DIR}/export + FILES + ${PROJECT_BINARY_DIR}/export/cmake-init-modules/cmake-init-modules.hpp + ${PROJECT_BINARY_DIR}/export/cmake-init-modules/cmake-init-modules_export.hpp ) +# cmake-format: on if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(cmake-init-modules_cmake-init-modules PUBLIC CMAKE_INIT_MODULES_STATIC_DEFINE) + target_compile_definitions(cmake-init-modules_cmake-init-modules + PUBLIC CMAKE_INIT_MODULES_STATIC_DEFINE) endif() set_target_properties( @@ -39,16 +55,13 @@ set_target_properties( VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" EXPORT_NAME cmake-init-modules - OUTPUT_NAME cmake-init-modules -) - -target_include_directories( - cmake-init-modules_cmake-init-modules ${warning_guard} PUBLIC "$" -) + OUTPUT_NAME cmake-init-modules) -target_include_directories( - cmake-init-modules_cmake-init-modules SYSTEM PUBLIC "$" -) +# target_include_directories( cmake-init-modules_cmake-init-modules +# ${warning_guard} PUBLIC "$" ) +# +# target_include_directories( cmake-init-modules_cmake-init-modules SYSTEM +# PUBLIC "$" ) target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) @@ -65,7 +78,8 @@ endif() enable_testing() if(PROJECT_IS_TOP_LEVEL) - option(BUILD_EXAMPLES "Build examples tree." "${cmake-init-modules_DEVELOPER_MODE}") + option(BUILD_EXAMPLES "Build examples tree." + "${cmake-init-modules_DEVELOPER_MODE}") if(BUILD_EXAMPLES) add_subdirectory(example) endif() @@ -76,7 +90,9 @@ endif() if(NOT cmake-init-modules_DEVELOPER_MODE) return() elseif(NOT PROJECT_IS_TOP_LEVEL) - message(AUTHOR_WARNING "Developer mode is intended for developers of cmake-init-modules") + message( + AUTHOR_WARNING + "Developer mode is intended for developers of cmake-init-modules") endif() include(cmake/dev-mode.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index 0c0e634..b1f2868 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -69,6 +69,11 @@ "CMAKE_CXX_FLAGS": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast", "CMAKE_EXE_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now", "CMAKE_SHARED_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" } }, { @@ -76,6 +81,11 @@ "hidden": true, "cacheVariables": { "CMAKE_CXX_FLAGS": "-fstack-protector-strong -fcf-protection=full -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" } }, { @@ -86,7 +96,13 @@ "CMAKE_CXX_FLAGS": "/sdl /guard:cf /utf-8 /diagnostics:caret /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44365 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc", "CMAKE_EXE_LINKER_FLAGS": "/machine:x64 /guard:cf", "CMAKE_SHARED_LINKER_FLAGS": "/machine:x64 /guard:cf" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" } + }, { "name": "ci-linux", @@ -166,7 +182,7 @@ "binaryDir": "${sourceDir}/build", "hidden": true, "cacheVariables": { - "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Release;Debug;" + "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Release;Debug" } }, { @@ -176,12 +192,7 @@ "ci-darwin", "dev-mode", "conan" - ], - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - } + ] }, { "name": "ci-ubuntu", @@ -189,15 +200,9 @@ "ci-build", "ci-linux", "clang-tidy", - "conan", - "cppcheck", - "dev-mode" - ], - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - } + "dev-mode", + "conan" + ] }, { "name": "ci-windows", @@ -206,12 +211,7 @@ "ci-win64", "dev-mode", "conan" - ], - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } + ] } ] } diff --git a/GNUmakefile b/GNUmakefile index de03fe8..a82d8d2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -10,14 +10,14 @@ MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefi # export CC=gcc-13 # export CXX=g++-13 export CC=clang-17 -export CXX=clang++-17 +export CXX=$(shell which clang++) export CMAKE_EXPORT_COMPILE_COMMANDS=YES CONAN_HOME=$(shell conan config home) # BUILD_TYPE=Release BUILD_TYPE=Debug -.PHONY: all clean distclean check format +.PHONY: all clean distclean check format test all: conan # TODO: if needed: cmake --preset dev --fresh --debug-find-pkg=fmt @@ -25,16 +25,19 @@ all: conan cmake --install build/dev --prefix $(CURDIR)/stagedir # TODO: cpack --list-presets -check:all +test: all + cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -D 'CMAKE_PREFIX_PATH=$(CURDIR)/stagedir;$(CURDIR)/conan' \ + --toolchain $(CURDIR)/conan/conan_toolchain.cmake --debug-find-pkg=fmt + ninja -C example/build + ninja -C example/build test + +check: test -run-clang-tidy -p build/dev conan: conanfile.py GNUmakefile conan profile detect -f - # test -e $(CONAN_HOME)/profiles/clang-17 || cp -n $(CONAN_HOME)/profiles/default $(CONAN_HOME)/profiles/clang-17 - test -e $(CONAN_HOME)/profiles/${CC} || \ - perl -p -e 's/(compiler.cppstd)=.*$$/$$1=20/;' -e 's/(build_type)=.*$$/$$1=$(BUILD_TYPE)/;' \ - $(CONAN_HOME)/profiles/default > $(CONAN_HOME)/profiles/${CC} - conan install --profile ${CC} . -s build_type=$(BUILD_TYPE) -b missing + conan install . -s build_type=$(BUILD_TYPE) -s compiler.cppstd=20 -b missing clean: rm -rf build diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index 5f3a32d..a0277c0 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -2,14 +2,18 @@ # We use variables separate from what CTest uses, because those have # customization issues -set(COVERAGE_TRACE_COMMAND lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d "${PROJECT_BINARY_DIR}" --include - "${PROJECT_SOURCE_DIR}/*" - CACHE STRING "; separated command to generate a trace for the 'coverage' target" -) +set(COVERAGE_TRACE_COMMAND + lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d + "${PROJECT_BINARY_DIR}" --include "${PROJECT_SOURCE_DIR}/*" + CACHE STRING + "; separated command to generate a trace for the 'coverage' target") -set(COVERAGE_HTML_COMMAND genhtml --legend -f -q "${PROJECT_BINARY_DIR}/coverage.info" -p "${PROJECT_SOURCE_DIR}" -o - "${PROJECT_BINARY_DIR}/coverage_html" - CACHE STRING "; separated command to generate an HTML report for the 'coverage' target" +set(COVERAGE_HTML_COMMAND + genhtml --legend -f -q "${PROJECT_BINARY_DIR}/coverage.info" -p + "${PROJECT_SOURCE_DIR}" -o "${PROJECT_BINARY_DIR}/coverage_html" + CACHE + STRING + "; separated command to generate an HTML report for the 'coverage' target" ) # ---- Coverage target ---- @@ -19,5 +23,4 @@ add_custom_target( COMMAND ${COVERAGE_TRACE_COMMAND} COMMAND ${COVERAGE_HTML_COMMAND} COMMENT "Generating coverage report" - VERBATIM -) + VERBATIM) diff --git a/cmake/dev-mode.cmake b/cmake/dev-mode.cmake index 867adec..25b3c98 100644 --- a/cmake/dev-mode.cmake +++ b/cmake/dev-mode.cmake @@ -1,6 +1,6 @@ include(cmake/folders.cmake) -#XXX include(CTest) +# XXX include(CTest) option(BUILD_TESTING "" ${PROJECT_IS_TOP_LEVEL}) if(BUILD_TESTING) add_subdirectory(test) diff --git a/cmake/docs-ci.cmake b/cmake/docs-ci.cmake index ca00cee..8c7371a 100644 --- a/cmake/docs-ci.cmake +++ b/cmake/docs-ci.cmake @@ -13,15 +13,19 @@ set(src "${PROJECT_SOURCE_DIR}") set(mcss_SOURCE_DIR "${bin}/docs/.ci") if(NOT IS_DIRECTORY "${mcss_SOURCE_DIR}") file(MAKE_DIRECTORY "${mcss_SOURCE_DIR}") - file(DOWNLOAD https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip "${mcss_SOURCE_DIR}/mcss.zip" - STATUS status EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f - ) + file( + DOWNLOAD + https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip + "${mcss_SOURCE_DIR}/mcss.zip" + STATUS status + EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f) if(NOT status MATCHES "^0;") message(FATAL_ERROR "Download failed with ${status}") endif() execute_process( - COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip WORKING_DIRECTORY "${mcss_SOURCE_DIR}" RESULT_VARIABLE result - ) + COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip + WORKING_DIRECTORY "${mcss_SOURCE_DIR}" + RESULT_VARIABLE result) if(NOT result EQUAL "0") message(FATAL_ERROR "Extraction failed with ${result}") endif() @@ -57,31 +61,35 @@ macro(list_pop_front list out) endmacro() function(docs_project name) - cmake_parse_arguments( - PARSE_ARGV - 1 - "" - "" - "VERSION;DESCRIPTION;HOMEPAGE_URL" - LANGUAGES - ) - set(PROJECT_NAME "${name}" PARENT_SCOPE) + cmake_parse_arguments(PARSE_ARGV 1 "" "" "VERSION;DESCRIPTION;HOMEPAGE_URL" + LANGUAGES) + set(PROJECT_NAME + "${name}" + PARENT_SCOPE) if(DEFINED _VERSION) - set(PROJECT_VERSION "${_VERSION}" PARENT_SCOPE) + set(PROJECT_VERSION + "${_VERSION}" + PARENT_SCOPE) string(REGEX MATCH "^[0-9]+(\\.[0-9]+)*" versions "${_VERSION}") string(REPLACE . ";" versions "${versions}") set(suffixes MAJOR MINOR PATCH TWEAK) while(NOT versions STREQUAL "" AND NOT suffixes STREQUAL "") list_pop_front(versions version) list_pop_front(suffixes suffix) - set("PROJECT_VERSION_${suffix}" "${version}" PARENT_SCOPE) + set("PROJECT_VERSION_${suffix}" + "${version}" + PARENT_SCOPE) endwhile() endif() if(DEFINED _DESCRIPTION) - set(PROJECT_DESCRIPTION "${_DESCRIPTION}" PARENT_SCOPE) + set(PROJECT_DESCRIPTION + "${_DESCRIPTION}" + PARENT_SCOPE) endif() if(DEFINED _HOMEPAGE_URL) - set(PROJECT_HOMEPAGE_URL "${_HOMEPAGE_URL}" PARENT_SCOPE) + set(PROJECT_HOMEPAGE_URL + "${_HOMEPAGE_URL}" + PARENT_SCOPE) endif() endfunction() @@ -104,8 +112,9 @@ set(config "${bin}/docs/conf.py") file(REMOVE_RECURSE "${out}/html" "${out}/xml") execute_process( - COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" WORKING_DIRECTORY "${bin}/docs" RESULT_VARIABLE result -) + COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" + WORKING_DIRECTORY "${bin}/docs" + RESULT_VARIABLE result) if(NOT result EQUAL "0") message(FATAL_ERROR "m.css returned with ${result}") endif() diff --git a/cmake/docs.cmake b/cmake/docs.cmake index 5f41772..7a1ef7e 100644 --- a/cmake/docs.cmake +++ b/cmake/docs.cmake @@ -12,15 +12,16 @@ FetchContent_Declare( URL_MD5 00cd2757ebafb9bcba7f5d399b3bec7f SOURCE_DIR "${PROJECT_BINARY_DIR}/mcss" UPDATE_DISCONNECTED YES - ${extract_timestamps} -) + ${extract_timestamps}) FetchContent_MakeAvailable(mcss) find_package(Python3 3.6 REQUIRED) # ---- Declare documentation target ---- -set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" CACHE PATH "Path for the generated Doxygen documentation") +set(DOXYGEN_OUTPUT_DIRECTORY + "${PROJECT_BINARY_DIR}/docs" + CACHE PATH "Path for the generated Doxygen documentation") set(working_dir "${PROJECT_BINARY_DIR}/docs") @@ -33,9 +34,9 @@ set(config "${working_dir}/conf.py") add_custom_target( docs - COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOXYGEN_OUTPUT_DIRECTORY}/html" "${DOXYGEN_OUTPUT_DIRECTORY}/xml" + COMMAND "${CMAKE_COMMAND}" -E remove_directory + "${DOXYGEN_OUTPUT_DIRECTORY}/html" "${DOXYGEN_OUTPUT_DIRECTORY}/xml" COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" COMMENT "Building documentation using Doxygen and m.css" WORKING_DIRECTORY "${working_dir}" - VERBATIM -) + VERBATIM) diff --git a/cmake/folders.cmake b/cmake/folders.cmake index da7bd33..7bbb770 100644 --- a/cmake/folders.cmake +++ b/cmake/folders.cmake @@ -5,14 +5,23 @@ set_property(GLOBAL PROPERTY USE_FOLDERS YES) # UtilityTargets folder, otherwise to the ${name}Targets folder. If a target # already has a folder assigned, then that target will be skipped. function(add_folders name) - get_property(targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS) + get_property( + targets + DIRECTORY + PROPERTY BUILDSYSTEM_TARGETS) foreach(target IN LISTS targets) - get_property(folder TARGET "${target}" PROPERTY FOLDER) + get_property( + folder + TARGET "${target}" + PROPERTY FOLDER) if(DEFINED folder) continue() endif() set(folder Utility) - get_property(type TARGET "${target}" PROPERTY TYPE) + get_property( + type + TARGET "${target}" + PROPERTY TYPE) if(NOT type STREQUAL "UTILITY") set(folder "${name}") endif() diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 1ac4156..88622ce 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -1,5 +1,7 @@ if(PROJECT_IS_TOP_LEVEL) - set(CMAKE_INSTALL_INCLUDEDIR "include/cmake-init-modules-${PROJECT_VERSION}" CACHE PATH "") + set(CMAKE_INSTALL_INCLUDEDIR + "include/cmake-init-modules-${PROJECT_VERSION}" + CACHE PATH "") endif() include(CMakePackageConfigHelpers) @@ -8,10 +10,10 @@ include(GNUInstallDirs) # find_package() call for consumers to find this project set(package cmake-init-modules) -install(DIRECTORY include/ "${PROJECT_BINARY_DIR}/export/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT cmake-init-modules_Development -) +# install(DIRECTORY include/ "${PROJECT_BINARY_DIR}/export/" DESTINATION +# "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT cmake-init-modules_Development ) +# cmake-format: off install(TARGETS cmake-init-modules_cmake-init-modules EXPORT cmake-init-modulesTargets RUNTIME # @@ -19,30 +21,38 @@ install(TARGETS cmake-init-modules_cmake-init-modules LIBRARY # COMPONENT cmake-init-modules_Runtime NAMELINK_COMPONENT cmake-init-modules_Development ARCHIVE # - COMPONENT cmake-init-modules_Development + COMPONENT cmake-init-modules_Development # + FILE_SET HEADERS # INCLUDES # DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) +# cmake-format: on -write_basic_package_version_file("${package}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion) +write_basic_package_version_file("${package}ConfigVersion.cmake" + COMPATIBILITY SameMajorVersion) # Allow package maintainers to freely override the path for the configs -set(cmake-init-modules_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" - CACHE PATH "CMake package config location relative to the install prefix" -) +set(cmake-init-modules_INSTALL_CMAKEDIR + "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" + CACHE PATH "CMake package config location relative to the install prefix") mark_as_advanced(cmake-init-modules_INSTALL_CMAKEDIR) -install(FILES cmake/install-config.cmake DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - RENAME "${package}Config.cmake" COMPONENT cmake-init-modules_Development -) - -install(FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake" DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - COMPONENT cmake-init-modules_Development -) - -install(EXPORT cmake-init-modulesTargets NAMESPACE cmake-init-modules:: - DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" COMPONENT cmake-init-modules_Development -) +install( + FILES cmake/install-config.cmake + DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" + RENAME "${package}Config.cmake" + COMPONENT cmake-init-modules_Development) + +install( + FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake" + DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" + COMPONENT cmake-init-modules_Development) + +install( + EXPORT cmake-init-modulesTargets + NAMESPACE cmake-init-modules:: + DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" + COMPONENT cmake-init-modules_Development) if(PROJECT_IS_TOP_LEVEL) include(CPack) diff --git a/cmake/lint-targets.cmake b/cmake/lint-targets.cmake index 1f0324a..0c02f24 100644 --- a/cmake/lint-targets.cmake +++ b/cmake/lint-targets.cmake @@ -6,25 +6,28 @@ set(FORMAT_PATTERNS test/*.hpp example/*.cpp example/*.hpp - CACHE STRING "; separated patterns relative to the project source dir to format" -) + CACHE STRING + "; separated patterns relative to the project source dir to format") -set(FORMAT_COMMAND clang-format CACHE STRING "Formatter to use") +set(FORMAT_COMMAND + clang-format + CACHE STRING "Formatter to use") add_custom_target( format-check - COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -P - "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + COMMAND + "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D + "PATTERNS=${FORMAT_PATTERNS}" -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Linting the code" - VERBATIM -) + VERBATIM) add_custom_target( format-fix - COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -D FIX=YES -P - "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + COMMAND + "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D + "PATTERNS=${FORMAT_PATTERNS}" -D FIX=YES -P + "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Fixing the code" - VERBATIM -) + VERBATIM) diff --git a/cmake/lint.cmake b/cmake/lint.cmake index 3f25809..949723a 100644 --- a/cmake/lint.cmake +++ b/cmake/lint.cmake @@ -7,15 +7,15 @@ macro(default name) endmacro() default(FORMAT_COMMAND clang-format) -default(PATTERNS - source/*.cpp - source/*.hpp - include/*.hpp - test/*.cpp - test/*.hpp - example/*.cpp - example/*.hpp -) +default( + PATTERNS + source/*.cpp + source/*.hpp + include/*.hpp + test/*.cpp + test/*.hpp + example/*.cpp + example/*.hpp) default(FIX NO) set(flag --output-replacements-xml) @@ -32,9 +32,9 @@ string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length) foreach(file IN LISTS files) execute_process( - COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result ${args} - ) + COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE result ${args}) if(NOT result EQUAL "0") message(FATAL_ERROR "'${file}': formatter returned with ${result}") endif() diff --git a/cmake/prelude.cmake b/cmake/prelude.cmake index 91bf95b..3978064 100644 --- a/cmake/prelude.cmake +++ b/cmake/prelude.cmake @@ -1,9 +1,9 @@ # ---- In-source guard ---- if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) - message(FATAL_ERROR - "In-source builds are not supported. " - "Please read the BUILDING document before trying to build this project. " - "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." - ) + message( + FATAL_ERROR + "In-source builds are not supported. " + "Please read the BUILDING document before trying to build this project. " + "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first.") endif() diff --git a/cmake/project-is-top-level.cmake b/cmake/project-is-top-level.cmake index 0b169e5..6da0bfb 100644 --- a/cmake/project-is-top-level.cmake +++ b/cmake/project-is-top-level.cmake @@ -1,2 +1,3 @@ # This variable is set by project() in CMake 3.21+ -string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" PROJECT_IS_TOP_LEVEL) +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" + PROJECT_IS_TOP_LEVEL) diff --git a/cmake/spell-targets.cmake b/cmake/spell-targets.cmake index c919f95..10c30e6 100644 --- a/cmake/spell-targets.cmake +++ b/cmake/spell-targets.cmake @@ -1,17 +1,19 @@ -set(SPELL_COMMAND codespell CACHE STRING "Spell checker to use") +set(SPELL_COMMAND + codespell + CACHE STRING "Spell checker to use") add_custom_target( spell-check - COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" + COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -P + "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Checking spelling" - VERBATIM -) + VERBATIM) add_custom_target( spell-fix - COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -D FIX=YES -P "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" + COMMAND "${CMAKE_COMMAND}" -D "SPELL_COMMAND=${SPELL_COMMAND}" -D FIX=YES -P + "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Fixing spelling errors" - VERBATIM -) + VERBATIM) diff --git a/cmake/spell.cmake b/cmake/spell.cmake index e1dfb70..c9e5416 100644 --- a/cmake/spell.cmake +++ b/cmake/spell.cmake @@ -14,7 +14,10 @@ if(FIX) set(flag -w) endif() -execute_process(COMMAND "${SPELL_COMMAND}" ${flag} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE result) +execute_process( + COMMAND "${SPELL_COMMAND}" ${flag} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE result) if(result EQUAL "65") message(FATAL_ERROR "Run again with FIX=YES to fix these errors.") diff --git a/cmake/variables.cmake b/cmake/variables.cmake index 5905157..d657225 100644 --- a/cmake/variables.cmake +++ b/cmake/variables.cmake @@ -1,9 +1,9 @@ # ---- Developer mode ---- # Developer mode enables targets and code paths in the CMake scripts that are -# only relevant for the developer(s) of cmake-init-modules -# Targets necessary to build the project must be provided unconditionally, so -# consumers can trivially build and package the project +# only relevant for the developer(s) of cmake-init-modules Targets necessary to +# build the project must be provided unconditionally, so consumers can trivially +# build and package the project if(PROJECT_IS_TOP_LEVEL) option(cmake-init-modules_DEVELOPER_MODE "Enable developer mode" OFF) option(BUILD_SHARED_LIBS "Build shared libs." OFF) @@ -20,20 +20,20 @@ set(pragma_suppress_c4251 #else # define CMAKE_INIT_MODULES_SUPPRESS_C4251 #endif -" -) +") # ---- Warning guard ---- # target_include_directories with the SYSTEM modifier will request the compiler -# to omit warnings from the provided paths, if the compiler supports that -# This is to provide a user experience similar to find_package when -# add_subdirectory or FetchContent is used to consume this project +# to omit warnings from the provided paths, if the compiler supports that This +# is to provide a user experience similar to find_package when add_subdirectory +# or FetchContent is used to consume this project set(warning_guard "") if(NOT PROJECT_IS_TOP_LEVEL) - option(cmake-init-modules_INCLUDES_WITH_SYSTEM - "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" ON - ) + option( + cmake-init-modules_INCLUDES_WITH_SYSTEM + "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" + ON) mark_as_advanced(cmake-init-modules_INCLUDES_WITH_SYSTEM) if(cmake-init-modules_INCLUDES_WITH_SYSTEM) set(warning_guard SYSTEM) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 6b63452..b119617 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -9,15 +9,22 @@ if(PROJECT_IS_TOP_LEVEL) find_package(cmake-init-modules REQUIRED) endif() +enable_testing() + add_custom_target(run-examples) function(add_example NAME) add_executable("${NAME}" "${NAME}.cpp") - target_link_libraries("${NAME}" PRIVATE cmake-init-modules::cmake-init-modules) + target_link_libraries("${NAME}" + PRIVATE cmake-init-modules::cmake-init-modules) target_compile_features("${NAME}" PRIVATE cxx_std_20) - add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM) + add_custom_target( + "run_${NAME}" + COMMAND "${NAME}" + VERBATIM) add_dependencies("run_${NAME}" "${NAME}") add_dependencies(run-examples "run_${NAME}") + add_test(NAME ${NAME} COMMAND ${NAME}) endfunction() add_example(empty_example) diff --git a/example/empty_example.cpp b/example/empty_example.cpp index a736724..46d2368 100644 --- a/example/empty_example.cpp +++ b/example/empty_example.cpp @@ -1,4 +1,9 @@ +#include + +#include + auto main() -> int { + std::cout << exported_class().name() << std::endl; return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47aa8d3..50e3866 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,9 @@ include(Catch) # ---- Tests ---- add_executable(cmake-init-modules_test source/cmake-init-modules_test.cpp) -target_link_libraries(cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules Catch2::Catch2WithMain) +target_link_libraries( + cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules + Catch2::Catch2WithMain) target_compile_features(cmake-init-modules_test PRIVATE cxx_std_20) catch_discover_tests(cmake-init-modules_test) From 952236aedebe6215571735923cecc573fba05661 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 27 Feb 2024 22:17:26 +0100 Subject: [PATCH 05/57] TestInstalledVersion only on ubuntu CI Last try with llvm-15 on ubuntu for now! --- .CMakeUserPresets.json | 2 +- .github/workflows/ci.yml | 14 ++++++++++---- GNUmakefile | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 5ca8352..db266e6 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -61,7 +61,7 @@ "name": "dev", "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", - "inherits": "dev-darwin" + "inherits": "dev-linux" }, { "name": "dev-coverage", diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c57d1e4..b3090df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: fail-fast: false matrix: - os: [macos-14, ubuntu-22.04, windows-2022] + os: [macos-13, ubuntu-22.04, windows-2022] type: [shared, static] @@ -135,10 +135,10 @@ jobs: - uses: actions/checkout@v4 - name: Setup Cpp - if: matrix.os != 'windows-2022' + if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: - compiler: llvm-17.0.6 + compiler: llvm-15 vcvarsall: ${{ contains(matrix.os, 'windows') }} # conan: true # vcpkg: true @@ -185,12 +185,18 @@ jobs: run: cmake --build build --config Release -j 2 - name: Install - run: cmake --install build --config Release --prefix prefix + run: cmake --install build --config Release --prefix stagedir - name: Test working-directory: build run: ctest --output-on-failure --no-tests=error -C Release -j 2 + - name: TestInstalledVersion + if: matrix.os == 'ubuntu-22.04' + run: | + ln -sf .CMakeUserPresets.json CMakeUserPresets.json + VERBOSE=1 BUILD_SHARED_LIBS=${{ matrix.shared }} gmake test + docs: # Deploy docs only when builds succeed needs: [sanitize, test] diff --git a/GNUmakefile b/GNUmakefile index a82d8d2..347f876 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,8 +9,8 @@ MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefi # export CC=gcc-13 # export CXX=g++-13 -export CC=clang-17 -export CXX=$(shell which clang++) +export CC?=clang-17 +export CXX?=$(shell which clang++) export CMAKE_EXPORT_COMPILE_COMMANDS=YES CONAN_HOME=$(shell conan config home) From d18d1bca8bd84d2b6d802c0173b7ec2ac044c8bb Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 27 Feb 2024 23:08:33 +0100 Subject: [PATCH 06/57] TestInstalledVersion without clang-tidy --- .CMakeUserPresets.json | 3 +-- GNUmakefile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index db266e6..7983092 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -11,8 +11,7 @@ "hidden": true, "inherits": [ "dev-mode", - "conan", - "clang-tidy" + "conan" ], "generator": "Ninja", "cacheVariables": { diff --git a/GNUmakefile b/GNUmakefile index 347f876..ec04b7f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,7 +17,7 @@ CONAN_HOME=$(shell conan config home) # BUILD_TYPE=Release BUILD_TYPE=Debug -.PHONY: all clean distclean check format test +.PHONY: all clean distclean check format test conan all: conan # TODO: if needed: cmake --preset dev --fresh --debug-find-pkg=fmt From 6022013905ed8d4297a2e21a09cebe7b8ab177ff Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 28 Feb 2024 07:37:26 +0100 Subject: [PATCH 07/57] Cleanup --- .CMakeUserPresets.json | 14 ++++++-------- .github/workflows/ci.yml | 11 +---------- GNUmakefile | 10 ++++------ HACKING.md | 6 +++--- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 7983092..5b1961f 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -15,6 +15,7 @@ ], "generator": "Ninja", "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, "BUILD_MCSS_DOCS": false, "BUILD_SHARED_LIBS": true } @@ -27,8 +28,7 @@ "ci-linux" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + "CMAKE_BUILD_TYPE": "Debug" } }, { @@ -39,8 +39,7 @@ "ci-darwin" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + "CMAKE_BUILD_TYPE": "Debug" } }, { @@ -64,12 +63,11 @@ }, { "name": "dev-coverage", - "binaryDir": "${sourceDir}/build/coverage", + "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", "inherits": [ - "dev-mode", - "coverage-linux", - "conan" + "dev-linux", + "coverage-linux" ] } ], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3090df..bfefaa5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: fail-fast: false matrix: - os: [macos-13, ubuntu-22.04, windows-2022] + os: [macos-14, ubuntu-22.04, windows-2022] type: [shared, static] @@ -146,15 +146,6 @@ jobs: clangtidy: true # ... - # - name: Install static analyzers - # if: matrix.os == 'ubuntu-22.04' - # run: >- - # sudo apt-get install clang-tidy-15 cppcheck -y -q - - # sudo update-alternatives --install - # /usr/bin/clang-tidy clang-tidy - # /usr/bin/clang-tidy-15 140 - - name: Install Python uses: actions/setup-python@v5 with: { python-version: "3.10" } diff --git a/GNUmakefile b/GNUmakefile index ec04b7f..9055112 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,8 +4,8 @@ $(VERBOSE).SILENT: MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. -MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. -MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk). +# MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. +# MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk). # export CC=gcc-13 # export CXX=g++-13 @@ -20,15 +20,13 @@ BUILD_TYPE=Debug .PHONY: all clean distclean check format test conan all: conan - # TODO: if needed: cmake --preset dev --fresh --debug-find-pkg=fmt - cmake --workflow --preset dev # XXX --fresh + cmake --workflow --preset dev --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir - # TODO: cpack --list-presets test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ -D 'CMAKE_PREFIX_PATH=$(CURDIR)/stagedir;$(CURDIR)/conan' \ - --toolchain $(CURDIR)/conan/conan_toolchain.cmake --debug-find-pkg=fmt + --toolchain $(CURDIR)/conan/conan_toolchain.cmake # XXX --debug-find-pkg=fmt ninja -C example/build ninja -C example/build test diff --git a/HACKING.md b/HACKING.md index 1fc0e99..c4b6eb4 100644 --- a/HACKING.md +++ b/HACKING.md @@ -92,9 +92,9 @@ the operating system you have, which may be `win64`, `linux` or `darwin`. You can see what these correspond to in the [`CMakePresets.json`](CMakePresets.json) file. -`CMakeUserPresets.json` is also the perfect place in which you can put all -sorts of things that you would otherwise want to pass to the configure command -in the terminal. +[`CMakeUserPresets.json`](.CMakeUserPresets.json) file is also the perfect place +in which you can put all sorts of things that you would otherwise want to pass +to the configure command in the terminal. > **Note** > Some editors are pretty greedy with how they open projects with presets. From 355c5b237e91e307207b079f5c3e200a78d5a396 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 28 Feb 2024 07:45:13 +0100 Subject: [PATCH 08/57] Try to use setup-cpp on macos-14 CI too --- .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 bfefaa5..7e93527 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,7 +135,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup Cpp - if: matrix.os == 'ubuntu-22.04' + if: matrix.os != 'windows-2022' uses: aminya/setup-cpp@v1 with: compiler: llvm-15 From bd2c321d03aac26f14e59ba1e4f586d5dc98678a Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 28 Feb 2024 14:50:55 +0100 Subject: [PATCH 09/57] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ab2917..e1194ce 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cmake-init-modules -This is the cmake-init-modules project. +This is the [cmake-init](https://github.com/friendlyanon/cmake-init) generated example project. # Building and installing From 58bc0f263c193f442b46576da8196dd61fa13db2 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 28 Feb 2024 20:54:03 +0100 Subject: [PATCH 10/57] Try to fix all errors --- .CMakeUserPresets.json | 13 +++++++++++-- .clang-tidy | 3 ++- .github/workflows/ci.yml | 9 +++++++++ CMakePresets.json | 12 +++++++----- example/empty_example.cpp | 2 +- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 5b1961f..f78c541 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -66,8 +66,17 @@ "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", "inherits": [ - "dev-linux", - "coverage-linux" + "ci-coverage", + "dev-linux" + ] + }, + { + "name": "dev-sanitize", + "binaryDir": "${sourceDir}/build/dev", + "generator": "Ninja", + "inherits": [ + "ci-sanitize", + "dev-linux" ] } ], diff --git a/.clang-tidy b/.clang-tidy index d509f2c..3fd7b57 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,8 @@ Checks: "*,\ -llvm-include-order,\ -llvmlibc-*,\ -modernize-use-nodiscard,\ - -misc-non-private-member-variables-in-classes" + -misc-non-private-member-variables-in-classes,\ + -readability-avoid-unconditional-preprocessor-if" WarningsAsErrors: '' CheckOptions: - key: 'bugprone-argument-comment.StrictMode' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e93527..0e189c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -188,6 +188,15 @@ jobs: ln -sf .CMakeUserPresets.json CMakeUserPresets.json VERBOSE=1 BUILD_SHARED_LIBS=${{ matrix.shared }} gmake test + - name: TestInstalledVersion + if: matrix.os == 'macos-14' + run: | + cmake -B example/build -S example -G Ninja -D CMAKE_BUILD_TYPE=Release \ + -D 'CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan' \ + --toolchain $PWD/conan/conan_toolchain.cmake + ninja -C example/build + ninja -C example/build test + docs: # Deploy docs only when builds succeed needs: [sanitize, test] diff --git a/CMakePresets.json b/CMakePresets.json index b1f2868..2d730e7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -80,7 +80,7 @@ "name": "flags-darwin", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "-fstack-protector-strong -fcf-protection=full -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast" + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast" }, "condition": { "type": "equals", @@ -106,7 +106,7 @@ }, { "name": "ci-linux", - "generator": "Unix Makefiles", + "generator": "Ninja", "hidden": true, "inherits": [ "flags-linux", @@ -118,7 +118,7 @@ }, { "name": "ci-darwin", - "generator": "Unix Makefiles", + "generator": "Ninja", "hidden": true, "inherits": [ "flags-darwin", @@ -145,11 +145,12 @@ "hidden": true, "cacheVariables": { "ENABLE_COVERAGE": "ON", + "CMAKE_SKIP_INSTALL_RULES": "ON", "CMAKE_BUILD_TYPE": "Coverage", "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions", "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage", - "CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug;" + "CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug" } }, { @@ -172,9 +173,10 @@ "conan" ], "cacheVariables": { + "CMAKE_SKIP_INSTALL_RULES": "ON", "CMAKE_BUILD_TYPE": "Sanitize", "CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common", - "CMAKE_MAP_IMPORTED_CONFIG_SANITIZE": "Sanitize;RelWithDebInfo;Release;Debug;" + "CMAKE_MAP_IMPORTED_CONFIG_SANITIZE": "Sanitize;RelWithDebInfo;Release;Debug" } }, { diff --git a/example/empty_example.cpp b/example/empty_example.cpp index 46d2368..aeae052 100644 --- a/example/empty_example.cpp +++ b/example/empty_example.cpp @@ -4,6 +4,6 @@ auto main() -> int { - std::cout << exported_class().name() << std::endl; + std::cout << exported_class().name() << "\n"; return 0; } From fcfcda309303ed9e6fc3ffc6c69f9321ad86e9f0 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 8 Apr 2024 08:53:36 +0200 Subject: [PATCH 11/57] cleanup --- CMakeLists.txt | 14 +++----------- cmake/install-rules.cmake | 20 +++++++------------- cmake/project-is-top-level.cmake | 3 --- example/CMakeLists.txt | 3 +-- test/CMakeLists.txt | 3 +-- 5 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 cmake/project-is-top-level.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 60128b9..a01210d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.28...3.29) include(cmake/prelude.cmake) @@ -9,7 +9,6 @@ project( HOMEPAGE_URL "https://example.com/" LANGUAGES CXX) -include(cmake/project-is-top-level.cmake) include(cmake/variables.cmake) # ---- Declare library ---- @@ -28,8 +27,6 @@ generate_export_header( CUSTOM_CONTENT_FROM_VARIABLE pragma_suppress_c4251) -configure_file(include/cmake-init-modules/cmake-init-modules.hpp - export/cmake-init-modules/cmake-init-modules.hpp COPYONLY) # cmake-format: off target_sources( @@ -37,8 +34,9 @@ target_sources( PUBLIC FILE_SET HEADERS BASE_DIRS ${PROJECT_BINARY_DIR}/export + ${PROJECT_SOURCE_DIR}/include FILES - ${PROJECT_BINARY_DIR}/export/cmake-init-modules/cmake-init-modules.hpp + include/cmake-init-modules/cmake-init-modules.hpp ${PROJECT_BINARY_DIR}/export/cmake-init-modules/cmake-init-modules_export.hpp ) # cmake-format: on @@ -57,12 +55,6 @@ set_target_properties( EXPORT_NAME cmake-init-modules OUTPUT_NAME cmake-init-modules) -# target_include_directories( cmake-init-modules_cmake-init-modules -# ${warning_guard} PUBLIC "$" ) -# -# target_include_directories( cmake-init-modules_cmake-init-modules SYSTEM -# PUBLIC "$" ) - target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) find_package(fmt REQUIRED) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 88622ce..346cf65 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -10,21 +10,14 @@ include(GNUInstallDirs) # find_package() call for consumers to find this project set(package cmake-init-modules) -# install(DIRECTORY include/ "${PROJECT_BINARY_DIR}/export/" DESTINATION -# "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT cmake-init-modules_Development ) - # cmake-format: off install(TARGETS cmake-init-modules_cmake-init-modules - EXPORT cmake-init-modulesTargets - RUNTIME # - COMPONENT cmake-init-modules_Runtime - LIBRARY # - COMPONENT cmake-init-modules_Runtime NAMELINK_COMPONENT cmake-init-modules_Development - ARCHIVE # - COMPONENT cmake-init-modules_Development # - FILE_SET HEADERS # - INCLUDES # - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + EXPORT cmake-init-modulesTargets + RUNTIME COMPONENT cmake-init-modules_Runtime + LIBRARY COMPONENT cmake-init-modules_Runtime NAMELINK_COMPONENT cmake-init-modules_Development + ARCHIVE COMPONENT cmake-init-modules_Development + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILE_SET HEADERS ) # cmake-format: on @@ -55,5 +48,6 @@ install( COMPONENT cmake-init-modules_Development) if(PROJECT_IS_TOP_LEVEL) + set(CPACK_GENERATOR TGZ) include(CPack) endif() diff --git a/cmake/project-is-top-level.cmake b/cmake/project-is-top-level.cmake deleted file mode 100644 index 6da0bfb..0000000 --- a/cmake/project-is-top-level.cmake +++ /dev/null @@ -1,3 +0,0 @@ -# This variable is set by project() in CMake 3.21+ -string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" - PROJECT_IS_TOP_LEVEL) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b119617..e109098 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,8 +1,7 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.28...3.29) project(cmake-init-modulesExamples CXX) -include(../cmake/project-is-top-level.cmake) include(../cmake/folders.cmake) if(PROJECT_IS_TOP_LEVEL) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 50e3866..a4de65d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,7 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.28...3.29) project(cmake-init-modulesTests LANGUAGES CXX) -include(../cmake/project-is-top-level.cmake) include(../cmake/folders.cmake) # ---- Dependencies ---- From 12036db470b5e79cb0246ba7668a8a7891a21f0f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 9 Apr 2024 10:54:09 +0200 Subject: [PATCH 12/57] Add C++20 Module as Shared Libraries Add .cmake-format config file Format all cmake files too --- .CMakeUserPresets.json | 17 ++---- .cmake-format | 109 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + CMakeLists.txt | 104 ++++++++++++++++++++++++++------ CMakePresets.json | 12 ++++ GNUmakefile | 24 +++++--- algo-impl.cpp | 10 ++++ algo-interface.cppm | 13 ++++ cmake/coverage.cmake | 21 +++---- cmake/docs-ci.cmake | 57 ++++++++---------- cmake/docs.cmake | 16 ++--- cmake/folders.cmake | 15 +---- cmake/install-rules.cmake | 22 +++---- cmake/lint-targets.cmake | 25 ++++---- cmake/lint.cmake | 11 ++-- cmake/my_package-config.cmake | 4 ++ cmake/prelude.cmake | 3 +- cmake/spell-targets.cmake | 10 ++-- cmake/spell.cmake | 5 +- cmake/variables.cmake | 10 ++-- example/CMakeLists.txt | 22 ++++--- example/main.cpp | 9 +++ test/CMakeLists.txt | 4 +- 23 files changed, 372 insertions(+), 152 deletions(-) create mode 100644 .cmake-format create mode 100644 algo-impl.cpp create mode 100644 algo-interface.cppm create mode 100644 cmake/my_package-config.cmake create mode 100644 example/main.cpp diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index f78c541..2765815 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -14,6 +14,7 @@ "conan" ], "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, "BUILD_MCSS_DOCS": false, @@ -21,8 +22,7 @@ } }, { - "name": "dev-linux", - "binaryDir": "${sourceDir}/build/dev-linux", + "name": "dev-Linux", "inherits": [ "dev-common", "ci-linux" @@ -32,8 +32,7 @@ } }, { - "name": "dev-darwin", - "binaryDir": "${sourceDir}/build/dev-darwin", + "name": "dev-Darwin", "inherits": [ "dev-common", "ci-darwin" @@ -44,7 +43,6 @@ }, { "name": "dev-win64", - "binaryDir": "${sourceDir}/build/dev-win64", "inherits": [ "dev-common", "cppcheck", @@ -57,26 +55,23 @@ }, { "name": "dev", - "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", - "inherits": "dev-linux" + "inherits": "dev-" }, { "name": "dev-coverage", - "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", "inherits": [ "ci-coverage", - "dev-linux" + "dev-Linux" ] }, { "name": "dev-sanitize", - "binaryDir": "${sourceDir}/build/dev", "generator": "Ninja", "inherits": [ "ci-sanitize", - "dev-linux" + "dev-Linux" ] } ], diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 0000000..263f534 --- /dev/null +++ b/.cmake-format @@ -0,0 +1,109 @@ +_help_format: Options affecting formatting. +format: + _help_disable: + - Disable formatting entirely, making cmake-format a no-op + disable: false + _help_line_width: + - How wide to allow formatted cmake files + line_width: 100 + _help_tab_size: + - How many spaces to tab for indent + tab_size: 2 + _help_use_tabchars: + - If true, lines are indented using tab characters (utf-8 + - 0x09) instead of space characters (utf-8 0x20). + - In cases where the layout would require a fractional tab + - character, the behavior of the fractional indentation is + - governed by + use_tabchars: false + _help_fractional_tab_policy: + - If is True, then the value of this variable + - indicates how fractional indentions are handled during + - whitespace replacement. If set to 'use-space', fractional + - indentation is left as spaces (utf-8 0x20). If set to + - '`round-up` fractional indentation is replaced with a single' + - tab character (utf-8 0x09) effectively shifting the column + - to the next tabstop + fractional_tab_policy: use-space + _help_max_subgroups_hwrap: + - If an argument group contains more than this many sub-groups + - (parg or kwarg groups) then force it to a vertical layout. + max_subgroups_hwrap: 4 + _help_max_pargs_hwrap: + - If a positional argument group contains more than this many + - arguments, then force it to a vertical layout. + max_pargs_hwrap: 6 + _help_max_rows_cmdline: + - If a cmdline positional group consumes more than this many + - lines without nesting, then invalidate the layout (and nest) + max_rows_cmdline: 2 + _help_separate_ctrl_name_with_space: + - If true, separate flow control names from their parentheses + - with a space + separate_ctrl_name_with_space: false + _help_separate_fn_name_with_space: + - If true, separate function names from parentheses with a + - space + separate_fn_name_with_space: false + _help_dangle_parens: + - If a statement is wrapped to more than one line, than dangle + - the closing parenthesis on its own line. + dangle_parens: true + _help_dangle_align: + - If the trailing parenthesis must be 'dangled' on its on + - 'line, then align it to this reference: `prefix`: the start' + - 'of the statement, `prefix-indent`: the start of the' + - 'statement, plus one indentation level, `child`: align to' + - the column of the arguments + dangle_align: prefix + _help_min_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is smaller than this amount, then force reject + - nested layouts. + min_prefix_chars: 4 + _help_max_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is larger than the tab width by more than this + - amount, then force reject un-nested layouts. + max_prefix_chars: 10 + _help_max_lines_hwrap: + - If a candidate layout is wrapped horizontally but it exceeds + - this many lines, then reject the layout. + max_lines_hwrap: 2 + _help_line_ending: + - What style line endings to use in the output. + line_ending: unix + _help_command_case: + - Format command names consistently as 'lower' or 'upper' case + command_case: canonical + _help_keyword_case: + - Format keywords consistently as 'lower' or 'upper' case + keyword_case: unchanged + _help_always_wrap: + - A list of command names which should always be wrapped + always_wrap: [file, install] + _help_enable_sort: + - If true, the argument lists which are known to be sortable + - will be sorted lexicographicall + enable_sort: true + _help_autosort: + - If true, the parsers may infer whether or not an argument + - list is sortable (without annotation). + autosort: false + _help_require_valid_layout: + - By default, if cmake-format cannot successfully fit + - everything into the desired linewidth it will apply the + - last, most aggressive attempt that it made. If this flag is + - True, however, cmake-format will print error, exit with non- + - zero status code, and write-out nothing + require_valid_layout: false + _help_layout_passes: + - A dictionary mapping layout nodes to a list of wrap + - decisions. See the documentation for more information. + layout_passes: {} + +_help_markup: Options affecting comment reflow and formatting. +markup: + _help_enable_markup: + - enable comment markup parsing and reflow + enable_markup: false diff --git a/.gitignore b/.gitignore index e036a5f..9fe1178 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ conan/ prefix/ stagedir/ .clangd +.init CMakeLists.txt.user CMakeUserPresets.json compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index a01210d..53a32a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,88 @@ -cmake_minimum_required(VERSION 3.28...3.29) +cmake_minimum_required(VERSION 3.28.4...3.29) include(cmake/prelude.cmake) -project( - cmake-init-modules - VERSION 0.1.0 - DESCRIPTION "Short description" - HOMEPAGE_URL "https://example.com/" - LANGUAGES CXX) +project(cxx_modules_example VERSION 0.1.0 LANGUAGES CXX) + +# This property setting also needs to be consistent between the +# installed shared library and its consumer, otherwise most +# toolchains will once again reject the consumer’s generated BMI. +set(CMAKE_CXX_EXTENSIONS FALSE) + +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) + +add_library(Algo SHARED) + +######################################################################### +# cmake-format: off +target_sources(Algo + PRIVATE + algo-impl.cpp + PUBLIC + FILE_SET CXX_MODULES + FILES + algo-interface.cppm +) + +# CMake requires the language standard to be specified as compile feature +# when a target provides C++20 modules and the target will be installed +target_compile_features(Algo PUBLIC cxx_std_20) + +include(GenerateExportHeader) +generate_export_header(Algo) +target_sources(Algo + PUBLIC + FILE_SET HEADERS + BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} + FILES + ${CMAKE_CURRENT_BINARY_DIR}/algo_export.h +) + +include(GNUInstallDirs) + +install(TARGETS Algo + EXPORT my_package-targets + # ... a few details omitted, see the "Deep CMake For Library Authors" talk + FILE_SET CXX_MODULES + # There's currently no convention for this location, see discussion below + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package/src + FILE_SET HEADERS + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # Same as default, could be omitted + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(EXPORT my_package-targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package + CXX_MODULES_DIRECTORY . +) +# The following file includes the my_package-targets.cmake file +install(FILES cmake/my_package-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package +) + +# cmake-format: on +######################################################################### + +# enable_testing() +# add_subdirectory(example) +# return() + +################################################## + +# project( +# cmake-init-modules +# VERSION 0.1.0 +# DESCRIPTION "Short description" +# HOMEPAGE_URL "https://example.com/" +# LANGUAGES CXX) include(cmake/variables.cmake) # ---- Declare library ---- add_library(cmake-init-modules_cmake-init-modules source/cmake-init-modules.cpp) -add_library(cmake-init-modules::cmake-init-modules ALIAS - cmake-init-modules_cmake-init-modules) +add_library(cmake-init-modules::cmake-init-modules ALIAS cmake-init-modules_cmake-init-modules) include(GenerateExportHeader) generate_export_header( @@ -25,8 +92,8 @@ generate_export_header( EXPORT_FILE_NAME export/cmake-init-modules/cmake-init-modules_export.hpp CUSTOM_CONTENT_FROM_VARIABLE - pragma_suppress_c4251) - + pragma_suppress_c4251 +) # cmake-format: off target_sources( @@ -42,8 +109,9 @@ target_sources( # cmake-format: on if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(cmake-init-modules_cmake-init-modules - PUBLIC CMAKE_INIT_MODULES_STATIC_DEFINE) + target_compile_definitions( + cmake-init-modules_cmake-init-modules PUBLIC CMAKE_INIT_MODULES_STATIC_DEFINE + ) endif() set_target_properties( @@ -53,7 +121,8 @@ set_target_properties( VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" EXPORT_NAME cmake-init-modules - OUTPUT_NAME cmake-init-modules) + OUTPUT_NAME cmake-init-modules +) target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) @@ -70,8 +139,7 @@ endif() enable_testing() if(PROJECT_IS_TOP_LEVEL) - option(BUILD_EXAMPLES "Build examples tree." - "${cmake-init-modules_DEVELOPER_MODE}") + option(BUILD_EXAMPLES "Build examples tree." "${cmake-init-modules_DEVELOPER_MODE}") if(BUILD_EXAMPLES) add_subdirectory(example) endif() @@ -82,9 +150,7 @@ endif() if(NOT cmake-init-modules_DEVELOPER_MODE) return() elseif(NOT PROJECT_IS_TOP_LEVEL) - message( - AUTHOR_WARNING - "Developer mode is intended for developers of cmake-init-modules") + message(AUTHOR_WARNING "Developer mode is intended for developers of cmake-init-modules") endif() include(cmake/dev-mode.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index 2d730e7..d3de749 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -196,6 +196,10 @@ "conan" ] }, + { + "name": "ci-Darwin", + "inherits": "ci-macos" + }, { "name": "ci-ubuntu", "inherits": [ @@ -206,6 +210,10 @@ "conan" ] }, + { + "name": "ci-Linux", + "inherits": "ci-ubuntu" + }, { "name": "ci-windows", "inherits": [ @@ -214,6 +222,10 @@ "dev-mode", "conan" ] + }, + { + "name": "ci-Windows", + "inherits": "ci-windows" } ] } diff --git a/GNUmakefile b/GNUmakefile index 9055112..6759b8b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,7 +1,6 @@ # Standard stuff .SUFFIXES: -$(VERBOSE).SILENT: MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. # MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. @@ -13,14 +12,16 @@ export CC?=clang-17 export CXX?=$(shell which clang++) export CMAKE_EXPORT_COMPILE_COMMANDS=YES +export hostSystemName=$(shell uname) + CONAN_HOME=$(shell conan config home) # BUILD_TYPE=Release BUILD_TYPE=Debug -.PHONY: all clean distclean check format test conan +.PHONY: all clean distclean check format test -all: conan - cmake --workflow --preset dev --fresh +all: .init conan + cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir test: all @@ -33,6 +34,10 @@ test: all check: test -run-clang-tidy -p build/dev +.init: .CMakeUserPresets.json + perl -p -e 's//${hostSystemName}/g;' .CMakeUserPresets.json > CMakeUserPresets.json + touch .init + conan: conanfile.py GNUmakefile conan profile detect -f conan install . -s build_type=$(BUILD_TYPE) -s compiler.cppstd=20 -b missing @@ -40,10 +45,15 @@ conan: conanfile.py GNUmakefile clean: rm -rf build -distclean: - rm -rf conan stagedir +distclean: clean + rm -rf conan stagedir .init CMakeUserPresets.json # XXX NO! git clean -xdf -format: +format: clean find . -name CMakeLists.txt -o -name '*.cmake' | xargs cmake-format -i git clang-format master + +# Anything we don't know how to build will use this rule. +# The command is a do-nothing command. +# +% :: ; diff --git a/algo-impl.cpp b/algo-impl.cpp new file mode 100644 index 0000000..26561ec --- /dev/null +++ b/algo-impl.cpp @@ -0,0 +1,10 @@ +module; + +#include + +module algo; + +void Algo::helloWorld() +{ + std::cout << "hello world\n"; +} diff --git a/algo-interface.cppm b/algo-interface.cppm new file mode 100644 index 0000000..2e7adf7 --- /dev/null +++ b/algo-interface.cppm @@ -0,0 +1,13 @@ +module; + +#include // <-- Generated header added to the global fragment + +export module + algo; // <-- Annotation not currently required, but see discussion below + +export class ALGO_EXPORT + Algo // <-- ALGO_EXPORT annotation added to the class definition +{ +public: + void helloWorld(); +}; diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index a0277c0..f7ead70 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -2,18 +2,14 @@ # We use variables separate from what CTest uses, because those have # customization issues -set(COVERAGE_TRACE_COMMAND - lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d - "${PROJECT_BINARY_DIR}" --include "${PROJECT_SOURCE_DIR}/*" - CACHE STRING - "; separated command to generate a trace for the 'coverage' target") +set(COVERAGE_TRACE_COMMAND lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d + "${PROJECT_BINARY_DIR}" --include "${PROJECT_SOURCE_DIR}/*" + CACHE STRING "; separated command to generate a trace for the 'coverage' target" +) -set(COVERAGE_HTML_COMMAND - genhtml --legend -f -q "${PROJECT_BINARY_DIR}/coverage.info" -p - "${PROJECT_SOURCE_DIR}" -o "${PROJECT_BINARY_DIR}/coverage_html" - CACHE - STRING - "; separated command to generate an HTML report for the 'coverage' target" +set(COVERAGE_HTML_COMMAND genhtml --legend -f -q "${PROJECT_BINARY_DIR}/coverage.info" -p + "${PROJECT_SOURCE_DIR}" -o "${PROJECT_BINARY_DIR}/coverage_html" + CACHE STRING "; separated command to generate an HTML report for the 'coverage' target" ) # ---- Coverage target ---- @@ -23,4 +19,5 @@ add_custom_target( COMMAND ${COVERAGE_TRACE_COMMAND} COMMAND ${COVERAGE_HTML_COMMAND} COMMENT "Generating coverage report" - VERBATIM) + VERBATIM +) diff --git a/cmake/docs-ci.cmake b/cmake/docs-ci.cmake index 8c7371a..b45eabd 100644 --- a/cmake/docs-ci.cmake +++ b/cmake/docs-ci.cmake @@ -13,19 +13,16 @@ set(src "${PROJECT_SOURCE_DIR}") set(mcss_SOURCE_DIR "${bin}/docs/.ci") if(NOT IS_DIRECTORY "${mcss_SOURCE_DIR}") file(MAKE_DIRECTORY "${mcss_SOURCE_DIR}") - file( - DOWNLOAD - https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip - "${mcss_SOURCE_DIR}/mcss.zip" - STATUS status - EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f) + file(DOWNLOAD https://github.com/friendlyanon/m.css/releases/download/release-1/mcss.zip + "${mcss_SOURCE_DIR}/mcss.zip" STATUS status EXPECTED_MD5 00cd2757ebafb9bcba7f5d399b3bec7f + ) if(NOT status MATCHES "^0;") message(FATAL_ERROR "Download failed with ${status}") endif() execute_process( - COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip - WORKING_DIRECTORY "${mcss_SOURCE_DIR}" - RESULT_VARIABLE result) + COMMAND "${CMAKE_COMMAND}" -E tar xf mcss.zip WORKING_DIRECTORY "${mcss_SOURCE_DIR}" + RESULT_VARIABLE result + ) if(NOT result EQUAL "0") message(FATAL_ERROR "Extraction failed with ${result}") endif() @@ -39,7 +36,9 @@ endif() # ---- Process project() call in CMakeLists.txt ---- -file(READ "${src}/CMakeLists.txt" content) +file( + READ "${src}/CMakeLists.txt" content +) string(FIND "${content}" "project(" index) if(index EQUAL "-1") @@ -53,7 +52,10 @@ if(index EQUAL "-1") endif() string(SUBSTRING "${content}" 0 "${index}" content) -file(WRITE "${bin}/docs-ci.project.cmake" "docs_${content}\n)\n") +file( + WRITE "${bin}/docs-ci.project.cmake" + "docs_${content}\n)\n" +) macro(list_pop_front list out) list(GET "${list}" 0 "${out}") @@ -61,35 +63,24 @@ macro(list_pop_front list out) endmacro() function(docs_project name) - cmake_parse_arguments(PARSE_ARGV 1 "" "" "VERSION;DESCRIPTION;HOMEPAGE_URL" - LANGUAGES) - set(PROJECT_NAME - "${name}" - PARENT_SCOPE) + cmake_parse_arguments(PARSE_ARGV 1 "" "" "VERSION;DESCRIPTION;HOMEPAGE_URL" LANGUAGES) + set(PROJECT_NAME "${name}" PARENT_SCOPE) if(DEFINED _VERSION) - set(PROJECT_VERSION - "${_VERSION}" - PARENT_SCOPE) + set(PROJECT_VERSION "${_VERSION}" PARENT_SCOPE) string(REGEX MATCH "^[0-9]+(\\.[0-9]+)*" versions "${_VERSION}") string(REPLACE . ";" versions "${versions}") set(suffixes MAJOR MINOR PATCH TWEAK) while(NOT versions STREQUAL "" AND NOT suffixes STREQUAL "") list_pop_front(versions version) list_pop_front(suffixes suffix) - set("PROJECT_VERSION_${suffix}" - "${version}" - PARENT_SCOPE) + set("PROJECT_VERSION_${suffix}" "${version}" PARENT_SCOPE) endwhile() endif() if(DEFINED _DESCRIPTION) - set(PROJECT_DESCRIPTION - "${_DESCRIPTION}" - PARENT_SCOPE) + set(PROJECT_DESCRIPTION "${_DESCRIPTION}" PARENT_SCOPE) endif() if(DEFINED _HOMEPAGE_URL) - set(PROJECT_HOMEPAGE_URL - "${_HOMEPAGE_URL}" - PARENT_SCOPE) + set(PROJECT_HOMEPAGE_URL "${_HOMEPAGE_URL}" PARENT_SCOPE) endif() endfunction() @@ -109,12 +100,14 @@ endforeach() set(mcss_script "${mcss_SOURCE_DIR}/documentation/doxygen.py") set(config "${bin}/docs/conf.py") -file(REMOVE_RECURSE "${out}/html" "${out}/xml") +file( + REMOVE_RECURSE "${out}/html" "${out}/xml" +) execute_process( - COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" - WORKING_DIRECTORY "${bin}/docs" - RESULT_VARIABLE result) + COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" WORKING_DIRECTORY "${bin}/docs" + RESULT_VARIABLE result +) if(NOT result EQUAL "0") message(FATAL_ERROR "m.css returned with ${result}") endif() diff --git a/cmake/docs.cmake b/cmake/docs.cmake index 7a1ef7e..ded1e01 100644 --- a/cmake/docs.cmake +++ b/cmake/docs.cmake @@ -12,16 +12,17 @@ FetchContent_Declare( URL_MD5 00cd2757ebafb9bcba7f5d399b3bec7f SOURCE_DIR "${PROJECT_BINARY_DIR}/mcss" UPDATE_DISCONNECTED YES - ${extract_timestamps}) + ${extract_timestamps} +) FetchContent_MakeAvailable(mcss) find_package(Python3 3.6 REQUIRED) # ---- Declare documentation target ---- -set(DOXYGEN_OUTPUT_DIRECTORY - "${PROJECT_BINARY_DIR}/docs" - CACHE PATH "Path for the generated Doxygen documentation") +set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" + CACHE PATH "Path for the generated Doxygen documentation" +) set(working_dir "${PROJECT_BINARY_DIR}/docs") @@ -34,9 +35,10 @@ set(config "${working_dir}/conf.py") add_custom_target( docs - COMMAND "${CMAKE_COMMAND}" -E remove_directory - "${DOXYGEN_OUTPUT_DIRECTORY}/html" "${DOXYGEN_OUTPUT_DIRECTORY}/xml" + COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOXYGEN_OUTPUT_DIRECTORY}/html" + "${DOXYGEN_OUTPUT_DIRECTORY}/xml" COMMAND "${Python3_EXECUTABLE}" "${mcss_script}" "${config}" COMMENT "Building documentation using Doxygen and m.css" WORKING_DIRECTORY "${working_dir}" - VERBATIM) + VERBATIM +) diff --git a/cmake/folders.cmake b/cmake/folders.cmake index 7bbb770..da7bd33 100644 --- a/cmake/folders.cmake +++ b/cmake/folders.cmake @@ -5,23 +5,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS YES) # UtilityTargets folder, otherwise to the ${name}Targets folder. If a target # already has a folder assigned, then that target will be skipped. function(add_folders name) - get_property( - targets - DIRECTORY - PROPERTY BUILDSYSTEM_TARGETS) + get_property(targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS) foreach(target IN LISTS targets) - get_property( - folder - TARGET "${target}" - PROPERTY FOLDER) + get_property(folder TARGET "${target}" PROPERTY FOLDER) if(DEFINED folder) continue() endif() set(folder Utility) - get_property( - type - TARGET "${target}" - PROPERTY TYPE) + get_property(type TARGET "${target}" PROPERTY TYPE) if(NOT type STREQUAL "UTILITY") set(folder "${name}") endif() diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 346cf65..fefd2db 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -1,7 +1,5 @@ if(PROJECT_IS_TOP_LEVEL) - set(CMAKE_INSTALL_INCLUDEDIR - "include/cmake-init-modules-${PROJECT_VERSION}" - CACHE PATH "") + set(CMAKE_INSTALL_INCLUDEDIR "include/cmake-init-modules-${PROJECT_VERSION}" CACHE PATH "") endif() include(CMakePackageConfigHelpers) @@ -21,31 +19,33 @@ install(TARGETS cmake-init-modules_cmake-init-modules ) # cmake-format: on -write_basic_package_version_file("${package}ConfigVersion.cmake" - COMPATIBILITY SameMajorVersion) +write_basic_package_version_file("${package}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion) # Allow package maintainers to freely override the path for the configs -set(cmake-init-modules_INSTALL_CMAKEDIR - "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" - CACHE PATH "CMake package config location relative to the install prefix") +set(cmake-init-modules_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}" + CACHE PATH "CMake package config location relative to the install prefix" +) mark_as_advanced(cmake-init-modules_INSTALL_CMAKEDIR) install( FILES cmake/install-config.cmake DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" RENAME "${package}Config.cmake" - COMPONENT cmake-init-modules_Development) + COMPONENT cmake-init-modules_Development +) install( FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake" DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - COMPONENT cmake-init-modules_Development) + COMPONENT cmake-init-modules_Development +) install( EXPORT cmake-init-modulesTargets NAMESPACE cmake-init-modules:: DESTINATION "${cmake-init-modules_INSTALL_CMAKEDIR}" - COMPONENT cmake-init-modules_Development) + COMPONENT cmake-init-modules_Development +) if(PROJECT_IS_TOP_LEVEL) set(CPACK_GENERATOR TGZ) diff --git a/cmake/lint-targets.cmake b/cmake/lint-targets.cmake index 0c02f24..f3790c0 100644 --- a/cmake/lint-targets.cmake +++ b/cmake/lint-targets.cmake @@ -6,28 +6,25 @@ set(FORMAT_PATTERNS test/*.hpp example/*.cpp example/*.hpp - CACHE STRING - "; separated patterns relative to the project source dir to format") + CACHE STRING "; separated patterns relative to the project source dir to format" +) -set(FORMAT_COMMAND - clang-format - CACHE STRING "Formatter to use") +set(FORMAT_COMMAND clang-format CACHE STRING "Formatter to use") add_custom_target( format-check - COMMAND - "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D - "PATTERNS=${FORMAT_PATTERNS}" -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" + -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Linting the code" - VERBATIM) + VERBATIM +) add_custom_target( format-fix - COMMAND - "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D - "PATTERNS=${FORMAT_PATTERNS}" -D FIX=YES -P - "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" + COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" + -D FIX=YES -P "${PROJECT_SOURCE_DIR}/cmake/lint.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Fixing the code" - VERBATIM) + VERBATIM +) diff --git a/cmake/lint.cmake b/cmake/lint.cmake index 949723a..b536270 100644 --- a/cmake/lint.cmake +++ b/cmake/lint.cmake @@ -15,7 +15,8 @@ default( test/*.cpp test/*.hpp example/*.cpp - example/*.hpp) + example/*.hpp +) default(FIX NO) set(flag --output-replacements-xml) @@ -25,7 +26,9 @@ if(FIX) set(args "") endif() -file(GLOB_RECURSE files ${PATTERNS}) +file( + GLOB_RECURSE files ${PATTERNS} +) set(badly_formatted "") set(output "") string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length) @@ -33,8 +36,8 @@ string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length) foreach(file IN LISTS files) execute_process( COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result ${args}) + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE result ${args} + ) if(NOT result EQUAL "0") message(FATAL_ERROR "'${file}': formatter returned with ${result}") endif() diff --git a/cmake/my_package-config.cmake b/cmake/my_package-config.cmake new file mode 100644 index 0000000..ec5deb9 --- /dev/null +++ b/cmake/my_package-config.cmake @@ -0,0 +1,4 @@ +# include(CMakeFindDependencyMacro) +# find_dependency(fmt) + +include("${CMAKE_CURRENT_LIST_DIR}/my_package-targets.cmake") diff --git a/cmake/prelude.cmake b/cmake/prelude.cmake index 3978064..f80c416 100644 --- a/cmake/prelude.cmake +++ b/cmake/prelude.cmake @@ -5,5 +5,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) FATAL_ERROR "In-source builds are not supported. " "Please read the BUILDING document before trying to build this project. " - "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first.") + "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." + ) endif() diff --git a/cmake/spell-targets.cmake b/cmake/spell-targets.cmake index 10c30e6..16c6111 100644 --- a/cmake/spell-targets.cmake +++ b/cmake/spell-targets.cmake @@ -1,6 +1,4 @@ -set(SPELL_COMMAND - codespell - CACHE STRING "Spell checker to use") +set(SPELL_COMMAND codespell CACHE STRING "Spell checker to use") add_custom_target( spell-check @@ -8,7 +6,8 @@ add_custom_target( "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Checking spelling" - VERBATIM) + VERBATIM +) add_custom_target( spell-fix @@ -16,4 +15,5 @@ add_custom_target( "${PROJECT_SOURCE_DIR}/cmake/spell.cmake" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMENT "Fixing spelling errors" - VERBATIM) + VERBATIM +) diff --git a/cmake/spell.cmake b/cmake/spell.cmake index c9e5416..a4f3c36 100644 --- a/cmake/spell.cmake +++ b/cmake/spell.cmake @@ -15,9 +15,8 @@ if(FIX) endif() execute_process( - COMMAND "${SPELL_COMMAND}" ${flag} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result) + COMMAND "${SPELL_COMMAND}" ${flag} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE result +) if(result EQUAL "65") message(FATAL_ERROR "Run again with FIX=YES to fix these errors.") diff --git a/cmake/variables.cmake b/cmake/variables.cmake index d657225..d96c946 100644 --- a/cmake/variables.cmake +++ b/cmake/variables.cmake @@ -20,7 +20,8 @@ set(pragma_suppress_c4251 #else # define CMAKE_INIT_MODULES_SUPPRESS_C4251 #endif -") +" +) # ---- Warning guard ---- @@ -30,10 +31,9 @@ set(pragma_suppress_c4251 # or FetchContent is used to consume this project set(warning_guard "") if(NOT PROJECT_IS_TOP_LEVEL) - option( - cmake-init-modules_INCLUDES_WITH_SYSTEM - "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" - ON) + option(cmake-init-modules_INCLUDES_WITH_SYSTEM + "Use SYSTEM modifier for cmake-init-modules's includes, disabling warnings" ON + ) mark_as_advanced(cmake-init-modules_INCLUDES_WITH_SYSTEM) if(cmake-init-modules_INCLUDES_WITH_SYSTEM) set(warning_guard SYSTEM) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index e109098..3881c2d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -6,21 +6,29 @@ include(../cmake/folders.cmake) if(PROJECT_IS_TOP_LEVEL) find_package(cmake-init-modules REQUIRED) + find_package(my_package REQUIRED) + enable_testing() endif() -enable_testing() +# Neither of these two are technically needed, but they make the expectation clear +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_EXTENSIONS FALSE) + +add_executable(app main.cpp) +target_link_libraries(app PRIVATE Algo) +add_test(NAME app COMMAND app) + +# return() + +################################################## add_custom_target(run-examples) function(add_example NAME) add_executable("${NAME}" "${NAME}.cpp") - target_link_libraries("${NAME}" - PRIVATE cmake-init-modules::cmake-init-modules) + target_link_libraries("${NAME}" PRIVATE cmake-init-modules::cmake-init-modules) target_compile_features("${NAME}" PRIVATE cxx_std_20) - add_custom_target( - "run_${NAME}" - COMMAND "${NAME}" - VERBATIM) + add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM) add_dependencies("run_${NAME}" "${NAME}") add_dependencies(run-examples "run_${NAME}") add_test(NAME ${NAME} COMMAND ${NAME}) diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..3c4bc3a --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,9 @@ +import algo; + +auto main() -> int +{ + Algo sut; + sut.helloWorld(); + + return 0; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a4de65d..8fb731b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,8 +18,8 @@ include(Catch) add_executable(cmake-init-modules_test source/cmake-init-modules_test.cpp) target_link_libraries( - cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules - Catch2::Catch2WithMain) + cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules Catch2::Catch2WithMain +) target_compile_features(cmake-init-modules_test PRIVATE cxx_std_20) catch_discover_tests(cmake-init-modules_test) From 720984c58b2362fce6a0326f0709ec5fee57aeb9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 9 Apr 2024 11:15:31 +0200 Subject: [PATCH 13/57] Try to use clang-17 on CI --- .github/workflows/ci.yml | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e189c7..4d2bb12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-15 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-17 -P cmake/lint.cmake - name: Spell check if: always() @@ -35,6 +35,8 @@ jobs: runs-on: ubuntu-22.04 + env: { CXX: clang++-17 } + # To enable coverage, delete the last line from the conditional below and # edit the "" placeholder to your GitHub name. # If you do not wish to use codecov, then simply delete this job from the @@ -53,6 +55,17 @@ jobs: uses: actions/setup-python@v5 with: { python-version: "3.10" } + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + compiler: llvm-17 + vcvarsall: ${{ contains(matrix.os, 'windows') }} + # conan: true + # vcpkg: true + clangformat: true + clangtidy: true + # ... + - name: Install dependencies run: | pip3 install conan cmake ninja gcovr @@ -82,7 +95,7 @@ jobs: runs-on: ubuntu-22.04 - env: { CXX: clang++-15 } + env: { CXX: clang++-17 } steps: - uses: actions/checkout@v4 @@ -91,6 +104,17 @@ jobs: uses: actions/setup-python@v5 with: { python-version: "3.10" } + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + compiler: llvm-17 + vcvarsall: ${{ contains(matrix.os, 'windows') }} + # conan: true + # vcpkg: true + clangformat: true + clangtidy: true + # ... + - name: Install dependencies run: | pip3 install conan cmake ninja @@ -138,7 +162,7 @@ jobs: if: matrix.os != 'windows-2022' uses: aminya/setup-cpp@v1 with: - compiler: llvm-15 + compiler: llvm-17 vcvarsall: ${{ contains(matrix.os, 'windows') }} # conan: true # vcpkg: true From f9562812c297c0a7fc0e6048583db32ea67a6b9c Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Tue, 9 Apr 2024 14:45:07 +0200 Subject: [PATCH 14/57] The final cut install cmake config version file too --- .clang-tidy | 14 +++++++++----- .gitignore | 1 + CMakeLists.txt | 7 +++++++ GNUmakefile | 1 + algo-impl.cpp | 2 +- algo-interface.cppm | 6 ++++++ example/CMakeLists.txt | 4 ++-- example/main.cpp | 2 +- requirements.txt | 14 ++++++++++++++ 9 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 requirements.txt diff --git a/.clang-tidy b/.clang-tidy index 3fd7b57..9f21c5e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,17 +3,21 @@ # misc-non-private-member-variables-in-classes: the options don't do anything # modernize-use-nodiscard: too aggressive, attribute is situationally useful Checks: "*,\ - -google-readability-todo,\ + google-readability-todo,\ -altera-*,\ -fuchsia-*,\ fuchsia-multiple-inheritance,\ -llvm-header-guard,\ -llvm-include-order,\ -llvmlibc-*,\ - -modernize-use-nodiscard,\ - -misc-non-private-member-variables-in-classes,\ - -readability-avoid-unconditional-preprocessor-if" -WarningsAsErrors: '' + modernize-use-nodiscard,\ + misc-non-private-member-variables-in-classes,\ + -misc-include-cleaner,\ + -readability-identifier-naming,\ + -readability-redundant-declaration,\ + readability-avoid-unconditional-preprocessor-if\ +" +WarningsAsErrors: '*' CheckOptions: - key: 'bugprone-argument-comment.StrictMode' value: 'true' diff --git a/.gitignore b/.gitignore index 9fe1178..2c7eb06 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ prefix/ stagedir/ .clangd .init +*.swp CMakeLists.txt.user CMakeUserPresets.json compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 53a32a6..bf641ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ target_sources(Algo ) include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +write_basic_package_version_file("my_package-config-version.cmake" COMPATIBILITY SameMajorVersion) install(TARGETS Algo EXPORT my_package-targets @@ -56,6 +59,10 @@ install(EXPORT my_package-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package CXX_MODULES_DIRECTORY . ) +install( + FILES "${PROJECT_BINARY_DIR}/my_package-config-version.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package +) # The following file includes the my_package-targets.cmake file install(FILES cmake/my_package-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package diff --git a/GNUmakefile b/GNUmakefile index 6759b8b..7898f72 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -33,6 +33,7 @@ test: all check: test -run-clang-tidy -p build/dev + -iwyu_tool -p build/dev/ *.cpp -- -Xiwyu --cxx17ns .init: .CMakeUserPresets.json perl -p -e 's//${hostSystemName}/g;' .CMakeUserPresets.json > CMakeUserPresets.json diff --git a/algo-impl.cpp b/algo-impl.cpp index 26561ec..e30df24 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -6,5 +6,5 @@ module algo; void Algo::helloWorld() { - std::cout << "hello world\n"; + std::cout << "hello " << m_name << "\n"; } diff --git a/algo-interface.cppm b/algo-interface.cppm index 2e7adf7..b941e51 100644 --- a/algo-interface.cppm +++ b/algo-interface.cppm @@ -1,6 +1,8 @@ module; #include // <-- Generated header added to the global fragment +#include // for string +#include // for move export module algo; // <-- Annotation not currently required, but see discussion below @@ -9,5 +11,9 @@ export class ALGO_EXPORT Algo // <-- ALGO_EXPORT annotation added to the class definition { public: + explicit Algo(std::string name) : m_name(std::move(name)) {} void helloWorld(); + +private: + std::string m_name; }; diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 3881c2d..f335502 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -5,8 +5,8 @@ project(cmake-init-modulesExamples CXX) include(../cmake/folders.cmake) if(PROJECT_IS_TOP_LEVEL) - find_package(cmake-init-modules REQUIRED) - find_package(my_package REQUIRED) + find_package(cmake-init-modules 0.1 REQUIRED) + find_package(my_package 0.1 REQUIRED) enable_testing() endif() diff --git a/example/main.cpp b/example/main.cpp index 3c4bc3a..272a020 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -2,7 +2,7 @@ import algo; auto main() -> int { - Algo sut; + Algo sut("cmake professionals"); sut.helloWorld(); return 0; diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1371d57 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +# +# usage: pip install -U -r requirements.txt +# +Pygments>=2.17 +builddriver>=0.9 +cmake-init>=0.40.5 +cmake>=3.28.4 +cmakelint>=1.4.2 +codespell>=2.2.6 +conan>=2.2 +gcovr>=7.2 +jinja2>=3.1.3 +ninja>=1.11.1 +yamllint>=1.35 From 6dc3a08482a60119263834fe64ddac4743b1e7e8 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Tue, 9 Apr 2024 15:39:33 +0200 Subject: [PATCH 15/57] Use format lib --- .gitignore | 1 + CMakeLists.txt | 1 + algo-impl.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2c7eb06..9bff477 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ stagedir/ CMakeLists.txt.user CMakeUserPresets.json compile_commands.json +tags diff --git a/CMakeLists.txt b/CMakeLists.txt index bf641ae..4ce6bc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ target_sources(Algo FILES algo-interface.cppm ) +target_link_libraries(Algo PRIVATE fmt::fmt) # CMake requires the language standard to be specified as compile feature # when a target provides C++20 modules and the target will be installed diff --git a/algo-impl.cpp b/algo-impl.cpp index e30df24..f1fd2d7 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -1,10 +1,12 @@ module; -#include +// XXX #include +#include module algo; void Algo::helloWorld() { - std::cout << "hello " << m_name << "\n"; + // XXX std::cout << "hello " << m_name << "\n"; + fmt::print("hello {}\n", m_name); } From 6e9cb75994c4b740fd235cb4a5cbce6a12bf4b82 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Tue, 9 Apr 2024 15:57:36 +0200 Subject: [PATCH 16/57] Use clang-17 on CI --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d2bb12..80b8ba3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-17 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-14 -P cmake/lint.cmake - name: Spell check if: always() @@ -158,6 +158,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@v5 + with: { python-version: "3.10" } + - name: Setup Cpp if: matrix.os != 'windows-2022' uses: aminya/setup-cpp@v1 @@ -170,10 +174,6 @@ jobs: clangtidy: true # ... - - name: Install Python - uses: actions/setup-python@v5 - with: { python-version: "3.10" } - - name: Install dependencies shell: bash run: | From 40028438c3acdfb68d7f2f90ae0800b4fb4c8c80 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Tue, 9 Apr 2024 16:41:05 +0200 Subject: [PATCH 17/57] NO check readability-avoid-unconditional-preprocessor-if --- .clang-tidy | 2 +- CMakeLists.txt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9f21c5e..fefd0a9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,7 @@ Checks: "*,\ -misc-include-cleaner,\ -readability-identifier-naming,\ -readability-redundant-declaration,\ - readability-avoid-unconditional-preprocessor-if\ + -readability-avoid-unconditional-preprocessor-if\ " WarningsAsErrors: '*' CheckOptions: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ce6bc6..7378740 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,10 @@ target_link_libraries(Algo PRIVATE fmt::fmt) target_compile_features(Algo PUBLIC cxx_std_20) include(GenerateExportHeader) -generate_export_header(Algo) +generate_export_header(Algo + CUSTOM_CONTENT_FROM_VARIABLE + pragma_suppress_c4251 +) target_sources(Algo PUBLIC FILE_SET HEADERS From 5e14c37af0b2139e751f0c0a331236c70bef7eda Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 9 Apr 2024 23:14:12 +0200 Subject: [PATCH 18/57] Use fmt::fmt-header-only with CPM.cmake --- CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++------ CMakePresets.json | 12 +++++------ GNUmakefile | 3 ++- algo-impl.cpp | 3 +-- cmake/CPM.cmake | 26 ++++++++++++++++++++++ cmake/install-config.cmake | 4 ++-- 6 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 cmake/CPM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7378740..29258c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,16 +6,45 @@ project(cxx_modules_example VERSION 0.1.0 LANGUAGES CXX) # This property setting also needs to be consistent between the # installed shared library and its consumer, otherwise most -# toolchains will once again reject the consumer’s generated BMI. -set(CMAKE_CXX_EXTENSIONS FALSE) +# toolchains will once again reject the consumer's generated BMI. + +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_EXTENSIONS FALSE) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +endif() set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) -add_library(Algo SHARED) +include(cmake/CPM.cmake) + +# Disable clang-tidy for target +macro(target_disable_clang_tidy TARGET) + 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() ######################################################################### # cmake-format: off + +# instead of find_package(fmt REQUIRED) +cpmaddpackage( + NAME fmt + GIT_TAG 10.2.1 + GITHUB_REPOSITORY fmtlib/fmt + SYSTEM YES + #FIXME(CK): OPTIONS "FMT_MODULE ON" +) +if(TARGET fmt) + target_disable_clang_tidy(fmt) +endif() + +add_library(Algo SHARED) + target_sources(Algo PRIVATE algo-impl.cpp @@ -24,7 +53,8 @@ target_sources(Algo FILES algo-interface.cppm ) -target_link_libraries(Algo PRIVATE fmt::fmt) +#XXX target_link_libraries(Algo PRIVATE fmt::fmt) +target_link_libraries(Algo PRIVATE $) # CMake requires the language standard to be specified as compile feature # when a target provides C++20 modules and the target will be installed @@ -137,8 +167,10 @@ set_target_properties( target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) -find_package(fmt REQUIRED) -target_link_libraries(cmake-init-modules_cmake-init-modules PRIVATE fmt::fmt) +#XXX target_link_libraries(cmake-init-modules_cmake-init-modules PRIVATE fmt::fmt) +target_link_libraries( + cmake-init-modules_cmake-init-modules PRIVATE $ +) # ---- Install rules ---- diff --git a/CMakePresets.json b/CMakePresets.json index d3de749..a2d1590 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,7 +26,7 @@ "hidden": true, "inherits": "cmake-pedantic", "cacheVariables": { - "cmake-init-modules_DEVELOPER_MODE": "ON" + "cmake-init-modules_DEVELOPER_MODE": true } }, { @@ -57,9 +57,9 @@ "description": "This preset makes sure the project actually builds with at least the specified standard", "hidden": true, "cacheVariables": { - "CMAKE_CXX_EXTENSIONS": "OFF", + "CMAKE_CXX_EXTENSIONS": false, "CMAKE_CXX_STANDARD": "20", - "CMAKE_CXX_STANDARD_REQUIRED": "ON" + "CMAKE_CXX_STANDARD_REQUIRED": true } }, { @@ -144,8 +144,8 @@ "inherits": "ci-linux", "hidden": true, "cacheVariables": { - "ENABLE_COVERAGE": "ON", - "CMAKE_SKIP_INSTALL_RULES": "ON", + "ENABLE_COVERAGE": true, + "CMAKE_SKIP_INSTALL_RULES": true, "CMAKE_BUILD_TYPE": "Coverage", "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions", "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", @@ -173,7 +173,7 @@ "conan" ], "cacheVariables": { - "CMAKE_SKIP_INSTALL_RULES": "ON", + "CMAKE_SKIP_INSTALL_RULES": true, "CMAKE_BUILD_TYPE": "Sanitize", "CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common", "CMAKE_MAP_IMPORTED_CONFIG_SANITIZE": "Sanitize;RelWithDebInfo;Release;Debug" diff --git a/GNUmakefile b/GNUmakefile index 7898f72..ca76662 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -11,6 +11,7 @@ MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. export CC?=clang-17 export CXX?=$(shell which clang++) export CMAKE_EXPORT_COMPILE_COMMANDS=YES +export CPM_USE_LOCAL_PACKAGES=NO export hostSystemName=$(shell uname) @@ -50,7 +51,7 @@ distclean: clean rm -rf conan stagedir .init CMakeUserPresets.json # XXX NO! git clean -xdf -format: clean +format: distclean find . -name CMakeLists.txt -o -name '*.cmake' | xargs cmake-format -i git clang-format master diff --git a/algo-impl.cpp b/algo-impl.cpp index f1fd2d7..4cbcc5a 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -1,12 +1,11 @@ module; -// XXX #include #include +//TODO(CK): import fmt; module algo; void Algo::helloWorld() { - // XXX std::cout << "hello " << m_name << "\n"; fmt::print("hello {}\n", m_name); } diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..b03800f --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.39.0) +set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file( + DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/install-config.cmake b/cmake/install-config.cmake index dcd03e6..3aa6089 100644 --- a/cmake/install-config.cmake +++ b/cmake/install-config.cmake @@ -1,4 +1,4 @@ -include(CMakeFindDependencyMacro) -find_dependency(fmt) +# include(CMakeFindDependencyMacro) +# find_dependency(fmt) include("${CMAKE_CURRENT_LIST_DIR}/cmake-init-modulesTargets.cmake") From 7384b6703ef7ab510fa267c30e3d1ed6823b47ad Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 10 Apr 2024 14:37:55 +0200 Subject: [PATCH 19/57] use setup-cpp only on ubuntu --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80b8ba3..bc7ee3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,7 @@ jobs: with: { python-version: "3.10" } - name: Setup Cpp + if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: compiler: llvm-17 @@ -105,6 +106,7 @@ jobs: with: { python-version: "3.10" } - name: Setup Cpp + if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: compiler: llvm-17 @@ -155,6 +157,8 @@ jobs: runs-on: ${{ matrix.os }} + env: { CXX: clang++-17 } + steps: - uses: actions/checkout@v4 @@ -163,7 +167,7 @@ jobs: with: { python-version: "3.10" } - name: Setup Cpp - if: matrix.os != 'windows-2022' + if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: compiler: llvm-17 From bf10d52ce7894eebdfebfa30b24f78f3f9b7c980 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 10:09:21 +0200 Subject: [PATCH 20/57] Install llvm-17 with brew on macos --- .github/workflows/ci.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc7ee3a..eb157ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,12 +84,13 @@ jobs: run: ctest --output-on-failure --no-tests=error -j 2 - name: Process coverage info - run: cmake --build build/coverage -t coverage + # run: cmake --build build/coverage -t coverage + run: gcovr . - - name: Submit to codecov.io - uses: codecov/codecov-action@v4 - with: - file: build/coverage/coverage.info + # - name: Submit to codecov.io + # uses: codecov/codecov-action@v4 + # with: + # file: build/coverage/coverage.info sanitize: needs: [lint] @@ -157,15 +158,24 @@ jobs: runs-on: ${{ matrix.os }} - env: { CXX: clang++-17 } + env: { CXX: clang++ } steps: - uses: actions/checkout@v4 - name: Install Python + if: matrix.os != 'macos-14' uses: actions/setup-python@v5 with: { python-version: "3.10" } + - name: Install llvm-17 + if: matrix.os == 'macos-14' + run: | + brew install llvm + echo $(brew --prefix llvm@17)/bin + echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile + export PATH=$(brew --prefix llvm@17)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV + - name: Setup Cpp if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 From 33bd5f007679cd040683f30e5bec236003c65e75 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 10:23:43 +0200 Subject: [PATCH 21/57] Quickfix to prevent pip install on macox --- .github/workflows/ci.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb157ef..ec261a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,10 +61,12 @@ jobs: with: compiler: llvm-17 vcvarsall: ${{ contains(matrix.os, 'windows') }} - # conan: true - # vcpkg: true clangformat: true clangtidy: true + cmake: true + conan: true + gcovr: true + ninja: true # ... - name: Install dependencies @@ -107,20 +109,21 @@ jobs: with: { python-version: "3.10" } - name: Setup Cpp - if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: compiler: llvm-17 vcvarsall: ${{ contains(matrix.os, 'windows') }} - # conan: true - # vcpkg: true clangformat: true clangtidy: true + cmake: true + conan: true + gcovr: true + ninja: true # ... - name: Install dependencies run: | - pip3 install conan cmake ninja + # pip3 install conan cmake ninja bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -182,16 +185,18 @@ jobs: with: compiler: llvm-17 vcvarsall: ${{ contains(matrix.os, 'windows') }} - # conan: true - # vcpkg: true clangformat: true clangtidy: true + cmake: true + conan: true + gcovr: true + ninja: true # ... - name: Install dependencies shell: bash run: | - pip3 install conan cmake ninja gcovr + # pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh conan install . -b missing From 99b001e99ee333428a8c0b0b88fa9bed97ed6b34 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 11:52:23 +0200 Subject: [PATCH 22/57] Hotfix for conon profile --- .github/scripts/conan-profile.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/scripts/conan-profile.sh b/.github/scripts/conan-profile.sh index d201862..757784d 100644 --- a/.github/scripts/conan-profile.sh +++ b/.github/scripts/conan-profile.sh @@ -1,8 +1,17 @@ #!/bin/bash set -e +set -u +set -x -conan profile detect -f +pip3 install --upgrade pip || echo ignored +pip3 install conan cmake ninja gcovr || echo ignored + +conan --version +conan profile --help +conan profile new --help +conan profile update --help +conan profile update || conan profile detect --force std=20 if [ "$RUNNER_OS" = Windows ]; then From 8c3fba61bc2ba03be051f9e1ec82f4694ce35ce3 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 13:35:00 +0200 Subject: [PATCH 23/57] Prevent to install old conon version --- .github/scripts/conan-profile.sh | 5 ++--- .github/workflows/ci.yml | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/scripts/conan-profile.sh b/.github/scripts/conan-profile.sh index 757784d..51a1588 100644 --- a/.github/scripts/conan-profile.sh +++ b/.github/scripts/conan-profile.sh @@ -7,11 +7,10 @@ set -x pip3 install --upgrade pip || echo ignored pip3 install conan cmake ninja gcovr || echo ignored +which conan conan --version conan profile --help -conan profile new --help -conan profile update --help -conan profile update || conan profile detect --force +conan profile detect --force std=20 if [ "$RUNNER_OS" = Windows ]; then diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec261a8..bf8a015 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: clangformat: true clangtidy: true cmake: true - conan: true + # conan: true gcovr: true ninja: true # ... @@ -116,7 +116,7 @@ jobs: clangformat: true clangtidy: true cmake: true - conan: true + # conan: true gcovr: true ninja: true # ... @@ -188,7 +188,7 @@ jobs: clangformat: true clangtidy: true cmake: true - conan: true + # conan: true gcovr: true ninja: true # ... From 38cd02b923b424df7eee21fef15b2d25c91b1a1f Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 13:47:36 +0200 Subject: [PATCH 24/57] Be not pedantic --- CMakePresets.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index a2d1590..5507174 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -17,8 +17,8 @@ "systemVars": false }, "errors": { - "dev": true, - "deprecated": true + "dev": false, + "deprecated": false } }, { From 767be54005fee7c95526f94b311ccaa6d6ae2499 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 14:01:27 +0200 Subject: [PATCH 25/57] Disable clang-tidy as cxx modules are not supported --- CMakePresets.json | 1 - include/cmake-init-modules/cmake-init-modules.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 5507174..d90a38e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -205,7 +205,6 @@ "inherits": [ "ci-build", "ci-linux", - "clang-tidy", "dev-mode", "conan" ] diff --git a/include/cmake-init-modules/cmake-init-modules.hpp b/include/cmake-init-modules/cmake-init-modules.hpp index 4cc561a..5d3b290 100644 --- a/include/cmake-init-modules/cmake-init-modules.hpp +++ b/include/cmake-init-modules/cmake-init-modules.hpp @@ -62,7 +62,7 @@ class CMAKE_INIT_MODULES_EXPORT exported_class /** * @brief Returns a non-owning pointer to the string stored in this class */ - auto name() const -> char const*; + [[nodiscard]] auto name() const -> char const*; private: CMAKE_INIT_MODULES_SUPPRESS_C4251 From fb09d452ebb51df4484b5ae23a7d62d7572659d2 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 14:37:21 +0200 Subject: [PATCH 26/57] Add TestInstalledVersion to CI for unix only --- .CMakeUserPresets.json | 2 +- .github/workflows/ci.yml | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 2765815..aa00925 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -18,7 +18,7 @@ "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, "BUILD_MCSS_DOCS": false, - "BUILD_SHARED_LIBS": true + "BUILD_SHARED_LIBS": false } }, { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf8a015..a4a24e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -225,18 +225,17 @@ jobs: working-directory: build run: ctest --output-on-failure --no-tests=error -C Release -j 2 - - name: TestInstalledVersion - if: matrix.os == 'ubuntu-22.04' - run: | - ln -sf .CMakeUserPresets.json CMakeUserPresets.json - VERBOSE=1 BUILD_SHARED_LIBS=${{ matrix.shared }} gmake test + # - name: TestInstalledVersion + # if: matrix.os == 'ubuntu-22.04' + # run: | + # BUILD_SHARED_LIBS=${{ matrix.shared }} gmake test - name: TestInstalledVersion - if: matrix.os == 'macos-14' + if: matrix.os != 'windows-2022' run: | cmake -B example/build -S example -G Ninja -D CMAKE_BUILD_TYPE=Release \ - -D 'CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan' \ - --toolchain $PWD/conan/conan_toolchain.cmake + -D "CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan" \ + --toolchain "$PWD/conan/conan_toolchain.cmake" ninja -C example/build ninja -C example/build test From e29c12d1f6a163160f3781529723df72daff3bc3 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 16:36:22 +0200 Subject: [PATCH 27/57] Install conan with brew on macos CI --- .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 a4a24e7..847a55c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,7 +174,7 @@ jobs: - name: Install llvm-17 if: matrix.os == 'macos-14' run: | - brew install llvm + brew install conan gcovr ninja llvm echo $(brew --prefix llvm@17)/bin echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile export PATH=$(brew --prefix llvm@17)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV From d0accd65d262f4ff2843e757bb763b66868695eb Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 11 Apr 2024 16:50:01 +0200 Subject: [PATCH 28/57] Prevent use of clang++ on windows CI --- .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 847a55c..28f9f1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,7 +161,7 @@ jobs: runs-on: ${{ matrix.os }} - env: { CXX: clang++ } + # env: { CXX: clang++ } steps: - uses: actions/checkout@v4 From 249839d91d9f1d0a32282509e81dc34e104052b0 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 18:13:29 +0200 Subject: [PATCH 29/57] Add gcovr.cfg --- .CMakeUserPresets.json | 6 ++++-- CMakePresets.json | 15 +++++++++++++++ GNUmakefile | 2 ++ algo-impl.cpp | 3 ++- algo-interface.cppm | 12 ++++++++---- gcovr.cfg | 23 +++++++++++++++++++++++ 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 gcovr.cfg diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index aa00925..362508a 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -24,21 +24,23 @@ { "name": "dev-Linux", "inherits": [ + "coverage-linux", "dev-common", "ci-linux" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Coverage" } }, { "name": "dev-Darwin", "inherits": [ + "coverage-darwin", "dev-common", "ci-darwin" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Coverage" } }, { diff --git a/CMakePresets.json b/CMakePresets.json index d90a38e..b160e89 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -153,6 +153,21 @@ "CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug" } }, + { + "name": "coverage-darwin", + "binaryDir": "${sourceDir}/build/coverage", + "inherits": "ci-darwin", + "hidden": true, + "cacheVariables": { + "ENABLE_COVERAGE": true, + "CMAKE_SKIP_INSTALL_RULES": true, + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage", + "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", + "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage", + "CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug" + } + }, { "name": "ci-coverage", "inherits": [ diff --git a/GNUmakefile b/GNUmakefile index ca76662..02ee11f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -24,6 +24,7 @@ BUILD_TYPE=Debug all: .init conan cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir + gcovr test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ @@ -38,6 +39,7 @@ check: test .init: .CMakeUserPresets.json perl -p -e 's//${hostSystemName}/g;' .CMakeUserPresets.json > CMakeUserPresets.json + mkdir -p build/coverage/ touch .init conan: conanfile.py GNUmakefile diff --git a/algo-impl.cpp b/algo-impl.cpp index 4cbcc5a..b61eafe 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -1,10 +1,11 @@ module; #include -//TODO(CK): import fmt; module algo; +// TODO(CK): import fmt; + void Algo::helloWorld() { fmt::print("hello {}\n", m_name); diff --git a/algo-interface.cppm b/algo-interface.cppm index b941e51..7c876a0 100644 --- a/algo-interface.cppm +++ b/algo-interface.cppm @@ -1,8 +1,9 @@ module; +#include // for string +#include // for move + #include // <-- Generated header added to the global fragment -#include // for string -#include // for move export module algo; // <-- Annotation not currently required, but see discussion below @@ -11,9 +12,12 @@ export class ALGO_EXPORT Algo // <-- ALGO_EXPORT annotation added to the class definition { public: - explicit Algo(std::string name) : m_name(std::move(name)) {} + explicit Algo(std::string name) + : m_name(std::move(name)) + { + } void helloWorld(); private: - std::string m_name; + std::string m_name; }; diff --git a/gcovr.cfg b/gcovr.cfg new file mode 100644 index 0000000..f2f27a0 --- /dev/null +++ b/gcovr.cfg @@ -0,0 +1,23 @@ +root = . +search-path = build + +filter = *.cpp +filter = example/* +filter = source/* +filter = include/* + +exclude-directories = stagedir +exclude-directories = example/build +exclude-directories = build/*/*/_deps +exclude-directories = test +exclude-directories = conan + +gcov-ignore-parse-errors = yes +print-summary = yes + +html-details = build/coverage/index.html + +cobertura-pretty = yes +cobertura = build/cobertura.xml + +#TBD delete-gcov-files = yes From 8af2b315f20776eada8637ff12048c12a1e753f9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 21:50:48 +0200 Subject: [PATCH 30/57] Need to 'export CXX=clang++' on macos CI --- .github/scripts/conan-profile.sh | 1 - .github/workflows/ci.yml | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/scripts/conan-profile.sh b/.github/scripts/conan-profile.sh index 51a1588..f1938d0 100644 --- a/.github/scripts/conan-profile.sh +++ b/.github/scripts/conan-profile.sh @@ -9,7 +9,6 @@ pip3 install conan cmake ninja gcovr || echo ignored which conan conan --version -conan profile --help conan profile detect --force std=20 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28f9f1f..286ad65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,6 @@ jobs: with: { python-version: "3.10" } - name: Setup Cpp - if: matrix.os == 'ubuntu-22.04' uses: aminya/setup-cpp@v1 with: compiler: llvm-17 @@ -64,14 +63,14 @@ jobs: clangformat: true clangtidy: true cmake: true - # conan: true + # NO! conan: true gcovr: true ninja: true # ... - name: Install dependencies run: | - pip3 install conan cmake ninja gcovr + # NO! pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -116,14 +115,14 @@ jobs: clangformat: true clangtidy: true cmake: true - # conan: true + # NO! conan: true gcovr: true ninja: true # ... - name: Install dependencies run: | - # pip3 install conan cmake ninja + # NO! pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh conan install . -b missing @@ -161,8 +160,6 @@ jobs: runs-on: ${{ matrix.os }} - # env: { CXX: clang++ } - steps: - uses: actions/checkout@v4 @@ -178,6 +175,7 @@ jobs: echo $(brew --prefix llvm@17)/bin echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile export PATH=$(brew --prefix llvm@17)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV + echo "CXX=clang++" >> $GITHUB_ENV - name: Setup Cpp if: matrix.os == 'ubuntu-22.04' @@ -188,7 +186,7 @@ jobs: clangformat: true clangtidy: true cmake: true - # conan: true + # NO! conan: true gcovr: true ninja: true # ... From 5e824f1294b8b2dcf317833c995b9e505d250523 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 22:16:21 +0200 Subject: [PATCH 31/57] export GCOV="llvm-cov gcov" --- .envrc | 3 ++- gcovr.cfg | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.envrc b/.envrc index 453a95a..aa17a63 100644 --- a/.envrc +++ b/.envrc @@ -1,8 +1,9 @@ export CMAKE_EXPORT_COMPILE_COMMANDS=YES -export CPM_USE_LOCAL_PACKAGES=YES +export CPM_USE_LOCAL_PACKAGES=NO export CPM_SOURCE_CACHE="${HOME}/.cache/CPM" export PATH="/usr/local/opt/llvm/bin:$PATH" export CXX=`which clang++` export CC=`which clang-17` +export GCOV="llvm-cov gcov" diff --git a/gcovr.cfg b/gcovr.cfg index f2f27a0..47164d8 100644 --- a/gcovr.cfg +++ b/gcovr.cfg @@ -12,7 +12,7 @@ exclude-directories = build/*/*/_deps exclude-directories = test exclude-directories = conan -gcov-ignore-parse-errors = yes +gcov-ignore-parse-errors = all print-summary = yes html-details = build/coverage/index.html From 855af5aef7b4ba5a720cc2d85a475fcc5a13e996 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 11 Apr 2024 22:51:22 +0200 Subject: [PATCH 32/57] workflow without coverage for now --- .CMakeUserPresets.json | 10 ++++------ GNUmakefile | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 362508a..accd76a 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -24,23 +24,21 @@ { "name": "dev-Linux", "inherits": [ - "coverage-linux", "dev-common", "ci-linux" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Coverage" + "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "dev-Darwin", "inherits": [ - "coverage-darwin", "dev-common", "ci-darwin" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Coverage" + "CMAKE_BUILD_TYPE": "Debug" } }, { @@ -65,7 +63,7 @@ "generator": "Ninja", "inherits": [ "ci-coverage", - "dev-Linux" + "dev-" ] }, { @@ -73,7 +71,7 @@ "generator": "Ninja", "inherits": [ "ci-sanitize", - "dev-Linux" + "dev-" ] } ], diff --git a/GNUmakefile b/GNUmakefile index 02ee11f..93b4c0d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -24,7 +24,7 @@ BUILD_TYPE=Debug all: .init conan cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir - gcovr + -gcovr -v test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ From ed2bb04d349b10f78fe3a236ea3afe4773e25e23 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 12 Apr 2024 07:34:11 +0200 Subject: [PATCH 33/57] Use cxx_std_23 --- .github/scripts/conan-profile.sh | 4 ++-- CMakeLists.txt | 8 ++++---- CMakePresets.json | 2 +- GNUmakefile | 4 ++-- example/CMakeLists.txt | 11 ++++++----- test/CMakeLists.txt | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/scripts/conan-profile.sh b/.github/scripts/conan-profile.sh index f1938d0..b30c8f0 100644 --- a/.github/scripts/conan-profile.sh +++ b/.github/scripts/conan-profile.sh @@ -11,9 +11,9 @@ which conan conan --version conan profile detect --force -std=20 +std=23 if [ "$RUNNER_OS" = Windows ]; then - std=20 + std=23 fi profile="$(conan profile path default)" diff --git a/CMakeLists.txt b/CMakeLists.txt index 29258c2..b892cb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(cxx_modules_example VERSION 0.1.0 LANGUAGES CXX) # toolchains will once again reject the consumer's generated BMI. if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_EXTENSIONS FALSE) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) endif() @@ -57,8 +57,8 @@ target_sources(Algo target_link_libraries(Algo PRIVATE $) # CMake requires the language standard to be specified as compile feature -# when a target provides C++20 modules and the target will be installed -target_compile_features(Algo PUBLIC cxx_std_20) +# when a target provides C++23 modules and the target will be installed +target_compile_features(Algo PUBLIC cxx_std_23) include(GenerateExportHeader) generate_export_header(Algo @@ -165,7 +165,7 @@ set_target_properties( OUTPUT_NAME cmake-init-modules ) -target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_20) +target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_23) #XXX target_link_libraries(cmake-init-modules_cmake-init-modules PRIVATE fmt::fmt) target_link_libraries( diff --git a/CMakePresets.json b/CMakePresets.json index b160e89..9a68167 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -58,7 +58,7 @@ "hidden": true, "cacheVariables": { "CMAKE_CXX_EXTENSIONS": false, - "CMAKE_CXX_STANDARD": "20", + "CMAKE_CXX_STANDARD": "23", "CMAKE_CXX_STANDARD_REQUIRED": true } }, diff --git a/GNUmakefile b/GNUmakefile index 93b4c0d..ba0b13f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -24,7 +24,7 @@ BUILD_TYPE=Debug all: .init conan cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir - -gcovr -v + #FIXME: gcovr -v test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ @@ -47,7 +47,7 @@ conan: conanfile.py GNUmakefile conan install . -s build_type=$(BUILD_TYPE) -s compiler.cppstd=20 -b missing clean: - rm -rf build + rm -rf build example/build distclean: clean rm -rf conan stagedir .init CMakeUserPresets.json diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f335502..ff3aa08 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -5,15 +5,16 @@ project(cmake-init-modulesExamples CXX) include(../cmake/folders.cmake) if(PROJECT_IS_TOP_LEVEL) + # Neither of these two are technically needed, but they make the expectation clear + set(CMAKE_CXX_STANDARD 23) + set(CMAKE_CXX_EXTENSIONS FALSE) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + find_package(cmake-init-modules 0.1 REQUIRED) find_package(my_package 0.1 REQUIRED) enable_testing() endif() -# Neither of these two are technically needed, but they make the expectation clear -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_EXTENSIONS FALSE) - add_executable(app main.cpp) target_link_libraries(app PRIVATE Algo) add_test(NAME app COMMAND app) @@ -27,7 +28,7 @@ add_custom_target(run-examples) function(add_example NAME) add_executable("${NAME}" "${NAME}.cpp") target_link_libraries("${NAME}" PRIVATE cmake-init-modules::cmake-init-modules) - target_compile_features("${NAME}" PRIVATE cxx_std_20) + target_compile_features("${NAME}" PRIVATE cxx_std_23) add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM) add_dependencies("run_${NAME}" "${NAME}") add_dependencies(run-examples "run_${NAME}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8fb731b..741e52c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,7 +20,7 @@ add_executable(cmake-init-modules_test source/cmake-init-modules_test.cpp) target_link_libraries( cmake-init-modules_test PRIVATE cmake-init-modules::cmake-init-modules Catch2::Catch2WithMain ) -target_compile_features(cmake-init-modules_test PRIVATE cxx_std_20) +target_compile_features(cmake-init-modules_test PRIVATE cxx_std_23) catch_discover_tests(cmake-init-modules_test) From 3045da3cf5e91a3d4fb10abef33f16fcec14f000 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 13 Apr 2024 22:40:26 +0200 Subject: [PATCH 34/57] Do not longer use conan --- .CMakeUserPresets.json | 3 +-- .github/workflows/ci.yml | 10 ++++++---- CMakeLists.txt | 6 +++--- CMakePresets.json | 15 +++++---------- GNUmakefile | 4 ++-- example/CMakeLists.txt | 9 ++++++--- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index accd76a..cb7e643 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -10,8 +10,7 @@ "name": "dev-common", "hidden": true, "inherits": [ - "dev-mode", - "conan" + "dev-mode" ], "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 286ad65..550f7d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,10 +69,11 @@ jobs: # ... - name: Install dependencies + shell: bash run: | # NO! pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh - conan install . -b missing + # conan install . -b missing - name: Configure run: cmake --preset=ci-coverage @@ -121,10 +122,11 @@ jobs: # ... - name: Install dependencies + shell: bash run: | # NO! pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh - conan install . -b missing + # conan install . -b missing - name: Configure run: cmake --preset=ci-sanitize @@ -196,7 +198,7 @@ jobs: run: | # pip3 install conan cmake ninja gcovr bash < .github/scripts/conan-profile.sh - conan install . -b missing + # conan install . -b missing - name: Setup MultiToolTask if: matrix.os == 'windows-2022' @@ -233,7 +235,7 @@ jobs: run: | cmake -B example/build -S example -G Ninja -D CMAKE_BUILD_TYPE=Release \ -D "CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan" \ - --toolchain "$PWD/conan/conan_toolchain.cmake" + # --toolchain "$PWD/conan/conan_toolchain.cmake" ninja -C example/build ninja -C example/build test diff --git a/CMakeLists.txt b/CMakeLists.txt index b892cb1..47bcdff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,9 +105,9 @@ install(FILES cmake/my_package-config.cmake # cmake-format: on ######################################################################### -# enable_testing() -# add_subdirectory(example) -# return() +enable_testing() +add_subdirectory(example) +return() ################################################## diff --git a/CMakePresets.json b/CMakePresets.json index 9a68167..fb3888b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -172,8 +172,7 @@ "name": "ci-coverage", "inherits": [ "coverage-linux", - "dev-mode", - "conan" + "dev-mode" ], "cacheVariables": { "COVERAGE_HTML_COMMAND": "" @@ -184,8 +183,7 @@ "binaryDir": "${sourceDir}/build/sanitize", "inherits": [ "ci-linux", - "dev-mode", - "conan" + "dev-mode" ], "cacheVariables": { "CMAKE_SKIP_INSTALL_RULES": true, @@ -207,8 +205,7 @@ "inherits": [ "ci-build", "ci-darwin", - "dev-mode", - "conan" + "dev-mode" ] }, { @@ -220,8 +217,7 @@ "inherits": [ "ci-build", "ci-linux", - "dev-mode", - "conan" + "dev-mode" ] }, { @@ -233,8 +229,7 @@ "inherits": [ "ci-build", "ci-win64", - "dev-mode", - "conan" + "dev-mode" ] }, { diff --git a/GNUmakefile b/GNUmakefile index ba0b13f..039086f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,7 +21,7 @@ BUILD_TYPE=Debug .PHONY: all clean distclean check format test -all: .init conan +all: .init # conan cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir #FIXME: gcovr -v @@ -29,7 +29,7 @@ all: .init conan test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ -D 'CMAKE_PREFIX_PATH=$(CURDIR)/stagedir;$(CURDIR)/conan' \ - --toolchain $(CURDIR)/conan/conan_toolchain.cmake # XXX --debug-find-pkg=fmt + # --toolchain $(CURDIR)/conan/conan_toolchain.cmake # XXX --debug-find-pkg=fmt ninja -C example/build ninja -C example/build test diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ff3aa08..07cdbdb 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28...3.29) +cmake_minimum_required(VERSION 3.28.4...3.29) project(cmake-init-modulesExamples CXX) @@ -10,7 +10,6 @@ if(PROJECT_IS_TOP_LEVEL) set(CMAKE_CXX_EXTENSIONS FALSE) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - find_package(cmake-init-modules 0.1 REQUIRED) find_package(my_package 0.1 REQUIRED) enable_testing() endif() @@ -19,10 +18,14 @@ add_executable(app main.cpp) target_link_libraries(app PRIVATE Algo) add_test(NAME app COMMAND app) -# return() +return() ################################################## +if(PROJECT_IS_TOP_LEVEL) + find_package(cmake-init-modules 0.1 REQUIRED) +endif() + add_custom_target(run-examples) function(add_example NAME) From 2d50753567ed0db29bf9d52614943a568bf7030f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 13 Apr 2024 22:51:49 +0200 Subject: [PATCH 35/57] Do not use UseMultiToolTask on CI --- .github/workflows/ci.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 550f7d3..8e6085f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,11 +200,11 @@ jobs: bash < .github/scripts/conan-profile.sh # conan install . -b missing - - name: Setup MultiToolTask - if: matrix.os == 'windows-2022' - run: | - Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true' - Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' + # - name: Setup MultiToolTask + # if: matrix.os == 'windows-2022' + # run: | + # Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true' + # Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' - name: Configure shell: pwsh @@ -225,11 +225,6 @@ jobs: working-directory: build run: ctest --output-on-failure --no-tests=error -C Release -j 2 - # - name: TestInstalledVersion - # if: matrix.os == 'ubuntu-22.04' - # run: | - # BUILD_SHARED_LIBS=${{ matrix.shared }} gmake test - - name: TestInstalledVersion if: matrix.os != 'windows-2022' run: | From 434b43c7e0cc6319d1f5c3c5c526102816bb2dab Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 13 Apr 2024 22:59:05 +0200 Subject: [PATCH 36/57] Do not use flags-windows preset on CI --- CMakePresets.json | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index fb3888b..e384377 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -131,7 +131,6 @@ { "name": "ci-win64", "inherits": [ - "flags-windows", "ci-std" ], "generator": "Visual Studio 17 2022", From 179af39648882acccaa6c4a7f793cb0af155404d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 13 Apr 2024 23:22:55 +0200 Subject: [PATCH 37/57] Set CMAKE_BUILD_TYPE to Release on Windows CI --- CMakePresets.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index e384377..4450429 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -135,7 +135,10 @@ ], "generator": "Visual Studio 17 2022", "architecture": "x64", - "hidden": true + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } }, { "name": "coverage-linux", From 49da1a4d4d92eceed360b5a03caed9ea71bb524c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 14 Apr 2024 07:30:55 +0200 Subject: [PATCH 38/57] Do not use cmake presets on Windows --- .github/workflows/ci.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e6085f..736aaed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,17 +200,24 @@ jobs: bash < .github/scripts/conan-profile.sh # conan install . -b missing - # - name: Setup MultiToolTask - # if: matrix.os == 'windows-2022' - # run: | - # Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true' - # Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' + - name: Setup MultiToolTask + if: matrix.os == 'windows-2022' + run: | + Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true' + Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' - - name: Configure + - name: Configure preset + if: matrix.os != 'windows-2022' shell: pwsh run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" -D BUILD_SHARED_LIBS=${{ matrix.shared }} + - name: Configure on windows + if: matrix.os == 'windows-2022' + shell: pwsh + run: cmake -G "Visual Studio 17 2022" -S . -B build\Release + -D CMAKE_INSTALL_PREFIX=$(Get-Location)\stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} + - name: Setup PATH if: matrix.os == 'windows-2022' && matrix.type == 'shared' run: Add-Content "$env:GITHUB_PATH" "$(Get-Location)\build\Release" From 4c28c5c77cd1088e067d96ccf9ea9d88cbba9049 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 14 Apr 2024 07:51:47 +0200 Subject: [PATCH 39/57] Quickfix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 736aaed..f6aed63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,8 +215,8 @@ jobs: - name: Configure on windows if: matrix.os == 'windows-2022' shell: pwsh - run: cmake -G "Visual Studio 17 2022" -S . -B build\Release - -D CMAKE_INSTALL_PREFIX=$(Get-Location)\stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} + run: cmake -G "Visual Studio 17 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release + -D CMAKE_INSTALL_PREFIX=$(Get-Location)/stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} - name: Setup PATH if: matrix.os == 'windows-2022' && matrix.type == 'shared' From 173b533eda7b18716c6f00f17c47cadc9c1ef1ab Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 14 Apr 2024 08:19:07 +0200 Subject: [PATCH 40/57] clang-format --- .clang-format | 2 +- algo-interface.cppm | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.clang-format b/.clang-format index 70e07e9..65a4236 100644 --- a/.clang-format +++ b/.clang-format @@ -56,7 +56,7 @@ BreakConstructorInitializersBeforeComma: true BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: true BreakStringLiterals: true -ColumnLimit: 80 +ColumnLimit: 90 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false diff --git a/algo-interface.cppm b/algo-interface.cppm index 7c876a0..fe277c0 100644 --- a/algo-interface.cppm +++ b/algo-interface.cppm @@ -5,11 +5,9 @@ module; #include // <-- Generated header added to the global fragment -export module - algo; // <-- Annotation not currently required, but see discussion below +export module algo; // <-- Annotation not currently required, but see discussion below -export class ALGO_EXPORT - Algo // <-- ALGO_EXPORT annotation added to the class definition +export class ALGO_EXPORT Algo // <-- ALGO_EXPORT annotation added to the class definition { public: explicit Algo(std::string name) From efe495f3d1644eb635d3a6db94d5f1abeecdb3e7 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 10 Apr 2024 15:31:58 +0200 Subject: [PATCH 41/57] Use C++20 fmt module --- .CMakeUserPresets.json | 9 +- .build-errors.txt | 195 +++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 3 +- algo-impl.cpp | 5 +- 4 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 .build-errors.txt diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index cb7e643..c5c453b 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -17,7 +17,10 @@ "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, "BUILD_MCSS_DOCS": false, - "BUILD_SHARED_LIBS": false + "BUILD_SHARED_LIBS": true + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "OFF" } }, { @@ -48,8 +51,8 @@ "ci-win64" ], "environment": { - "UseMultiToolTask": "true", - "EnforceProcessCountAcrossBuilds": "true" + "UseMultiToolTask": "ON", + "EnforceProcessCountAcrossBuilds": "ON" } }, { diff --git a/.build-errors.txt b/.build-errors.txt new file mode 100644 index 0000000..4716068 --- /dev/null +++ b/.build-errors.txt @@ -0,0 +1,195 @@ +bash-5.2$ ninja -v fmt + +[1/4] cd /Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/_deps/fmt-build && +/usr/local/opt/llvm/bin/clang++ -std=c++20 -x c++-module --precompile -c -o fmt.pcm +/Users/clausklein/.cache/CPM/fmt/c3ebf53335b44df838d9982d1a0e35afe190e34f/src/fmt.cc +-I/Users/clausklein/.cache/CPM/fmt/c3ebf53335b44df838d9982d1a0e35afe190e34f/include + +[2/4] cd /Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/_deps/fmt-build && +/usr/local/opt/llvm/bin/clang++ +-fmodule-file=/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/_deps/fmt-build/fmt.pcm -c -o fmt.o +/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/_deps/fmt-build/fmt.pcm + +[3/4] : && /usr/local/opt/llvm/bin/clang++ -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 +-Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough +-Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast -g -arch x86_64 -isysroot +/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -dynamiclib +-Wl,-headerpad_max_install_names -m64 -compatibility_version 10.0.0 -current_version 10.2.1 -o +_deps/fmt-build/libfmtd.10.2.1.dylib -install_name @rpath/libfmtd.10.dylib _deps/fmt-build/fmt.o && : + +[4/4] /usr/local/bin/cmake -E cmake_symlink_library _deps/fmt-build/libfmtd.10.2.1.dylib _deps/fmt-build/libfmtd.10.dylib +_deps/fmt-build/libfmtd.dylib && : + +bash-5.2$ ninja -v Algo + +[1/2] /usr/local/opt/llvm/bin/clang++ -DAlgo_EXPORTS -DFMT_HEADER_ONLY=1 +-I/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev -isystem +/Users/clausklein/.cache/CPM/fmt/c3ebf53335b44df838d9982d1a0e35afe190e34f/include -Wall -Wextra -Wpedantic -Wconversion +-Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference +-Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast -g +-std=c++20 -arch x86_64 -isysroot +/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -fPIC +-fvisibility=hidden -fvisibility-inlines-hidden -MD -MT CMakeFiles/Algo.dir/algo-impl.cpp.o -MF +CMakeFiles/Algo.dir/algo-impl.cpp.o.d @CMakeFiles/Algo.dir/algo-impl.cpp.o.modmap -o CMakeFiles/Algo.dir/algo-impl.cpp.o -c +/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/algo-impl.cpp + +FAILED: CMakeFiles/Algo.dir/algo-impl.cpp.o +/usr/local/opt/llvm/bin/clang++ -DAlgo_EXPORTS -DFMT_HEADER_ONLY=1 -I/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev -isystem /Users/clausklein/.cache/CPM/fmt/c3ebf53335b44df838d9982d1a0e35afe190e34f/include -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast -g -std=c++20 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT CMakeFiles/Algo.dir/algo-impl.cpp.o -MF CMakeFiles/Algo.dir/algo-impl.cpp.o.d @CMakeFiles/Algo.dir/algo-impl.cpp.o.modmap -o CMakeFiles/Algo.dir/algo-impl.cpp.o -c /Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/algo-impl.cpp +/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/algo-impl.cpp:8:8: fatal error: module 'fmt' not found + 8 | import fmt; + | ~~~~~~~^~~ +1 error generated. +ninja: build stopped: subcommand failed. +bash-5.2$ + +bash-5.2$ tree _deps/ +_deps/ +`-- fmt-build + |-- CMakeFiles + | |-- Export + | | `-- b834597d9b1628ff12ae4314c3a2e4b8 + | | |-- fmt-targets-debug.cmake + | | `-- fmt-targets.cmake + | `-- fmt.dir + |-- cmake_install.cmake + |-- fmt-config-version.cmake + |-- fmt-config.cmake + |-- fmt-targets.cmake + |-- fmt.o + |-- fmt.pc + |-- fmt.pcm + |-- libfmtd.10.2.1.dylib + |-- libfmtd.10.dylib -> libfmtd.10.2.1.dylib + `-- libfmtd.dylib -> libfmtd.10.dylib + +6 directories, 12 files +bash-5.2$ + +bash-5.2$ clang-format -i *.json +bash-5.2$ head -50 *.ddi *.json *.modmap +==> algo-impl.cpp.o.ddi <== +{ + "revision": 0, + "rules": [ + { + "primary-output": "CMakeFiles/Algo.dir/algo-impl.cpp.o", + "requires": [ + { + "logical-name": "fmt" + }, + { + "logical-name": "algo" + } + ] + } + ], + "version": 1 +} + +==> algo-interface.cppm.o.ddi <== +{ + "revision": 0, + "rules": [ + { + "primary-output": "CMakeFiles/Algo.dir/algo-interface.cppm.o", + "provides": [ + { + "is-interface": true, + "logical-name": "algo", + "source-path": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/algo-interface.cppm" + } + ] + } + ], + "version": 1 +} + +==> CXXDependInfo.json <== +{ + "bmi-installation": null, + "compiler-frontend-variant": "GNU", + "compiler-id": "Clang", + "compiler-simulate-id": "", + "config": "Debug", + "cxx-modules": + { + "CMakeFiles/Algo.dir/algo-interface.cppm.o": + { + "bmi-only": false, + "destination": "lib/cmake/my_package/src", + "name": "CXX_MODULES", + "relative-directory": "", + "source": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/algo-interface.cppm", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + } + }, + "dir-cur-bld": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev", + "dir-cur-src": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules", + "dir-top-bld": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev", + "dir-top-src": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules", + "exports": + [ + { + "cxx-module-info-dir": ".", + "destination": "lib/cmake/my_package", + "export-name": "Algo", + "export-prefix": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/CMakeFiles/Export/0814a8a452340fa10b4323026df361bb", + "install": true, + "namespace": "" + } + ], + "forward-modules-from-target-dirs": [], + "include-dirs": + [ + ".", + "/Users/clausklein/.cache/CPM/fmt/c3ebf53335b44df838d9982d1a0e35afe190e34f/include" + ], + "language": "CXX", + "linked-target-dirs": [], + "module-dir": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/CMakeFiles/Algo.dir" +} +==> CXXModules.json <== +{ + "modules": + { + "algo": + { + "bmi": "/Users/clausklein/Workspace/cpp/cxx20/cmake-init-modules/build/dev/CMakeFiles/Algo.dir/algo.pcm", + "is-private": false + } + }, + "references": + { + "algo": + { + "lookup-method": "by-name", + "path": "CMakeFiles/Algo.dir/algo.pcm" + } + }, + "usages": {} +} +==> algo-impl.cpp.o.modmap <== +-fmodule-file=algo=CMakeFiles/Algo.dir/algo.pcm + +==> algo-interface.cppm.o.modmap <== +-x c++-module +-fmodule-output=CMakeFiles/Algo.dir/algo.pcm +bash-5.2$ !tree +tree +. +|-- CXX.dd +|-- CXXDependInfo.json +|-- CXXModules.json +|-- algo-impl.cpp.o.ddi +|-- algo-impl.cpp.o.ddi.d +|-- algo-impl.cpp.o.modmap +|-- algo-interface.cppm.o +|-- algo-interface.cppm.o.ddi +|-- algo-interface.cppm.o.ddi.d +|-- algo-interface.cppm.o.modmap +`-- algo.pcm + +1 directory, 11 files +bash-5.2$ + diff --git a/CMakeLists.txt b/CMakeLists.txt index 47bcdff..03d7858 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,8 @@ cpmaddpackage( GIT_TAG 10.2.1 GITHUB_REPOSITORY fmtlib/fmt SYSTEM YES - #FIXME(CK): OPTIONS "FMT_MODULE ON" + #FIXME(CK): + OPTIONS "FMT_MODULE ON" ) if(TARGET fmt) target_disable_clang_tidy(fmt) diff --git a/algo-impl.cpp b/algo-impl.cpp index b61eafe..4afc24e 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -1,10 +1,11 @@ module; -#include +// XXX #include module algo; -// TODO(CK): import fmt; +// FIXME(CK): +import fmt; void Algo::helloWorld() { From 5305762b82c78f7e469fe8e4e40a82aab6e72966 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 14 Apr 2024 22:13:58 +0200 Subject: [PATCH 42/57] Use std::print() if possible --- algo-impl.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/algo-impl.cpp b/algo-impl.cpp index 4afc24e..1391b6f 100644 --- a/algo-impl.cpp +++ b/algo-impl.cpp @@ -1,13 +1,20 @@ module; -// XXX #include +#include + +#if defined(__cpp_lib_print) +# include +using std::print; +#else +# include +using fmt::print; +#endif module algo; -// FIXME(CK): -import fmt; +// FIXME(CK): import fmt; void Algo::helloWorld() { - fmt::print("hello {}\n", m_name); + print("hello {}\n", m_name); } From 0c3ff7bd42cb4692b3680a3d18eb5037d14ed540 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 29 Sep 2024 11:00:37 +0200 Subject: [PATCH 43/57] import-std-in-cmake-3-30 --- .cmake-format.json | 33 ++++++++++++++++ std/.CMakeLists.txt | 92 +++++++++++++++++++++++++++++++++++++++++++++ std/CMakeLists.txt | 37 ++++++++++++++++++ std/GNUmakefile | 41 ++++++++++++++++++++ std/main.cpp | 7 ++++ std/main.cxx | 9 +++++ std/uses_std.cxx | 6 +++ 7 files changed, 225 insertions(+) create mode 100644 .cmake-format.json create mode 100644 std/.CMakeLists.txt create mode 100644 std/CMakeLists.txt create mode 100644 std/GNUmakefile create mode 100644 std/main.cpp create mode 100644 std/main.cxx create mode 100644 std/uses_std.cxx diff --git a/.cmake-format.json b/.cmake-format.json new file mode 100644 index 0000000..3b58f43 --- /dev/null +++ b/.cmake-format.json @@ -0,0 +1,33 @@ +{ + "format": { + "disable": false, + "line_width": 100, + "tab_size": 2, + "use_tabchars": false, + "fractional_tab_policy": "use-space", + "max_subgroups_hwrap": 4, + "max_pargs_hwrap": 6, + "max_rows_cmdline": 2, + "separate_ctrl_name_with_space": false, + "separate_fn_name_with_space": false, + "dangle_parens": true, + "dangle_align": "prefix", + "min_prefix_chars": 4, + "max_prefix_chars": 10, + "max_lines_hwrap": 2, + "line_ending": "unix", + "command_case": "canonical", + "keyword_case": "unchanged", + "always_wrap": [ + "file", + "install" + ], + "enable_sort": true, + "autosort": false, + "require_valid_layout": false, + "layout_passes": {} + }, + "markup": { + "enable_markup": false + } +} diff --git a/std/.CMakeLists.txt b/std/.CMakeLists.txt new file mode 100644 index 0000000..71e94ce --- /dev/null +++ b/std/.CMakeLists.txt @@ -0,0 +1,92 @@ +# CMake 3.30 is required for C++23 `import std` support; we use 3.29.20240416 +# here so that in-development versions satisfy it. +cmake_minimum_required(VERSION 3.30 FATAL_ERROR) + +# Set experimental flag to enable `import std` support from CMake. +# This must be enabled before C++ language support. +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + # This specific value changes as experimental support evolves. See + # `Help/dev/experimental.rst` in the CMake source corresponding to + # your CMake build for the exact value to use. + "0e5b6991-d74f-4b3d-a41c-cf096e0b2508" +) + +# C++ needs to be enabled. +project(import_std LANGUAGES CXX) + +# Tell CMake that we explicitly want `import std`. This will initialize the +# property on all targets declared after this to 1 +set(CMAKE_CXX_MODULE_STD 1) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.1) + # set(USE_MODULES TRUE) # used by fmt + set(CMAKE_CXX_SCAN_FOR_MODULES ON) + # see https://releases.llvm.org/19.1.0/projects/libcxx/docs/index.html + # and https://releases.llvm.org/19.1.0/projects/libcxx/docs/Modules.html + # Currently CMake requires extensions enabled when using import std. + # https://gitlab.kitware.com/cmake/cmake/-/issues/25916 + # https://gitlab.kitware.com/cmake/cmake/-/issues/25539 + set(CMAKE_CXX_EXTENSIONS ON) + add_compile_options(-fexperimental-library) + add_link_options(-lc++experimental) + add_compile_options(-ftime-trace) + add_compile_options(-stdlib=libc++) + add_link_options(-stdlib=libc++) + if(DEFINED ENV{LLVM_ROOT}) + message(STATUS "LLVM_ROOT=$ENV{LLVM_ROOT}") + set(LLVM_LIBC_SOURCE $ENV{LLVM_ROOT}/share/libc++/v1) + set(HAS_STDLIB_MODULES stdlib) + set(CMAKE_CXX_COMPILER_IMPORT_STD 23) + endif() +endif() + +# Build the stdlib module +function(add_stdlib_module NAME) + add_library(${NAME}) + add_library(__CMAKE::CXX23 ALIAS ${NAME}) + # cmake-format: off + target_sources(${NAME} PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${LLVM_LIBC_SOURCE} + FILES + ${LLVM_LIBC_SOURCE}/std.cppm + ${LLVM_LIBC_SOURCE}/std.compat.cppm + ) + # cmake-format: on + target_compile_features(${NAME} PUBLIC cxx_std_23) + target_compile_definitions(${NAME} PUBLIC _LIBCPP_HAS_NO_LOCALIZATION) + target_compile_options(${NAME} PRIVATE -Wno-reserved-module-identifier) +endfunction() + +# Build the stdlib module +if(HAS_STDLIB_MODULES) + message(STATUS "HAS_STDLIB_MODULES=${HAS_STDLIB_MODULES}") + # XXX add_stdlib_module(${HAS_STDLIB_MODULES}) +endif() + +# +# Import the modules from libc++ +# + +# include(FetchContent) +# FetchContent_Declare( +# std +# URL "file://${LIBCXX_BUILD}/modules/c++/v1/" +# DOWNLOAD_EXTRACT_TIMESTAMP TRUE +# SYSTEM +# ) +# FetchContent_MakeAvailable(std) + +# Make a library. +add_library(uses_std STATIC) +# Add sources. +target_sources(uses_std PRIVATE uses_std.cxx) +# Tell CMake we're using C++23 but only C++20 is needed to consume it. +target_compile_features(uses_std PRIVATE cxx_std_23 INTERFACE cxx_std_20) + +# Make an executable. +add_executable(main) +# Note that this source is *not* allowed to `import std` as it ends up +# with only C++20 support due to the `uses_std` INTERFACE requirements. +target_sources(main PRIVATE main.cxx) +target_link_libraries(main PRIVATE uses_std) diff --git a/std/CMakeLists.txt b/std/CMakeLists.txt new file mode 100644 index 0000000..ebc9939 --- /dev/null +++ b/std/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.30.0 FATAL_ERROR) + +# +# Set language version used +# +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +# Currently CMake requires extensions enabled when using import std. +# https://gitlab.kitware.com/cmake/cmake/-/issues/25916 +# https://gitlab.kitware.com/cmake/cmake/-/issues/25539 +set(CMAKE_CXX_EXTENSIONS ON) + +# +# see https://gitlab.kitware.com/cmake/cmake/-/issues/25965#note_1523575 +# and https://www.kitware.com/import-std-in-cmake-3-30/ +# +if("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 17 2022") + # This can be done before or after project() on MSVC + # It works regardless of CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + set(CMAKE_CXX_SCAN_FOR_MODULES ON) + + # This does not seem to work on MSVC under any circumstances + # set(CMAKE_CXX_MODULE_STD ON) +else() + # This needs to be done before selecting the languages so the project() command + # The CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is required + set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + set(CMAKE_CXX_MODULE_STD ON) + + # Does not work regardless of value of CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + # set(CMAKE_CXX_SCAN_FOR_MODULES ON) +endif() + +project("example" LANGUAGES CXX) + +add_executable(main) +target_sources(main PRIVATE main.cpp) diff --git a/std/GNUmakefile b/std/GNUmakefile new file mode 100644 index 0000000..8d75385 --- /dev/null +++ b/std/GNUmakefile @@ -0,0 +1,41 @@ +UNAME:=$(shell uname) +ifeq (${UNAME},Darwin) + export GNU_PREFIX:=$(shell brew --prefix gcc@14) + export GNU_ROOT:=$(shell realpath ${GNU_PREFIX}) + #TODO: export CXX:=g++-14 + + export LLVM_PREFIX:=$(shell brew --prefix llvm@19) + export LLVM_ROOT:=$(shell realpath ${LLVM_PREFIX}) + export LDFLAGS+=-L${LLVM_ROOT}/lib/c++ + export PATH:=${LLVM_ROOT}/bin:${PATH} + export CXX?=clang++ +else ifeq (${UNAME},Linux) + export LLVM_ROOT:=/usr/lib/llvm-18 +endif + +#TODO: export CXXFLAGS:=-std=c++23 +export CMAKE_BUILD_TYPE:=Release + +BUILD_SHARED_LIBS?=YES + +.PHONY: all build install format clean distclean +all: build + ninja -C build + cd build && ctest --verbose + +build: CMakeLists.txt #XXX stagedir + cmake -G Ninja -S . -B build -D BUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -D CMAKE_PREFIX_PATH=$(CURDIR)/stagedir --fresh #XXX --debug-find-pkg=Asio + +# stagedir: asio-module/CMakeLists.txt GNUmakefile +# cmake -G Ninja -S asio-module -B build/asio -D CMAKE_INSTALL_PREFIX=$(CURDIR)/stagedir --fresh +# cmake --build build/asio +# cmake --install build/asio # --prefix stagedir + +format: + cmake-format -i CMakeLists.txt asio-module/CMakeLists.txt asio-module/AsioConfig.cmake.in + +clean: + rm -rf build + +distclean: clean + rm -rf stagedir __build diff --git a/std/main.cpp b/std/main.cpp new file mode 100644 index 0000000..1d7aa2c --- /dev/null +++ b/std/main.cpp @@ -0,0 +1,7 @@ +import std; // When importing std.compat it's not needed to import std. +import std.compat; + +int main() { + std::cout << "Hello modular world\n"; + ::printf("Hello compat modular world\n"); +} diff --git a/std/main.cxx b/std/main.cxx new file mode 100644 index 0000000..eb2010b --- /dev/null +++ b/std/main.cxx @@ -0,0 +1,9 @@ +#include + +void hello_world(std::string const& name); + +int main(int argc, char* argv[]) +{ + hello_world(argv[0] ? argv[0] : "Voldemort?"); + return 0; +} diff --git a/std/uses_std.cxx b/std/uses_std.cxx new file mode 100644 index 0000000..84fe21d --- /dev/null +++ b/std/uses_std.cxx @@ -0,0 +1,6 @@ +import std; + +void hello_world(std::string const& name) +{ + std::cout << "Hello World! My name is " << name << std::endl; +} From 18fae44721986a3a6897bf781a3ba6b2680de6cf Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 29 Sep 2024 21:42:03 +0200 Subject: [PATCH 44/57] Modernize std example code --- .envrc | 9 --------- CMakeLists.txt | 2 +- example/CMakeLists.txt | 2 +- std/CMakeLists.txt | 17 +++++++++++++++++ std/main.cpp | 2 +- std/main.cxx | 6 +++--- std/uses_std.cxx | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-) delete mode 100644 .envrc diff --git a/.envrc b/.envrc deleted file mode 100644 index aa17a63..0000000 --- a/.envrc +++ /dev/null @@ -1,9 +0,0 @@ -export CMAKE_EXPORT_COMPILE_COMMANDS=YES -export CPM_USE_LOCAL_PACKAGES=NO -export CPM_SOURCE_CACHE="${HOME}/.cache/CPM" - -export PATH="/usr/local/opt/llvm/bin:$PATH" -export CXX=`which clang++` -export CC=`which clang-17` - -export GCOV="llvm-cov gcov" diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d7858..1ee9b8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28.4...3.29) +cmake_minimum_required(VERSION 3.28.4...3.30) include(cmake/prelude.cmake) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 07cdbdb..8ef4c63 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28.4...3.29) +cmake_minimum_required(VERSION 3.28.4...3.30) project(cmake-init-modulesExamples CXX) diff --git a/std/CMakeLists.txt b/std/CMakeLists.txt index ebc9939..03cd7c8 100644 --- a/std/CMakeLists.txt +++ b/std/CMakeLists.txt @@ -35,3 +35,20 @@ project("example" LANGUAGES CXX) add_executable(main) target_sources(main PRIVATE main.cpp) + +# Make a library. +add_library(uses_std STATIC) +# Add sources. +target_sources(uses_std PRIVATE uses_std.cxx) +# Tell CMake we're using C++23 but only C++20 is needed to consume it. +target_compile_features(uses_std PRIVATE cxx_std_23 INTERFACE cxx_std_20) + +# Make an executable. +add_executable(test-module) +# Note that this source is *not* allowed to `import std` as it ends up +# with only C++20 support due to the `uses_std` INTERFACE requirements. +target_sources(test-module PRIVATE main.cxx) +target_link_libraries(test-module PRIVATE uses_std) + +enable_testing() +add_test(NAME test-module COMMAND test-module) diff --git a/std/main.cpp b/std/main.cpp index 1d7aa2c..134ccb9 100644 --- a/std/main.cpp +++ b/std/main.cpp @@ -1,7 +1,7 @@ import std; // When importing std.compat it's not needed to import std. import std.compat; -int main() { +auto main() -> int { std::cout << "Hello modular world\n"; ::printf("Hello compat modular world\n"); } diff --git a/std/main.cxx b/std/main.cxx index eb2010b..dd9ff1c 100644 --- a/std/main.cxx +++ b/std/main.cxx @@ -1,9 +1,9 @@ #include -void hello_world(std::string const& name); +extern void hello_world(std::string const& name); -int main(int argc, char* argv[]) +auto main(int /*argc*/, char* argv[]) -> int { - hello_world(argv[0] ? argv[0] : "Voldemort?"); + hello_world((argv[1] != nullptr) ? argv[1] : "Voldemort?"); return 0; } diff --git a/std/uses_std.cxx b/std/uses_std.cxx index 84fe21d..241002b 100644 --- a/std/uses_std.cxx +++ b/std/uses_std.cxx @@ -2,5 +2,5 @@ import std; void hello_world(std::string const& name) { - std::cout << "Hello World! My name is " << name << std::endl; + std::print("Hello World! My name is {}\n", name); } From e8144c039934c16794b69b9d53ad0e75015f17ac Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 10:57:12 +0200 Subject: [PATCH 45/57] Bump requried cmake version --- CMakeLists.txt | 2 +- CMakePresets.json | 10 ++- CMakeUserPresets.jsonnet | 184 +++++++++++++++++++++++++++++++++++++++ example/CMakeLists.txt | 2 +- std/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 6 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 CMakeUserPresets.jsonnet diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee9b8a..9ff6bc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28.4...3.30) +cmake_minimum_required(VERSION 3.30...3.31) include(cmake/prelude.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index 4450429..c1d38d1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,8 +1,8 @@ { - "version": 6, + "version": 9, "cmakeMinimumRequired": { "major": 3, - "minor": 28, + "minor": 30, "patch": 0 }, "configurePresets": [ @@ -102,7 +102,6 @@ "lhs": "${hostSystemName}", "rhs": "Windows" } - }, { "name": "ci-linux", @@ -138,6 +137,11 @@ "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" } }, { diff --git a/CMakeUserPresets.jsonnet b/CMakeUserPresets.jsonnet new file mode 100644 index 0000000..3643d55 --- /dev/null +++ b/CMakeUserPresets.jsonnet @@ -0,0 +1,184 @@ +# jrsonnet --preserve-order CMakeUserPresets.jsonnet > CMakeUserPresets.json + +local archs = [ + 'Linux', + 'Darwin', + 'win64', +]; + +local types = [ + 'dev', + # 'sanitize', + # 'coverage', +]; + +local link_modes = [ + # 'static', + 'dynamic', +]; + +local configs = [ + 'Debug', + # 'Release', +]; + +local cp_generator(arch, type, link_mode) = + { + name: arch + '-' + type + '-' + link_mode, + inherits: [type, link_mode], + }; + +local bp_generator(arch, type, link_mode, config) = + { + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + # configurePreset: arch + '-' + type + '-' + link_mode, + configurePreset: type + '-' + arch, + configuration: config, + }; + +local tp_generator(arch, type, link_mode, config) = + { + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + # configurePreset: arch + '-' + type + '-' + link_mode, + configurePreset: type + '-' + arch, + output: { outputOnFailure: true }, + execution: { noTestsAction: 'ignore', stopOnFailure: true }, + }; + +local wp_generator(arch, type, link_mode, config) = + { + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + steps: [ + { + type: 'configure', + # name: arch + '-' + type + '-' + link_mode, + name: type + '-' + arch, + }, + { + type: 'build', + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + }, + { + type: 'test', + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + }, + { + type: 'package', + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + }, + ], + }; + +local pp_generator(arch, type, link_mode, config) = + { + name: arch + '-' + type + '-' + link_mode + '-' + std.asciiLower(config), + # configurePreset: arch + '-' + type + '-' + link_mode, + configurePreset: type + '-' + arch, + generators: [ + 'TGZ', + ], + "configurations": [ + config + ], + }; + +{ + version: 9, + cmakeMinimumRequired: { + major: 3, + minor: 30, + patch: 0, + }, + configurePresets: [ + { + name: 'default', + hidden: true, + displayName: 'Default Config', + description: 'Default build using Ninja Multi-Config generator', + generator: 'Ninja Multi-Config', + binaryDir: '${sourceDir}/build/${presetName}', + cacheVariables: { + CMAKE_EXPORT_COMPILE_COMMANDS: true, + CPM_USE_LOCAL_PACKAGES: true, + BUILD_TESTING: true, + }, + }, + { + name: 'asan', + inherits: 'default', + hidden: true, + cacheVariables: { + CMAKE_CXX_FLAGS_SANITIZE: '-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common', + }, + }, + { + name: 'static', + hidden: true, + cacheVariables: { + 'BUILD_SHARED_LIBS': false, + }, + }, + { + name: 'dynamic', + hidden: true, + cacheVariables: { + 'BUILD_SHARED_LIBS': true, + }, + }, + { + "name": "dev-common", + "hidden": true, + "inherits": [ + "dev-mode" + ], + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "BUILD_MCSS_DOCS": false, + "BUILD_SHARED_LIBS": true + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "OFF" + } + }, + { + "name": "dev-Linux", + "inherits": [ + "dev-common", + "ci-linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "dev-Darwin", + "inherits": [ + "dev-common", + "ci-darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "dev-win64", + "inherits": [ + "dev-common", + "cppcheck", + "ci-win64" + ], + "environment": { + "UseMultiToolTask": "ON", + "EnforceProcessCountAcrossBuilds": "ON" + } + }, + ], # TODO: + [cp_generator(arch, type, link_mode) for arch in archs for type in types for link_mode in link_modes], + + buildPresets: [] + [bp_generator(arch, type, link_mode, config) for arch in archs for type in types for link_mode in link_modes for config in configs], + testPresets: [] + [tp_generator(arch, type, link_mode, config) for arch in archs for type in types for link_mode in link_modes for config in configs], + packagePresets: [] + [pp_generator(arch, type, link_mode, config) for arch in archs for type in types for link_mode in link_modes for config in configs], + workflowPresets: [] + [wp_generator(arch, type, link_mode, config) for arch in archs for type in types for link_mode in link_modes for config in configs], +} + diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8ef4c63..075936b 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28.4...3.30) +cmake_minimum_required(VERSION 3.28...3.31) project(cmake-init-modulesExamples CXX) diff --git a/std/CMakeLists.txt b/std/CMakeLists.txt index 03cd7c8..6010064 100644 --- a/std/CMakeLists.txt +++ b/std/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.30.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.30...3.31) # # Set language version used diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 741e52c..7ea0f3a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28...3.29) +cmake_minimum_required(VERSION 3.28...3.31) project(cmake-init-modulesTests LANGUAGES CXX) From 8cb1bdee35bd1dca8db8dfd0200b02ca226bbb3d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 20:48:04 +0200 Subject: [PATCH 46/57] Use ctest --build-and-test --- CMakeLists.txt | 97 ++++++++++++++++++---------------- GNUmakefile | 11 ++-- cmake/AddUninstallTarget.cmake | 92 ++++++++++++++++++++++++++++++++ cmake/CPM.cmake | 12 ++--- cmake/my_package-config.cmake | 2 +- example/CMakeLists.txt | 35 ++++++++++-- 6 files changed, 186 insertions(+), 63 deletions(-) create mode 100644 cmake/AddUninstallTarget.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ff6bc7..d757a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) include(cmake/CPM.cmake) +include(cmake/AddUninstallTarget.cmake) # Disable clang-tidy for target macro(target_disable_clang_tidy TARGET) @@ -32,30 +33,29 @@ endmacro() # cmake-format: off # instead of find_package(fmt REQUIRED) -cpmaddpackage( - NAME fmt - GIT_TAG 10.2.1 - GITHUB_REPOSITORY fmtlib/fmt - SYSTEM YES - #FIXME(CK): - OPTIONS "FMT_MODULE ON" -) -if(TARGET fmt) - target_disable_clang_tidy(fmt) -endif() +# cpmaddpackage( +# NAME fmt +# GIT_TAG 10.2.1 +# GITHUB_REPOSITORY fmtlib/fmt +# SYSTEM YES +# # TODO(CK): OPTIONS "FMT_MODULE ON" +# ) +# if(TARGET fmt) +# target_disable_clang_tidy(fmt) +# endif() add_library(Algo SHARED) target_sources(Algo - PRIVATE - algo-impl.cpp - PUBLIC - FILE_SET CXX_MODULES - FILES - algo-interface.cppm + PRIVATE + algo-impl.cpp + PUBLIC + FILE_SET CXX_MODULES + FILES + algo-interface.cppm ) -#XXX target_link_libraries(Algo PRIVATE fmt::fmt) -target_link_libraries(Algo PRIVATE $) +# TODO(CK): target_link_libraries(Algo PRIVATE fmt::fmt) +# target_link_libraries(Algo PRIVATE $) # CMake requires the language standard to be specified as compile feature # when a target provides C++23 modules and the target will be installed @@ -63,54 +63,61 @@ target_compile_features(Algo PUBLIC cxx_std_23) include(GenerateExportHeader) generate_export_header(Algo - CUSTOM_CONTENT_FROM_VARIABLE - pragma_suppress_c4251 + CUSTOM_CONTENT_FROM_VARIABLE + # XXX pragma_suppress_c4251 ) target_sources(Algo - PUBLIC - FILE_SET HEADERS - BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} - FILES - ${CMAKE_CURRENT_BINARY_DIR}/algo_export.h + PUBLIC + FILE_SET HEADERS + BASE_DIRS + ${CMAKE_CURRENT_BINARY_DIR} + FILES + ${CMAKE_CURRENT_BINARY_DIR}/algo_export.h ) -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) +if(NOT CMAKE_SKIP_INSTALL_RULES) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) -write_basic_package_version_file("my_package-config-version.cmake" COMPATIBILITY SameMajorVersion) + write_basic_package_version_file("my_package-config-version.cmake" COMPATIBILITY SameMajorVersion) -install(TARGETS Algo + install(TARGETS Algo EXPORT my_package-targets # ... a few details omitted, see the "Deep CMake For Library Authors" talk FILE_SET CXX_MODULES - # There's currently no convention for this location, see discussion below - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package/src + # There's currently no convention for this location, see discussion below + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package/src FILE_SET HEADERS - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # Same as default, could be omitted + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # Same as default, could be omitted INCLUDES - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) -install(EXPORT my_package-targets + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + install(EXPORT my_package-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package CXX_MODULES_DIRECTORY . -) -install( + ) + install( FILES "${PROJECT_BINARY_DIR}/my_package-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package -) -# The following file includes the my_package-targets.cmake file -install(FILES cmake/my_package-config.cmake + ) + # The following file includes the my_package-targets.cmake file + install(FILES cmake/my_package-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package -) + ) +endif() # cmake-format: on ######################################################################### -enable_testing() -add_subdirectory(example) -return() +if(PROJECT_IS_TOP_LEVEL) + enable_testing() + add_subdirectory(example) +endif() ################################################## +return() # NOTE: XXX +################################################## + # project( # cmake-init-modules diff --git a/GNUmakefile b/GNUmakefile index 039086f..5db34f6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,10 +6,10 @@ MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules. # MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced. # MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk). -# export CC=gcc-13 -# export CXX=g++-13 -export CC?=clang-17 -export CXX?=$(shell which clang++) +# export CC=gcc-14 +# export CXX=g++-14 +export CC?=clang-19 +export CXX?=$(shell type -f clang++) export CMAKE_EXPORT_COMPILE_COMMANDS=YES export CPM_USE_LOCAL_PACKAGES=NO @@ -24,7 +24,7 @@ BUILD_TYPE=Debug all: .init # conan cmake --workflow --preset dev # XXX --fresh cmake --install build/dev --prefix $(CURDIR)/stagedir - #FIXME: gcovr -v + # FIXME: gcovr -v test: all cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ @@ -38,6 +38,7 @@ check: test -iwyu_tool -p build/dev/ *.cpp -- -Xiwyu --cxx17ns .init: .CMakeUserPresets.json + # TODO: jrsonnet --preserve-order CMakeUserPresets.jsonnet > CMakeUserPresets.json || perl -p -e 's//${hostSystemName}/g;' .CMakeUserPresets.json > CMakeUserPresets.json mkdir -p build/coverage/ touch .init diff --git a/cmake/AddUninstallTarget.cmake b/cmake/AddUninstallTarget.cmake new file mode 100644 index 0000000..63b3fce --- /dev/null +++ b/cmake/AddUninstallTarget.cmake @@ -0,0 +1,92 @@ +# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT) +# SPDX-FileCopyrightText: 2008-2013 Kitware Inc. +# SPDX-License-Identifier: BSD-3-Clause + +#[=======================================================================[.rst: +AddUninstallTarget +------------------ + +Add the "uninstall" target for your project:: + + include(AddUninstallTarget) + + +will create a file ``cmake_uninstall.cmake`` in the build directory and add a +custom target ``uninstall`` (or ``UNINSTALL`` on Visual Studio and Xcode) that +will remove the files installed by your package (using +``install_manifest.txt``). +See also +https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake + +The :module:`AddUninstallTarget` module must be included in your main +``CMakeLists.txt``. If included in a subdirectory it does nothing. +This allows you to use it safely in your main ``CMakeLists.txt`` and include +your project using ``add_subdirectory`` (for example when using it with +:cmake:module:`FetchContent`). + +If the ``uninstall`` target already exists, the module does nothing. +#]=======================================================================] + + +# AddUninstallTarget works only when included in the main CMakeLists.txt +if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + return() +endif() + +# The name of the target is uppercase in MSVC and Xcode (for coherence with the +# other standard targets) +if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)") + set(_uninstall "UNINSTALL") +else() + set(_uninstall "uninstall") +endif() + +# If target is already defined don't do anything +if(TARGET ${_uninstall}) + return() +endif() + + +set(_filename cmake_uninstall.cmake) + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}" +"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\") + message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\") + return() +endif() + +file(READ \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\" files) +string(STRIP \"\${files}\" files) +string(REGEX REPLACE \"\\n\" \";\" files \"\${files}\") +list(REVERSE files) +foreach(file \${files}) + if(IS_SYMLINK \"\$ENV{DESTDIR}\${file}\" OR EXISTS \"\$ENV{DESTDIR}\${file}\") + message(STATUS \"Uninstalling: \$ENV{DESTDIR}\${file}\") + execute_process( + COMMAND \${CMAKE_COMMAND} -E remove \"\$ENV{DESTDIR}\${file}\" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval) + if(NOT \"\${rm_retval}\" EQUAL 0) + message(FATAL_ERROR \"Problem when removing \\\"\$ENV{DESTDIR}\${file}\\\"\") + endif() + else() + message(STATUS \"Not-found: \$ENV{DESTDIR}\${file}\") + endif() +endforeach(file) +") + +set(_desc "Uninstall the project...") +if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") + set(_comment COMMAND \$\(CMAKE_COMMAND\) -E cmake_echo_color --switch=$\(COLOR\) --cyan "${_desc}") +else() + set(_comment COMMENT "${_desc}") +endif() +add_custom_target(${_uninstall} + ${_comment} + COMMAND ${CMAKE_COMMAND} -P ${_filename} + USES_TERMINAL + BYPRODUCTS uninstall_byproduct + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +set_property(SOURCE uninstall_byproduct PROPERTY SYMBOLIC 1) + +set_property(TARGET ${_uninstall} PROPERTY FOLDER "CMakePredefinedTargets") diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index b03800f..baf2d8c 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -2,8 +2,8 @@ # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors -set(CPM_DOWNLOAD_VERSION 0.39.0) -set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef") +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") if(CPM_SOURCE_CACHE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") @@ -16,11 +16,9 @@ endif() # Expand relative path. This is important if the provided path contains a tilde (~) get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -file( - DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake - ${CPM_DOWNLOAD_LOCATION} - EXPECTED_HASH SHA256=${CPM_HASH_SUM} +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} ) include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/my_package-config.cmake b/cmake/my_package-config.cmake index ec5deb9..eaba36c 100644 --- a/cmake/my_package-config.cmake +++ b/cmake/my_package-config.cmake @@ -1,4 +1,4 @@ # include(CMakeFindDependencyMacro) -# find_dependency(fmt) +# TODO(CK): find_dependency(fmt) include("${CMAKE_CURRENT_LIST_DIR}/my_package-targets.cmake") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 075936b..708caad 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -2,25 +2,50 @@ cmake_minimum_required(VERSION 3.28...3.31) project(cmake-init-modulesExamples CXX) -include(../cmake/folders.cmake) - if(PROJECT_IS_TOP_LEVEL) # Neither of these two are technically needed, but they make the expectation clear set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_EXTENSIONS FALSE) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - find_package(my_package 0.1 REQUIRED) + find_package(my_package 0.1 QUIET) + if(NOT my_package_FOUND) + message(STATUS "find_package(my_package) was NOT found, use as subproject ...") + # test if the targets are usable if used as subproject + add_subdirectory(.. my_package EXCLUDE_FROM_ALL) + endif() + enable_testing() endif() add_executable(app main.cpp) target_link_libraries(app PRIVATE Algo) -add_test(NAME app COMMAND app) +add_test(NAME app-tests COMMAND app) -return() +if(NOT PROJECT_IS_TOP_LEVEL) + # test if the targets are findable from the build directory + # cmake-format: off + add_test(find-package-test + ${CMAKE_CTEST_COMMAND} + -C ${CMAKE_BUILD_TYPE} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) + # cmake-format: on +endif() ################################################## +return() # NOTE: XXX +################################################## + +include(../cmake/folders.cmake) if(PROJECT_IS_TOP_LEVEL) find_package(cmake-init-modules 0.1 REQUIRED) From 5ce3e7467098e4a4e3f49b835a7dc5351898103f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 22:33:32 +0200 Subject: [PATCH 47/57] format all files --- .CMakeUserPresets.json | 20 +++++++++++++++- CMakeLists.txt | 9 ++++++-- CMakePresets.json | 10 +++++++- GNUmakefile | 10 +------- cmake/AddUninstallTarget.cmake | 34 +++++++++++++++++---------- cmake/CPM.cmake | 8 ++++--- cmake/dev-mode.cmake | 1 - cmake/lint-targets.cmake | 1 + cmake/lint.cmake | 1 + example/CMakeLists.txt | 42 +++++++++++++++++----------------- 10 files changed, 86 insertions(+), 50 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index c5c453b..02b5166 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -82,7 +82,12 @@ "name": "dev", "configurePreset": "dev", "configuration": "Debug", - "jobs": 12 + "jobs": 12, + "targets": [ + "all", + "all_verify_interface_header_sets", + "install" + ] } ], "testPresets": [ @@ -99,6 +104,15 @@ } } ], + "packagePresets": [ + { + "name": "dev", + "configurePreset": "dev", + "generators": [ + "TGZ" + ] + } + ], "workflowPresets": [ { "name": "dev", @@ -114,6 +128,10 @@ { "type": "test", "name": "dev" + }, + { + "type": "package", + "name": "dev" } ] } diff --git a/CMakeLists.txt b/CMakeLists.txt index d757a2a..bbab02e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,12 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) include(cmake/CPM.cmake) -include(cmake/AddUninstallTarget.cmake) + +if(PROJECT_IS_TOP_LEVEL) + include(cmake/AddUninstallTarget.cmake) + include(cmake/lint-targets.cmake) + include(cmake/spell-targets.cmake) +endif() # Disable clang-tidy for target macro(target_disable_clang_tidy TARGET) @@ -76,6 +81,7 @@ target_sources(Algo ) if(NOT CMAKE_SKIP_INSTALL_RULES) + include(CPack) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -118,7 +124,6 @@ endif() return() # NOTE: XXX ################################################## - # project( # cmake-init-modules # VERSION 0.1.0 diff --git a/CMakePresets.json b/CMakePresets.json index c1d38d1..f56cf1d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -25,7 +25,15 @@ "name": "dev-mode", "hidden": true, "inherits": "cmake-pedantic", - "cacheVariables": { + "installDir": "${sourceDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceDir}/stagedir" + }, + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_MESSAGE_LOG_LEVEL": "WARNING", + "CMAKE_VERIFY_INTERFACE_HEADER_SETS": true, "cmake-init-modules_DEVELOPER_MODE": true } }, diff --git a/GNUmakefile b/GNUmakefile index 5db34f6..6375baf 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -23,17 +23,9 @@ BUILD_TYPE=Debug all: .init # conan cmake --workflow --preset dev # XXX --fresh - cmake --install build/dev --prefix $(CURDIR)/stagedir # FIXME: gcovr -v -test: all - cd example && cmake -B build -S . -G Ninja -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ - -D 'CMAKE_PREFIX_PATH=$(CURDIR)/stagedir;$(CURDIR)/conan' \ - # --toolchain $(CURDIR)/conan/conan_toolchain.cmake # XXX --debug-find-pkg=fmt - ninja -C example/build - ninja -C example/build test - -check: test +check: all -run-clang-tidy -p build/dev -iwyu_tool -p build/dev/ *.cpp -- -Xiwyu --cxx17ns diff --git a/cmake/AddUninstallTarget.cmake b/cmake/AddUninstallTarget.cmake index 63b3fce..efbac59 100644 --- a/cmake/AddUninstallTarget.cmake +++ b/cmake/AddUninstallTarget.cmake @@ -27,7 +27,6 @@ your project using ``add_subdirectory`` (for example when using it with If the ``uninstall`` target already exists, the module does nothing. #]=======================================================================] - # AddUninstallTarget works only when included in the main CMakeLists.txt if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") return() @@ -46,11 +45,11 @@ if(TARGET ${_uninstall}) return() endif() - set(_filename cmake_uninstall.cmake) -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}" -"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\") +file( + WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}" + "if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\") message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\") return() endif() @@ -73,20 +72,31 @@ foreach(file \${files}) message(STATUS \"Not-found: \$ENV{DESTDIR}\${file}\") endif() endforeach(file) -") +" +) set(_desc "Uninstall the project...") if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") - set(_comment COMMAND \$\(CMAKE_COMMAND\) -E cmake_echo_color --switch=$\(COLOR\) --cyan "${_desc}") + set(_comment + COMMAND + \$\(CMAKE_COMMAND\) + -E + cmake_echo_color + --switch=$\(COLOR\) + --cyan + "${_desc}" + ) else() set(_comment COMMENT "${_desc}") endif() -add_custom_target(${_uninstall} - ${_comment} - COMMAND ${CMAKE_COMMAND} -P ${_filename} - USES_TERMINAL - BYPRODUCTS uninstall_byproduct - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +add_custom_target( + ${_uninstall} + ${_comment} + COMMAND ${CMAKE_COMMAND} -P ${_filename} + USES_TERMINAL + BYPRODUCTS uninstall_byproduct + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) set_property(SOURCE uninstall_byproduct PROPERTY SYMBOLIC 1) set_property(TARGET ${_uninstall} PROPERTY FOLDER "CMakePredefinedTargets") diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index baf2d8c..d311a8d 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -16,9 +16,11 @@ endif() # Expand relative path. This is important if the provided path contains a tilde (~) get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -file(DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake - ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +file( + DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + EXPECTED_HASH SHA256=${CPM_HASH_SUM} ) include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/dev-mode.cmake b/cmake/dev-mode.cmake index 25b3c98..1d9f264 100644 --- a/cmake/dev-mode.cmake +++ b/cmake/dev-mode.cmake @@ -1,6 +1,5 @@ include(cmake/folders.cmake) -# XXX include(CTest) option(BUILD_TESTING "" ${PROJECT_IS_TOP_LEVEL}) if(BUILD_TESTING) add_subdirectory(test) diff --git a/cmake/lint-targets.cmake b/cmake/lint-targets.cmake index f3790c0..5c01dc1 100644 --- a/cmake/lint-targets.cmake +++ b/cmake/lint-targets.cmake @@ -1,4 +1,5 @@ set(FORMAT_PATTERNS + CMake*Presets.json source/*.cpp source/*.hpp include/*.hpp diff --git a/cmake/lint.cmake b/cmake/lint.cmake index b536270..ac67090 100644 --- a/cmake/lint.cmake +++ b/cmake/lint.cmake @@ -9,6 +9,7 @@ endmacro() default(FORMAT_COMMAND clang-format) default( PATTERNS + CMake*Presets.json source/*.cpp source/*.hpp include/*.hpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 708caad..a436612 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -9,11 +9,11 @@ if(PROJECT_IS_TOP_LEVEL) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) find_package(my_package 0.1 QUIET) - if(NOT my_package_FOUND) - message(STATUS "find_package(my_package) was NOT found, use as subproject ...") - # test if the targets are usable if used as subproject - add_subdirectory(.. my_package EXCLUDE_FROM_ALL) - endif() + if(NOT my_package_FOUND) + message(STATUS "find_package(my_package) was NOT found, use as subproject ...") + # test if the targets are usable if used as subproject + add_subdirectory(.. my_package EXCLUDE_FROM_ALL) + endif() enable_testing() endif() @@ -23,22 +23,22 @@ target_link_libraries(app PRIVATE Algo) add_test(NAME app-tests COMMAND app) if(NOT PROJECT_IS_TOP_LEVEL) - # test if the targets are findable from the build directory - # cmake-format: off - add_test(find-package-test - ${CMAKE_CTEST_COMMAND} - -C ${CMAKE_BUILD_TYPE} - --build-and-test - "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-options - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" - ) - # cmake-format: on + # test if the targets are findable from the build directory + # cmake-format: off + add_test(find-package-test + ${CMAKE_CTEST_COMMAND} + -C ${CMAKE_BUILD_TYPE} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) + # cmake-format: on endif() ################################################## From ba16e326f69a9d2fdce5bf0f6a0c0e2117954ea9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 22:49:46 +0200 Subject: [PATCH 48/57] Rename c++20 module to *.cppm --- std/CMakeLists.txt | 2 +- std/{uses_std.cxx => uses_std.cppm} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename std/{uses_std.cxx => uses_std.cppm} (100%) diff --git a/std/CMakeLists.txt b/std/CMakeLists.txt index 6010064..88e8533 100644 --- a/std/CMakeLists.txt +++ b/std/CMakeLists.txt @@ -39,7 +39,7 @@ target_sources(main PRIVATE main.cpp) # Make a library. add_library(uses_std STATIC) # Add sources. -target_sources(uses_std PRIVATE uses_std.cxx) +target_sources(uses_std PRIVATE uses_std.cppm) # Tell CMake we're using C++23 but only C++20 is needed to consume it. target_compile_features(uses_std PRIVATE cxx_std_23 INTERFACE cxx_std_20) diff --git a/std/uses_std.cxx b/std/uses_std.cppm similarity index 100% rename from std/uses_std.cxx rename to std/uses_std.cppm From 656e696d2085443db23e75b10ac909a765601fea Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 22:53:37 +0200 Subject: [PATCH 49/57] Add using std example --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbab02e..f787e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ endif() if(PROJECT_IS_TOP_LEVEL) enable_testing() add_subdirectory(example) + add_subdirectory(std) endif() ################################################## From 057889787a33f374c905fbb8fa8b595582372bde Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 23:03:18 +0200 Subject: [PATCH 50/57] Modernize CI tools used --- .github/workflows/ci.yml | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6aed63..3005035 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,19 +12,19 @@ on: jobs: lint: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - with: { python-version: "3.10" } + with: { python-version: "3.12" } - name: Install codespell run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-14 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-19 -P cmake/lint.cmake - name: Spell check if: always() @@ -33,9 +33,9 @@ jobs: coverage: needs: [lint] - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 - env: { CXX: clang++-17 } + env: { CXX: clang++-19 } # To enable coverage, delete the last line from the conditional below and # edit the "" placeholder to your GitHub name. @@ -53,12 +53,12 @@ jobs: - name: Install Python uses: actions/setup-python@v5 - with: { python-version: "3.10" } + with: { python-version: "3.12" } - name: Setup Cpp uses: aminya/setup-cpp@v1 with: - compiler: llvm-17 + compiler: llvm-19 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -97,21 +97,21 @@ jobs: sanitize: needs: [lint] - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 - env: { CXX: clang++-17 } + env: { CXX: clang++-19 } steps: - uses: actions/checkout@v4 - name: Install Python uses: actions/setup-python@v5 - with: { python-version: "3.10" } + with: { python-version: "3.12" } - name: Setup Cpp uses: aminya/setup-cpp@v1 with: - compiler: llvm-17 + compiler: llvm-19 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -152,7 +152,7 @@ jobs: fail-fast: false matrix: - os: [macos-14, ubuntu-22.04, windows-2022] + os: [macos-15, ubuntu-24.04, windows-2022] type: [shared, static] @@ -166,24 +166,24 @@ jobs: - uses: actions/checkout@v4 - name: Install Python - if: matrix.os != 'macos-14' + if: matrix.os != 'macos-15' uses: actions/setup-python@v5 - with: { python-version: "3.10" } + with: { python-version: "3.12" } - - name: Install llvm-17 - if: matrix.os == 'macos-14' + - name: Install llvm-19 + if: matrix.os == 'macos-15' run: | brew install conan gcovr ninja llvm - echo $(brew --prefix llvm@17)/bin + echo $(brew --prefix llvm@19)/bin echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile - export PATH=$(brew --prefix llvm@17)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV + export PATH=$(brew --prefix llvm@19)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV - name: Setup Cpp - if: matrix.os == 'ubuntu-22.04' + if: matrix.os == 'ubuntu-24.04' uses: aminya/setup-cpp@v1 with: - compiler: llvm-17 + compiler: llvm-19 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -215,7 +215,7 @@ jobs: - name: Configure on windows if: matrix.os == 'windows-2022' shell: pwsh - run: cmake -G "Visual Studio 17 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release + run: cmake -G "Visual Studio 19 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$(Get-Location)/stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} - name: Setup PATH @@ -245,7 +245,7 @@ jobs: # Deploy docs only when builds succeed needs: [sanitize, test] - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 # To enable, first you have to create an orphaned gh-pages branch: # @@ -267,7 +267,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - with: { python-version: "3.10" } + with: { python-version: "3.12" } - name: Install m.css dependencies run: pip3 install jinja2 Pygments cmake ninja From 062a9b655b96a0de0540bcc219d1c02615b03d58 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 14 Oct 2024 23:11:48 +0200 Subject: [PATCH 51/57] Add using std test --- .github/workflows/ci.yml | 20 ++++++++++---------- CMakeLists.txt | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3005035..4347755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-19 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-18 -P cmake/lint.cmake - name: Spell check if: always() @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-24.04 - env: { CXX: clang++-19 } + env: { CXX: clang++-18 } # To enable coverage, delete the last line from the conditional below and # edit the "" placeholder to your GitHub name. @@ -58,7 +58,7 @@ jobs: - name: Setup Cpp uses: aminya/setup-cpp@v1 with: - compiler: llvm-19 + compiler: llvm-18 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -99,7 +99,7 @@ jobs: runs-on: ubuntu-24.04 - env: { CXX: clang++-19 } + env: { CXX: clang++-18 } steps: - uses: actions/checkout@v4 @@ -111,7 +111,7 @@ jobs: - name: Setup Cpp uses: aminya/setup-cpp@v1 with: - compiler: llvm-19 + compiler: llvm-18 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -170,20 +170,20 @@ jobs: uses: actions/setup-python@v5 with: { python-version: "3.12" } - - name: Install llvm-19 + - name: Install llvm-18 if: matrix.os == 'macos-15' run: | brew install conan gcovr ninja llvm - echo $(brew --prefix llvm@19)/bin + echo $(brew --prefix llvm@18)/bin echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile - export PATH=$(brew --prefix llvm@19)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV + export PATH=$(brew --prefix llvm@18)/bin:$PATH && echo "PATH=$PATH" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV - name: Setup Cpp if: matrix.os == 'ubuntu-24.04' uses: aminya/setup-cpp@v1 with: - compiler: llvm-19 + compiler: llvm-18 vcvarsall: ${{ contains(matrix.os, 'windows') }} clangformat: true clangtidy: true @@ -215,7 +215,7 @@ jobs: - name: Configure on windows if: matrix.os == 'windows-2022' shell: pwsh - run: cmake -G "Visual Studio 19 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release + run: cmake -G "Visual Studio 17 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$(Get-Location)/stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} - name: Setup PATH diff --git a/CMakeLists.txt b/CMakeLists.txt index f787e14..48538ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,22 @@ endif() if(PROJECT_IS_TOP_LEVEL) enable_testing() add_subdirectory(example) - add_subdirectory(std) + + # cmake-format: off + add_test(using-std-test + ${CMAKE_CTEST_COMMAND} + -C ${CMAKE_BUILD_TYPE} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}/std" + "${CMAKE_CURRENT_BINARY_DIR}/std" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) + # cmake-format: on endif() ################################################## From efd8fd0c64aae796909429bec3f36477532da73d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 15 Oct 2024 10:05:43 +0200 Subject: [PATCH 52/57] Use windowsToolchain and workflow preset on CI Distable using std for now --- .github/workflows/ci.yml | 80 +++++++++++++++++++++------------------- .gitmodules | 3 ++ CMakeLists.txt | 34 ++++++++--------- CMakePresets.json | 17 ++++++--- cmake/WindowsToolchain | 1 + cmake/lint-targets.cmake | 2 +- cmake/lint.cmake | 2 +- 7 files changed, 76 insertions(+), 63 deletions(-) create mode 100644 .gitmodules create mode 160000 cmake/WindowsToolchain diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4347755..b83174b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,12 +153,15 @@ jobs: matrix: os: [macos-15, ubuntu-24.04, windows-2022] - - type: [shared, static] - include: - - { type: shared, shared: YES } - - { type: static, shared: NO } + - { os: macos-15, uname: Darwin } + - { os: ubuntu-22.04, uname: Linux } + - { os: windows-2022, uname: Windows } + + # type: [shared, static] + # include: + # - { type: shared, shared: YES } + # - { type: static, shared: NO } runs-on: ${{ matrix.os }} @@ -207,39 +210,42 @@ jobs: Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' - name: Configure preset - if: matrix.os != 'windows-2022' - shell: pwsh - run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" - -D BUILD_SHARED_LIBS=${{ matrix.shared }} - - - name: Configure on windows - if: matrix.os == 'windows-2022' - shell: pwsh - run: cmake -G "Visual Studio 17 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release - -D CMAKE_INSTALL_PREFIX=$(Get-Location)/stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} - - - name: Setup PATH - if: matrix.os == 'windows-2022' && matrix.type == 'shared' - run: Add-Content "$env:GITHUB_PATH" "$(Get-Location)\build\Release" - - - name: Build - run: cmake --build build --config Release -j 2 - - - name: Install - run: cmake --install build --config Release --prefix stagedir - - - name: Test - working-directory: build - run: ctest --output-on-failure --no-tests=error -C Release -j 2 - - - name: TestInstalledVersion - if: matrix.os != 'windows-2022' + # if: matrix.os != 'windows-2022' + shell: bash run: | - cmake -B example/build -S example -G Ninja -D CMAKE_BUILD_TYPE=Release \ - -D "CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan" \ - # --toolchain "$PWD/conan/conan_toolchain.cmake" - ninja -C example/build - ninja -C example/build test + export hostSystemName=${{ matrix.uname }} + uname || echo ${hostSystemName} + perl -p -e "s//${hostSystemName}/g;" .CMakeUserPresets.json > CMakeUserPresets.json + cmake --workflow --preset=dev # XXX "--preset=ci-$("${{ matrix.os }}".split("-")[0])" + + # - name: Configure on windows + # if: matrix.os == 'windows-2022' + # shell: pwsh + # run: cmake -G "Visual Studio 17 2022" -S . -B build -D CMAKE_BUILD_TYPE=Release + # -D CMAKE_INSTALL_PREFIX=$(Get-Location)/stagedir -D BUILD_SHARED_LIBS=${{ matrix.shared }} + + # - name: Setup PATH + # if: matrix.os == 'windows-2022' && matrix.type == 'shared' + # run: Add-Content "$env:GITHUB_PATH" "$(Get-Location)\build\Release" + + # - name: Build + # run: cmake --build build --config Release -j 2 + + # - name: Install + # run: cmake --install build --config Release --prefix stagedir + + # - name: Test + # working-directory: build + # run: ctest --output-on-failure --no-tests=error -C Release -j 2 + + # - name: TestInstalledVersion + # if: matrix.os != 'windows-2022' + # run: | + # cmake -B example/build -S example -G Ninja -D CMAKE_BUILD_TYPE=Release \ + # -D "CMAKE_PREFIX_PATH=$PWD/stagedir;$PWD/conan" \ + # # --toolchain "$PWD/conan/conan_toolchain.cmake" + # ninja -C example/build + # ninja -C example/build test docs: # Deploy docs only when builds succeed diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dcebc89 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake/WindowsToolchain"] + path = cmake/WindowsToolchain + url = https://github.com/MarkSchofield/WindowsToolchain.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 48538ca..e650c3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,6 @@ endif() set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) -include(cmake/CPM.cmake) - if(PROJECT_IS_TOP_LEVEL) include(cmake/AddUninstallTarget.cmake) include(cmake/lint-targets.cmake) @@ -37,6 +35,7 @@ endmacro() ######################################################################### # cmake-format: off +# include(cmake/CPM.cmake) # instead of find_package(fmt REQUIRED) # cpmaddpackage( # NAME fmt @@ -59,8 +58,6 @@ target_sources(Algo FILES algo-interface.cppm ) -# TODO(CK): target_link_libraries(Algo PRIVATE fmt::fmt) -# target_link_libraries(Algo PRIVATE $) # CMake requires the language standard to be specified as compile feature # when a target provides C++23 modules and the target will be installed @@ -69,7 +66,6 @@ target_compile_features(Algo PUBLIC cxx_std_23) include(GenerateExportHeader) generate_export_header(Algo CUSTOM_CONTENT_FROM_VARIABLE - # XXX pragma_suppress_c4251 ) target_sources(Algo PUBLIC @@ -119,20 +115,20 @@ if(PROJECT_IS_TOP_LEVEL) enable_testing() add_subdirectory(example) - # cmake-format: off - add_test(using-std-test - ${CMAKE_CTEST_COMMAND} - -C ${CMAKE_BUILD_TYPE} - --build-and-test - "${CMAKE_CURRENT_SOURCE_DIR}/std" - "${CMAKE_CURRENT_BINARY_DIR}/std" - --build-generator ${CMAKE_GENERATOR} - --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-options - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" - ) + # # cmake-format: off + # add_test(using-std-test + # ${CMAKE_CTEST_COMMAND} + # -C ${CMAKE_BUILD_TYPE} + # --build-and-test + # "${CMAKE_CURRENT_SOURCE_DIR}/std" + # "${CMAKE_CURRENT_BINARY_DIR}/std" + # --build-generator ${CMAKE_GENERATOR} + # --build-makeprogram ${CMAKE_MAKE_PROGRAM} + # --build-options + # "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + # "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + # "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + # ) # cmake-format: on endif() diff --git a/CMakePresets.json b/CMakePresets.json index f56cf1d..0fb82bf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -42,8 +42,7 @@ "hidden": true, "cacheVariables": { "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Release;Debug", - "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/conan_toolchain.cmake", - "CMAKE_POLICY_DEFAULT_CMP0091": "NEW" + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/conan_toolchain.cmake" } }, { @@ -114,6 +113,7 @@ { "name": "ci-linux", "generator": "Ninja", + "description": "This build is only available on Linux", "hidden": true, "inherits": [ "flags-linux", @@ -126,6 +126,7 @@ { "name": "ci-darwin", "generator": "Ninja", + "description": "This build is only available on Darwin", "hidden": true, "inherits": [ "flags-darwin", @@ -140,11 +141,14 @@ "inherits": [ "ci-std" ], - "generator": "Visual Studio 17 2022", - "architecture": "x64", + "toolchainFile": "cmake/WindowsToolchain/Windows.MSVC.toolchain.cmake", + "generator": "Ninja Multi-Config", + "description": "This build is only available on Windows", "hidden": true, + "architecture": "x64", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_SYSTEM_PROCESSOR": "AMD64" }, "condition": { "type": "equals", @@ -156,6 +160,7 @@ "name": "coverage-linux", "binaryDir": "${sourceDir}/build/coverage", "inherits": "ci-linux", + "description": "This build is only available on Linux", "hidden": true, "cacheVariables": { "ENABLE_COVERAGE": true, @@ -171,6 +176,7 @@ "name": "coverage-darwin", "binaryDir": "${sourceDir}/build/coverage", "inherits": "ci-darwin", + "description": "This build is only available on Darwin", "hidden": true, "cacheVariables": { "ENABLE_COVERAGE": true, @@ -199,6 +205,7 @@ "ci-linux", "dev-mode" ], + "description": "This build is only available on Linux", "cacheVariables": { "CMAKE_SKIP_INSTALL_RULES": true, "CMAKE_BUILD_TYPE": "Sanitize", diff --git a/cmake/WindowsToolchain b/cmake/WindowsToolchain new file mode 160000 index 0000000..b44662d --- /dev/null +++ b/cmake/WindowsToolchain @@ -0,0 +1 @@ +Subproject commit b44662d3e3fc1a4375e10a856ce098fc1507db1c diff --git a/cmake/lint-targets.cmake b/cmake/lint-targets.cmake index 5c01dc1..e73d7b3 100644 --- a/cmake/lint-targets.cmake +++ b/cmake/lint-targets.cmake @@ -1,5 +1,5 @@ set(FORMAT_PATTERNS - CMake*Presets.json + # CMake*Presets.json source/*.cpp source/*.hpp include/*.hpp diff --git a/cmake/lint.cmake b/cmake/lint.cmake index ac67090..70d5042 100644 --- a/cmake/lint.cmake +++ b/cmake/lint.cmake @@ -9,7 +9,7 @@ endmacro() default(FORMAT_COMMAND clang-format) default( PATTERNS - CMake*Presets.json + # CMake*Presets.json source/*.cpp source/*.hpp include/*.hpp From 4b94163d9b38f65735ff58a7ca1e9e307e221cfa Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 15 Oct 2024 20:49:26 +0200 Subject: [PATCH 53/57] Fix Windows workflow preset Use CMAKE_TOOLCHAIN_FILE for ctest too Checkout with submodules recursive strategy --- .CMakeUserPresets.json | 10 +++------- .github/workflows/ci.yml | 4 +++- CMakeLists.txt | 3 ++- CMakePresets.json | 9 +++++---- example/CMakeLists.txt | 3 ++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 02b5166..7952653 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -12,7 +12,6 @@ "inherits": [ "dev-mode" ], - "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": true, @@ -44,7 +43,7 @@ } }, { - "name": "dev-win64", + "name": "dev-Windows", "inherits": [ "dev-common", "cppcheck", @@ -57,23 +56,20 @@ }, { "name": "dev", - "generator": "Ninja", "inherits": "dev-" }, { "name": "dev-coverage", - "generator": "Ninja", "inherits": [ "ci-coverage", - "dev-" + "dev-Linux" ] }, { "name": "dev-sanitize", - "generator": "Ninja", "inherits": [ "ci-sanitize", - "dev-" + "dev-Linux" ] } ], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b83174b..278b092 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -155,7 +155,7 @@ jobs: os: [macos-15, ubuntu-24.04, windows-2022] include: - { os: macos-15, uname: Darwin } - - { os: ubuntu-22.04, uname: Linux } + - { os: ubuntu-24.04, uname: Linux } - { os: windows-2022, uname: Windows } # type: [shared, static] @@ -167,6 +167,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: recursive - name: Install Python if: matrix.os != 'macos-15' diff --git a/CMakeLists.txt b/CMakeLists.txt index e650c3c..210f3fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,9 +125,10 @@ if(PROJECT_IS_TOP_LEVEL) # --build-generator ${CMAKE_GENERATOR} # --build-makeprogram ${CMAKE_MAKE_PROGRAM} # --build-options - # "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" # "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + # "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" # "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + # "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" # ) # cmake-format: on endif() diff --git a/CMakePresets.json b/CMakePresets.json index 0fb82bf..8e1cf22 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -97,7 +97,7 @@ }, { "name": "flags-windows", - "description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard", + "description": "NOTE: that all the flags after /W4 are required for MSVC to conform to the language standard", "hidden": true, "cacheVariables": { "CMAKE_CXX_FLAGS": "/sdl /guard:cf /utf-8 /diagnostics:caret /w14165 /w44242 /w44254 /w44263 /w34265 /w34287 /w44296 /w44365 /w44388 /w44464 /w14545 /w14546 /w14547 /w14549 /w14555 /w34619 /w34640 /w24826 /w14905 /w14906 /w14928 /w45038 /W4 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc", @@ -141,14 +141,15 @@ "inherits": [ "ci-std" ], - "toolchainFile": "cmake/WindowsToolchain/Windows.MSVC.toolchain.cmake", "generator": "Ninja Multi-Config", "description": "This build is only available on Windows", "hidden": true, - "architecture": "x64", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "CMAKE_SYSTEM_PROCESSOR": "AMD64" + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl", + "CMAKE_SYSTEM_PROCESSOR": "AMD64", + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/WindowsToolchain/Windows.MSVC.toolchain.cmake" }, "condition": { "type": "equals", diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a436612..8d17e3d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -34,9 +34,10 @@ if(NOT PROJECT_IS_TOP_LEVEL) --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" ) # cmake-format: on endif() From 67fd34d09d1f02dafda759438c0405a69058155d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 15 Oct 2024 20:54:33 +0200 Subject: [PATCH 54/57] No cppcheck used on windows CI --- .CMakeUserPresets.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 7952653..250d0d0 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -46,7 +46,6 @@ "name": "dev-Windows", "inherits": [ "dev-common", - "cppcheck", "ci-win64" ], "environment": { From 4e77f2000db750168159a706c7a806f2e6cc0e25 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 15 Oct 2024 21:06:35 +0200 Subject: [PATCH 55/57] Setup path to dll on windows CI --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 278b092..9f7a768 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -211,6 +211,10 @@ jobs: Add-Content "$env:GITHUB_ENV" 'UseMultiToolTask=true' Add-Content "$env:GITHUB_ENV" 'EnforceProcessCountAcrossBuilds=true' + - name: Setup PATH + if: matrix.os == 'windows-2022' + run: Add-Content "$env:GITHUB_PATH" "$(Get-Location)\stagedir\bin" + - name: Configure preset # if: matrix.os != 'windows-2022' shell: bash From 9f312c4e5434e3f844a8467cc22939a6ed87f083 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 1 Nov 2024 13:13:47 +0100 Subject: [PATCH 56/57] Use generator expression for CMAKE_BUILD_TYPE --- example/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8d17e3d..446a089 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -23,18 +23,20 @@ target_link_libraries(app PRIVATE Algo) add_test(NAME app-tests COMMAND app) if(NOT PROJECT_IS_TOP_LEVEL) - # test if the targets are findable from the build directory + # test if the targets are findable from the source or install directory # cmake-format: off - add_test(find-package-test - ${CMAKE_CTEST_COMMAND} - -C ${CMAKE_BUILD_TYPE} + add_test(NAME find-package-test + COMMAND ${CMAKE_CTEST_COMMAND} + # --verbose + --output-on-failure + -C $ --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DCMAKE_BUILD_TYPE=$" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" From 9819f7bf0496cfb43c45f6fd8d99509f258b488a Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 1 Nov 2024 13:34:37 +0100 Subject: [PATCH 57/57] Add configurations list to packagePreset --- .CMakeUserPresets.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json index 250d0d0..9552627 100644 --- a/.CMakeUserPresets.json +++ b/.CMakeUserPresets.json @@ -103,6 +103,9 @@ { "name": "dev", "configurePreset": "dev", + "configurations": [ + "Debug" + ], "generators": [ "TGZ" ]