mirror of
https://github.com/TheLartians/ModernCppStarter.git
synced 2025-09-01 06:30:52 +02:00
add build time dependency to static lib
the header only fmt lib is used to show this
This commit is contained in:
parent
b58e0717f4
commit
88781d22ab
6 changed files with 62 additions and 19 deletions
|
@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||
# Note: update this to your new project's name and version
|
||||
project(
|
||||
Greeter
|
||||
VERSION 1.0
|
||||
VERSION 1.1
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
@ -18,6 +18,14 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
|||
)
|
||||
endif()
|
||||
|
||||
# ---- Project settings ----
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS NO)
|
||||
endif()
|
||||
|
||||
# ---- Add dependencies via CPM ----
|
||||
# see https://github.com/TheLartians/CPM.cmake for more info
|
||||
|
||||
|
@ -27,7 +35,18 @@ include(cmake/CPM.cmake)
|
|||
CPMAddPackage(
|
||||
NAME PackageProject.cmake
|
||||
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
|
||||
VERSION 1.4
|
||||
VERSION 1.4.1
|
||||
)
|
||||
|
||||
# NOTE: If fmt is not imported, this is needed to prevent: CMake Error: install(EXPORT
|
||||
# "GreeterTargets" ...) includes target "Greeter" which requires target "fmt" that is not in any
|
||||
# export set. see too https://gitlab.kitware.com/cmake/cmake/-/issues/15415
|
||||
set(FMT_VERSION 7.1.3)
|
||||
CPMAddPackage(
|
||||
NAME fmt
|
||||
GIT_TAG ${FMT_VERSION}
|
||||
GITHUB_REPOSITORY fmtlib/fmt
|
||||
# XXX OPTION "FMT_INSTALL YES"
|
||||
)
|
||||
|
||||
# ---- Add source files ----
|
||||
|
@ -40,17 +59,20 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
|
|||
# ---- Create library ----
|
||||
|
||||
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
|
||||
# target: add_library(Greeter INTERFACE) set_target_properties(Greeter PROPERTIES
|
||||
# INTERFACE_COMPILE_FEATURES cxx_std_17)
|
||||
# target:
|
||||
add_library(Greeter)
|
||||
target_compile_features(Greeter PUBLIC cxx_std_17)
|
||||
|
||||
add_library(Greeter ${headers} ${sources})
|
||||
|
||||
set_target_properties(Greeter PROPERTIES CXX_STANDARD 17)
|
||||
target_sources(Greeter PRIVATE ${headers} ${sources})
|
||||
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||
target_compile_options(Greeter PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
|
||||
if(MSVC)
|
||||
target_compile_options(Greeter PUBLIC /permissive)
|
||||
endif()
|
||||
|
||||
# Link dependencies (if required) target_link_libraries(Greeter PUBLIC cxxopts)
|
||||
# Link dependencies (if required)
|
||||
target_link_libraries(Greeter PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>)
|
||||
# XXX target_link_libraries(Greeter PUBLIC fmt::fmt)
|
||||
|
||||
target_include_directories(
|
||||
Greeter PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
|
@ -72,5 +94,5 @@ packageProject(
|
|||
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
|
||||
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
||||
DEPENDENCIES ""
|
||||
# XXX DEPENDENCIES "fmt ${FMT_VERSION}"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue