@@ -32,110 +32,88 @@ include(cmake/CPM.cmake)
32
32
CPMAddPackage(
33
33
NAME PackageProject.cmake
34
34
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
35
- VERSION 1.5.0
35
+ VERSION 1.5.1
36
36
)
37
37
38
- CPMAddPackage(
39
- NAME fmt
40
- GIT_TAG 7.1.3
41
- GITHUB_REPOSITORY fmtlib/fmt # to get an installable target
42
- OPTIONS "FMT_INSTALL YES"
43
- )
38
+ option (COMPONENT_TARGETS_ENABLED "Install multiple cmake config target files" NO )
39
+ set (PROJECT_NAMESPACE ${PROJECT_NAME} )
40
+ set (NAMESPACE_HEADER_LOCATION ${CMAKE_CURRENT_LIST_DIR} /include )
41
+ string (TOLOWER ${PROJECT_NAMESPACE} PROJECT_HEADER_LOCATION)
44
42
45
- set (COMPONET_TARGETS_ENABLED YES )
46
- set (namespace ${PROJECT_NAME} )
47
- if (DEFINED COMPONET_TARGETS_ENABLED)
48
- message (STATUS "Install only 1 cmake Component ${namespace} Targets.cmake config file" )
43
+ if (NOT COMPONENT_TARGETS_ENABLED)
44
+ message (STATUS "Install only 1 cmake config target ${PROJECT_NAMESPACE} Targets.cmake file" )
45
+ endif ()
49
46
50
- add_subdirectory (source /Addition)
51
- add_subdirectory (source /SquareRoot)
47
+ # ---- Add components libraries here ----
52
48
53
- # NO! include(source/CMakeLists.txt)
49
+ add_subdirectory (source /Addition)
50
+ add_subdirectory (source /SquareRoot)
51
+ add_subdirectory (source /MathFunctions)
54
52
55
- include (CMakePackageConfigHelpers)
53
+ # ---------------------------------------
56
54
57
- # generate the version file for the config file
58
- write_basic_package_version_file(
59
- ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfigVersion.cmake
60
- VERSION ${PROJECT_VERSION}
61
- COMPATIBILITY SameMajorVersion
62
- )
55
+ include (GenerateExportHeader)
63
56
64
- # create config file
65
- configure_package_config_file(
66
- ${CMAKE_CURRENT_SOURCE_DIR} /Config.cmake.in
67
- ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfig.cmake
68
- INSTALL_DESTINATION lib/cmake/MathFunctions
69
- )
57
+ # Note: depends on target MathFunctions! CK
58
+ string (TOLOWER ${PROJECT_NAME} /${PROJECT_NAMESPACE} _export.h EXPORT_HEADER_LOCATION)
70
59
71
- # install config files
72
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfig.cmake
73
- ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfigVersion.cmake
74
- DESTINATION lib/cmake/MathFunctions
75
- )
76
-
77
- # generate the export targets for the build tree. Note: This needs to be done after the all
78
- # install(TARGETS ...) commands!
79
- export (
80
- EXPORT MathFunctionsTargets
81
- FILE ${CMAKE_CURRENT_BINARY_DIR} /cmake/MathFunctionsTargets.cmake
82
- NAMESPACE MathFunctions::
83
- )
84
- else ()
85
- # ---- Add source files ----
86
-
87
- # Note: globbing sources is considered bad practice as CMake's generators may not detect new files
88
- # automatically. Keep that in mind when changing files, or explicitly mention them here.
89
- file (GLOB_RECURSE headers CONFIGURE_DEPENDS include /*.h)
90
- file (GLOB_RECURSE sources CONFIGURE_DEPENDS source /*.cxx)
91
-
92
- # ---- Create library ----
60
+ # Note: need to generate at source tree! CK
61
+ generate_export_header(
62
+ ${PROJECT_NAMESPACE} EXPORT_FILE_NAME ${CMAKE_CURRENT_LIST_DIR} /include /${EXPORT_HEADER_LOCATION}
63
+ )
93
64
94
- # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
95
- # target! EITHER: add_library(MathFunctions INTERFACE) OR:
96
- add_library (MathFunctions ${headers} ${sources} )
97
- set_target_properties (MathFunctions PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD} )
65
+ # install generated header files
66
+ install (
67
+ DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /include /${PROJECT_HEADER_LOCATION}
68
+ TYPE INCLUDE # or: DESTINATION include/${PROJECT_NAMESPACE}
69
+ FILES_MATCHING
70
+ PATTERN "*.h"
71
+ )
98
72
99
- # for SameMajorVersion upgrade stategie
100
- set_target_properties (MathFunctions PROPERTIES SOVERSION 1 VERSION ${PROJECT_VERSION} )
73
+ # install source tree header files
74
+ install (
75
+ DIRECTORY include /${PROJECT_HEADER_LOCATION}
76
+ TYPE INCLUDE # or: DESTINATION include/${PROJECT_NAMESPACE}
77
+ FILES_MATCHING
78
+ PATTERN "*.h"
79
+ )
101
80
102
- # being a cross-platform target, we enforce standards conformance on MSVC:
103
- target_compile_options (MathFunctions PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive>" )
81
+ # Note: This needs to be done after all install(TARGETS ...) commands!
82
+ # generate and install export targets file
83
+ install (
84
+ EXPORT ${PROJECT_NAMESPACE} Targets
85
+ FILE ${PROJECT_NAMESPACE} Targets.cmake
86
+ NAMESPACE ${PROJECT_NAMESPACE} ::
87
+ DESTINATION lib/cmake/${PROJECT_NAMESPACE}
88
+ )
104
89
105
- # Link dependencies EITHER:
106
- target_link_libraries (MathFunctions PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>)
107
- # OR: target_link_libraries(MathFunctions PUBLIC fmt::fmt)
90
+ include (CMakePackageConfigHelpers)
108
91
109
- set (INCLUDE_INSTALL_DIR include /${PROJECT_NAME} -${PROJECT_VERSION} )
110
- target_include_directories (
111
- MathFunctions BEFORE PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
112
- $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR} >
113
- )
92
+ # generate the version file for the config file
93
+ write_basic_package_version_file(
94
+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAMESPACE} ConfigVersion.cmake
95
+ VERSION ${PROJECT_VERSION}
96
+ COMPATIBILITY SameMajorVersion
97
+ )
114
98
115
- # ---- Create an installable target ----
116
- # this allows users to install and find the library via `find_package()`.
99
+ # create config file
100
+ configure_package_config_file(
101
+ ${CMAKE_CURRENT_SOURCE_DIR} /Config.cmake.in
102
+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAMESPACE} Config.cmake
103
+ INSTALL_DESTINATION lib/cmake/${PROJECT_NAMESPACE}
104
+ NO_CHECK_REQUIRED_COMPONENTS_MACRO
105
+ )
117
106
118
- # the location where the project's version header will be placed should match the project's
119
- # regular header paths
120
- string (TOLOWER ${PROJECT_NAME} /version .h VERSION_HEADER_LOCATION)
121
- string (TOLOWER ${PROJECT_NAME} /MathFunctions_export.h EXPORT_HEADER_LOCATION)
107
+ # generate the export targets for the build tree. Note: The file created by this command is specific
108
+ # to the build tree and should never be installed!
109
+ export (
110
+ EXPORT ${PROJECT_NAMESPACE} Targets
111
+ FILE ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAMESPACE} Targets.cmake
112
+ NAMESPACE ${PROJECT_NAMESPACE} ::
113
+ )
122
114
123
- # TODO: should be done in packageProject()
124
- include (GenerateExportHeader)
125
- generate_export_header(
126
- ${PROJECT_NAME} EXPORT_FILE_NAME PackageProjectInclude/${EXPORT_HEADER_LOCATION}
127
- )
128
- # Note: the export header will be installed while installing the version header! CK
129
-
130
- packageProject(
131
- NAME ${PROJECT_NAME}
132
- VERSION ${PROJECT_VERSION}
133
- NAMESPACE ${PROJECT_NAME}
134
- BINARY_DIR ${PROJECT_BINARY_DIR}
135
- INCLUDE_DIR ${PROJECT_SOURCE_DIR} /include
136
- INCLUDE_DESTINATION ${INCLUDE_INSTALL_DIR}
137
- VERSION_HEADER ${VERSION_HEADER_LOCATION}
138
- COMPATIBILITY SameMajorVersion
139
- # Note: not needed DEPENDENCIES "fmt 7.1.3"
140
- )
141
- endif ()
115
+ # install cmake project config files
116
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfig.cmake
117
+ ${CMAKE_CURRENT_BINARY_DIR} /MathFunctionsConfigVersion.cmake
118
+ DESTINATION lib/cmake/${PROJECT_NAMESPACE}
119
+ )
0 commit comments