@@ -71,11 +71,42 @@ install(TARGETS roaring
7171 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
7272 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
7373)
74- install (EXPORT roaring-config
75- FILE roaring-config.cmake
76- NAMESPACE roaring::
77- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/roaring
78- )
74+
75+ include (CMakePackageConfigHelpers )
76+
77+ # Set up both the build and install trees as suitable for find_package calls.
78+ # Configuring the build tree as well as the install tree makes it much easier
79+ # to test other libraries against custom builds of CRoaring by pointing
80+ # CMAKE_PREFIX_PATH or equivalent directly at the build directory of CRoaring.
81+ foreach (tree_type BUILD INSTALL)
82+ if (tree_type STREQUAL "BUILD" )
83+ set (install_location "." )
84+ else ()
85+ set (install_location "${CMAKE_INSTALL_LIBDIR} /cmake/roaring" )
86+ endif ()
87+
88+ set (build_location "${PROJECT_BINARY_DIR} /${install_location} " )
89+ write_basic_package_version_file (
90+ "${build_location} /roaring-config-version.cmake"
91+ VERSION ${ROARING_LIB_VERSION}
92+ COMPATIBILITY SameMajorVersion )
93+ configure_package_config_file ("${CMAKE_SOURCE_DIR} /cmake/config.cmake.in"
94+ "${build_location} /roaring-config.cmake"
95+ INSTALL_DESTINATION "${install_location} " )
96+
97+ if (tree_type STREQUAL "BUILD" )
98+ export (EXPORT roaring-config
99+ FILE "${build_location} /roaring-targets.cmake"
100+ NAMESPACE roaring:: )
101+
102+ else ()
103+ install (DIRECTORY "${build_location} /" DESTINATION "${install_location} " )
104+ install (EXPORT roaring-config
105+ DESTINATION "${install_location} "
106+ FILE "roaring-targets.cmake"
107+ NAMESPACE roaring::)
108+ endif ()
109+ endforeach ()
79110
80111if (NOT MSVC )
81112## We output the library at the root of the current directory where cmake is invoked
@@ -112,4 +143,4 @@ if(ROARING_SANITIZE_THREADS)
112143 message (STATUS "Enabling thread sanitizer" )
113144 target_compile_options (roaring PUBLIC -fsanitize=thread -fno-sanitize-recover=all )
114145 target_link_libraries (roaring PUBLIC -fsanitize=thread -fno-sanitize-recover=all )
115- endif ()
146+ endif ()
0 commit comments