my CMakeLists.txt
contains this:
# ---- Create library ----
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
# Link dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
# FIXME: should be PRIVATE! CK
target_link_libraries(${PROJECT_NAME} PUBLIC project_warnings project_options)
# target_include_directories with the SYSTEM modifier will request the compiler
# to omit warnings from the provided paths, if the compiler supports that
target_include_directories(
${PROJECT_NAME} SYSTEM PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(CMAKE_SKIP_INSTALL_RULES)
return()
endif()
# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.
# Add other targets that you want installe here. Or be default we just package
# all targets recursively found for the current folder if not specified.
package_project(
NAME ${PROJECT_NAME}
TARGETS ${PROJECT_NAME} project_options project_warnings
PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include
PUBLIC_DEPENDENCIES_CONFIGURED "fmt 8.1.1"
# FIXME: not yet used! PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
)
cmake -B ./build-ModernCmakeStarter-Debug -S /Users/clausklein/Workspace/cpp/ModernCmakeStarter/all -D OPT_ENABLE_COVERAGE=NO -DOPT_WARNINGS_AS_ERRORS=NO
-- CPM: adding package [email protected] (v3.0.0 at /Users/clausklein/.cache/CPM/cxxopts/0c1df694f5ab3306e541038e6a2ed62926062894)
-- CPM: adding package greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/standalone/..)
-- CPM: greeter: adding package [email protected] (v0.20.0 at /Users/clausklein/.cache/CPM/project_options/f4f28e0d6a43eb4247d834f6b906d21040cf1ef9)
-- CPM: greeter: adding package [email protected] (v1.8.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/987b02f8a9fe04de3c43e0e7a1afbb29c87adc5e)
-- Module support is disabled.
-- Version: 8.1.1
-- Build type: Debug
-- CXX_STANDARD: 20
-- Required features: cxx_variadic_templates
-- CPM: greeter: adding package [email protected] (8.1.1 at /Users/clausklein/.cache/CPM/fmt/15c05aa781ab44fa13a906fe5737c1d14e5edee9)
-- Developer mode is ON. For production, use `-DENABLE_DEVELOPER_MODE:BOOL=OFF`. Building the project for the developer...
-- The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is 90
-- /usr/local/bin/ccache found and enabled
-- CPM: adding package [email protected] (v2.4.8 at /Users/clausklein/.cache/CPM/doctest/367f22d2dff85570a9f727b99741f9e40b17df46)
-- CPM: adding package [email protected] (v1.7.3 at /Users/clausklein/.cache/CPM/format.cmake/17e103764947115e78d95ecc29c4bee54dc64e08)
-- CPM: adding package Greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/test/..)
-- CPM: adding package m.css@0 (a0d292ec311b97fefd21e93cdefb60f88d19ede6 at /Users/clausklein/.cache/CPM/m.css/23b42fe3166cf5c34c25c267ae0664557edd2200)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clausklein/Workspace/cpp/ModernCmakeStarter/build-ModernCmakeStarter-Debug
DESTDIR=/Users/clausklein/Workspace/cpp/stage cmake --install ./build-ModernCmakeStarter-Debug --prefix /usr
-- Install configuration: "Debug"
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/cxxopts.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/cxxopts.pc
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libfmtd.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets-debug.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/args.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/chrono.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/color.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/compile.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/core.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format-inl.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/locale.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/os.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ostream.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/printf.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ranges.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/xchar.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/fmt.pc
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter/greeter.h
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libgreeter.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfigVersion.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfig.cmake
-- Old export file "/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake" will be replaced. Removing files [/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake].
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/usage
-- # The package greeter provides the following CMake targets:
find_package(greeter CONFIG REQUIRED)
target_link_libraries(main PRIVATE greeter::greeter greeter::project_options greeter::project_warnings)
bash-3.2$
This installed CMake config packages contains:
# Create imported target greeter::greeter
add_library(greeter::greeter STATIC IMPORTED)
set_target_properties(greeter::greeter PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_20"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "fmt::fmt;greeter::project_warnings;greeter::project_options"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include"
)
# Create imported target greeter::project_options
add_library(greeter::project_options INTERFACE IMPORTED)
set_target_properties(greeter::project_options PROPERTIES
INTERFACE_COMPILE_FEATURES "cxx_std_20"
INTERFACE_COMPILE_OPTIONS "-fsanitize=address,undefined"
INTERFACE_LINK_OPTIONS "-fsanitize=address,undefined"
)
# Create imported target greeter::project_warnings
add_library(greeter::project_warnings INTERFACE IMPORTED)
set_target_properties(greeter::project_warnings PROPERTIES
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:-Wall;-Wextra;-Wshadow;-Wnon-virtual-dtor;-Wold-style-cast;-Wcast-align;-Wunused;-Woverloaded-virtual;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:C>:-Wall;-Wextra;-Wshadow;-Wcast-align;-Wunused;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:CUDA>:-Wall;-Wextra;-Wunused;-Wconversion;-Wshadow>"
)
``
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too