@@ -6,7 +6,11 @@ if (POLICY CMP0141)
6
6
set (CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>" )
7
7
endif ()
8
8
9
- project ("MyLibrary" )
9
+ set (MYLIBRARY_INCLUDE_DIR
10
+ $< BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include>
11
+ $< INSTALL_INTERFACE:include> )
12
+
13
+ project ("MyLibrary" )
10
14
set (PROJECT_VERSION_MAJOR 1 )
11
15
set (PROJECT_VERSION_MINOR 0 )
12
16
set (PROJECT_VERSION_PATCH 0 )
@@ -19,6 +23,7 @@ string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" MYLIBRA
19
23
option (MYLIBRARY_BUILD_EXAMPLES "Build the ${PROJECT_NAME} example programs" ${MYLIBRARY_STANDALONE} )
20
24
option (MYLIBRARY_BUILD_TESTS "Build the ${PROJECT_NAME} test programs" ${MYLIBRARY_STANDALONE} )
21
25
option (MYLIBRARY_BUILD_DOCS "Build the ${PROJECT_NAME} HTML documentation." ON )
26
+ option (MYLIBRARY_INSTALL "Generate the ${PROJECT_NAME} installation target" ON )
22
27
23
28
# Add CMake modules to this project
24
29
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
@@ -28,21 +33,29 @@ add_library(${PROJECT_NAME})
28
33
add_subdirectory ("src" )
29
34
30
35
# Add template header files (.hpp) to this project
31
- file (GLOB_RECURSE TEMPLATE_FILES CONFIGURE_DEPENDS "include /*.hpp" )
36
+ file (GLOB_RECURSE TEMPLATE_FILES CONFIGURE_DEPENDS "${MYLIBRARY_INCLUDE_DIR} /*.hpp" )
32
37
target_sources (${PROJECT_NAME} PUBLIC ${TEMPLATE_FILES} )
33
38
34
39
# Add normal header files (.h) to this project
35
- file (GLOB_RECURSE HEADER_FILES CONFIGURE_DEPENDS "include /*.h" )
40
+ file (GLOB_RECURSE HEADER_FILES CONFIGURE_DEPENDS "${MYLIBRARY_INCLUDE_DIR} /*.h" )
36
41
target_sources (${PROJECT_NAME} PUBLIC ${HEADER_FILES} )
37
- target_include_directories (${PROJECT_NAME} PUBLIC "include" )
42
+ target_include_directories (${PROJECT_NAME} PUBLIC ${MYLIBRARY_INCLUDE_DIR} )
38
43
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_20 )
39
44
40
45
# Fix CMake Issue #18837
41
46
# https://gitlab.kitware.com/cmake/cmake/-/issues/18837
47
+ # This is required for making the standard conforming __cplusplus macro the correct value
42
48
if ((MSVC ) AND (MSVC_VERSION GREATER_EQUAL 1914 ))
43
49
target_compile_options (${PROJECT_NAME} PUBLIC "/Zc:__cplusplus" )
44
50
endif ()
45
51
52
+ # Fix CMake Issue #17068
53
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/17068
54
+ # This is required for making some standard conforming features compilable
55
+ if ((MSVC ) AND (MSVC_VERSION GREATER_EQUAL 1912 ))
56
+ target_compile_options (${PROJECT_NAME} PUBLIC "/permissive-" )
57
+ endif ()
58
+
46
59
# Add example programs to this project.
47
60
if (MYLIBRARY_BUILD_EXAMPLES )
48
61
add_subdirectory ("examples" )
@@ -58,4 +71,39 @@ endif()
58
71
# Add documentation to this project.
59
72
if (MYLIBRARY_BUILD_DOCS )
60
73
add_subdirectory ("docs" )
74
+ endif ()
75
+
76
+ # Add installation target to this project.
77
+ if (MYLIBRARY_INSTALL )
78
+ install (DIRECTORY ${MYLIBRARY_INCLUDE_DIR}
79
+ DESTINATION ${CMAKE_INSTALL_PREFIX}
80
+ FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" )
81
+
82
+ set (MYLIBRARY_EXPORT_TARGETS "${PROJECT_NAME} Targets" )
83
+ set (MYLIBRARY_EXPORT_TARGETS_FILE "${MYLIBRARY_EXPORT_TARGETS} .cmake" )
84
+ set (MYLIBRARY_EXPORT_PATH "${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} " )
85
+ install (TARGETS ${PROJECT_NAME}
86
+ EXPORT ${MYLIBRARY_EXPORT_TARGETS} )
87
+ install (EXPORT ${MYLIBRARY_EXPORT_TARGETS}
88
+ FILE ${MYLIBRARY_EXPORT_TARGETS_FILE}
89
+ NAMESPACE ${PROJECT_NAME} ::
90
+ DESTINATION ${MYLIBRARY_EXPORT_PATH} )
91
+
92
+ set (MYLIBRARY_EXPORT_CONFIGS_FILE "${PROJECT_NAME} Config.cmake" )
93
+ include (CMakePackageConfigHelpers )
94
+ configure_package_config_file (
95
+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake/${MYLIBRARY_EXPORT_CONFIGS_FILE} "
96
+ "${CMAKE_CURRENT_BINARY_DIR} /${MYLIBRARY_EXPORT_CONFIGS_FILE} "
97
+ INSTALL_DESTINATION ${MYLIBRARY_EXPORT_PATH} )
98
+
99
+ set (MYLIBRARY_EXPORT_CONFIGS_VERSION_FILE "${PROJECT_NAME} ConfigVersion.cmake" )
100
+ write_basic_package_version_file (
101
+ ${MYLIBRARY_EXPORT_CONFIGS_VERSION_FILE}
102
+ VERSION ${PACKAGE_VERSION}
103
+ COMPATIBILITY SameMajorVersion )
104
+
105
+ install (FILES
106
+ "${CMAKE_CURRENT_BINARY_DIR} /${MYLIBRARY_EXPORT_CONFIGS_FILE} "
107
+ "${CMAKE_CURRENT_BINARY_DIR} /${MYLIBRARY_EXPORT_CONFIGS_VERSION_FILE} "
108
+ DESTINATION ${MYLIBRARY_EXPORT_PATH} )
61
109
endif ()
0 commit comments