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..940daa7 --- /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 agressive 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)