1- cmake_minimum_required (VERSION 3.14 )
1+ cmake_minimum_required (VERSION 3.25...3.30 )
22project (mylib
33 VERSION 1.0.0
44 DESCRIPTION "Template for C++ library built with CMake"
@@ -14,8 +14,8 @@ include(GNUInstallDirs)
1414string (COMPARE EQUAL "${CMAKE_SOURCE_DIR} " "${CMAKE_CURRENT_SOURCE_DIR} " is_top_level)
1515
1616# MYLIB_SHARED_LIBS option (undefined by default) can be used to force shared/static build
17- option (MYLIB_BUILD_TESTS "Build mylib tests" OFF )
18- option (MYLIB_BUILD_EXAMPLES "Build mylib examples" OFF )
17+ option (MYLIB_BUILD_TESTS "Build mylib tests" ${is_top_level} )
18+ option (MYLIB_BUILD_EXAMPLES "Build mylib examples" ${is_top_level} )
1919option (MYLIB_BUILD_DOCS "Build mylib documentation" OFF )
2020option (MYLIB_INSTALL "Generate target for installing mylib" ${is_top_level} )
2121set_if_undefined(MYLIB_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR} /cmake/mylib" CACHE STRING
@@ -30,6 +30,10 @@ if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
3030 set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
3131endif ()
3232
33+ # Neither of these two are technically needed, but they make the expectation clear
34+ set_if_undefined(CMAKE_CXX_STANDARD 20)
35+ set_if_undefined(CMAKE_CXX_EXTENSIONS FALSE )
36+
3337set_if_undefined(CMAKE_CXX_VISIBILITY_PRESET hidden)
3438set_if_undefined(CMAKE_VISIBILITY_INLINES_HIDDEN ON )
3539
@@ -67,13 +71,22 @@ source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${sources})
6771
6872include (CMakePackageConfigHelpers)
6973
70- target_sources (mylib PRIVATE ${sources} )
74+
75+ target_sources (mylib PRIVATE src/mylib.cpp)
76+ target_sources (mylib PUBLIC FILE_SET HEADERS
77+ BASE_DIRS
78+ ${CMAKE_CURRENT_SOURCE_DIR} /include
79+ ${CMAKE_CURRENT_BINARY_DIR} /include
80+ FILES
81+ ${CMAKE_CURRENT_SOURCE_DIR} /include /mylib/mylib.h
82+ ${CMAKE_CURRENT_SOURCE_DIR} /include /mylib/export.h
83+ ${CMAKE_CURRENT_BINARY_DIR} /include /mylib/${export_file_name} )
7184target_compile_definitions (mylib PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS} >>:MYLIB_STATIC_DEFINE>" )
7285
73- target_include_directories (mylib
74- PUBLIC
75- "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include>"
76- "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} /include>" )
86+ # target_include_directories(mylib
87+ # PUBLIC
88+ # "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
89+ # "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
7790
7891set_target_properties (mylib PROPERTIES
7992 SOVERSION ${PROJECT_VERSION_MAJOR}
@@ -90,13 +103,15 @@ if(MYLIB_INSTALL AND NOT CMAKE_SKIP_INSTALL_RULES)
90103 RUNTIME COMPONENT mylib
91104 LIBRARY COMPONENT mylib NAMELINK_COMPONENT mylib-dev
92105 ARCHIVE COMPONENT mylib-dev
106+ FILE_SET HEADERS
93107 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} " )
94- install (DIRECTORY include /
95- TYPE INCLUDE
96- COMPONENT mylib-dev)
97- install (FILES "${CMAKE_CURRENT_BINARY_DIR} /include/mylib/${export_file_name} "
98- COMPONENT mylib-dev
99- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} /mylib" )
108+
109+ # install(DIRECTORY include/
110+ # TYPE INCLUDE
111+ # COMPONENT mylib-dev)
112+ # install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/mylib/${export_file_name}"
113+ # COMPONENT mylib-dev
114+ # DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mylib")
100115
101116 set (targets_file "mylib-shared-targets.cmake" )
102117
0 commit comments