@@ -58,17 +58,58 @@ target_compile_definitions(${PROJECT_NAME} INTERFACE
58
58
$< $< BOOL:${OPENSSL_FOUND} > :CPPHTTPLIB_OPENSSL_SUPPORT>
59
59
)
60
60
61
+ # Cmake's find_package search path is different based on the system
62
+ # See https://cmake.org/cmake/help/latest/command/find_package.html for the list
63
+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
64
+ set (_TARGET_INSTALL_CMAKEDIR "${CMAKE_INSTALL_PREFIX} /cmake/${PROJECT_NAME} " )
65
+ else ()
66
+ # On Non-Windows, it should be /usr/lib/cmake/<name>/<name>Config.cmake
67
+ # NOTE: This may or may not work for macOS...
68
+ set (_TARGET_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} " )
69
+ endif ()
70
+
71
+ include (CMakePackageConfigHelpers )
72
+
73
+ # Configures the meta-file httplibConfig.cmake.in to replace variables with paths/values/etc.
74
+ configure_package_config_file ("${PROJECT_NAME} Config.cmake.in"
75
+ "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake"
76
+ INSTALL_DESTINATION "${_TARGET_INSTALL_CMAKEDIR} "
77
+ # Passes the includedir install path
78
+ PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
79
+ # There aren't any components, so don't use the macro
80
+ NO_CHECK_REQUIRED_COMPONENTS_MACRO
81
+ )
61
82
62
- install (TARGETS ${PROJECT_NAME} EXPORT httplibConfig
63
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
64
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
65
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
83
+ # Creates the version file for version-checking with find_package(httplib)
84
+ write_basic_package_version_file ("${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake"
85
+ VERSION ${CMAKE_PROJECT_VERSION}
86
+ # Controls how the version-checking works.
87
+ # AnyNewerVersion just accepts any version >= the target version.
88
+ # If SemVer is instead desired behaviour, use SameMajorVersion
89
+ COMPATIBILITY AnyNewerVersion
90
+ )
66
91
92
+ # Creates the export httplibTargets.cmake
93
+ # This is strictly what holds compilation requirements
94
+ # and linkage information (doesn't find deps though).
95
+ install (TARGETS ${PROJECT_NAME}
96
+ EXPORT httplibTargets
97
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
98
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
99
+ )
67
100
68
- install (EXPORT httplibConfig DESTINATION share/httplib/cmake )
69
101
install (FILES httplib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
70
102
71
- export (TARGETS ${PROJECT_NAME} FILE httplibConfig.cmake )
103
+ install (FILES
104
+ "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake"
105
+ "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake"
106
+ DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
107
+ )
72
108
73
- #add_subdirectory(example)
74
- #add_subdirectory(test)
109
+ # NOTE: This path changes depending on if it's on Windows or Linux
110
+ install (EXPORT httplibTargets
111
+ # Puts the targets into the httplib namespace
112
+ # So this makes httplib::httplib linkable after doing find_package(httplib)
113
+ NAMESPACE ${PROJECT_NAME} ::
114
+ DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
115
+ )
0 commit comments