Debian Codegraph @

third-party/xxhash/cmake_unofficial/CMakeLists.txt

raw
1 # To the extent possible under law, the author(s) have dedicated all
2 # copyright and related and neighboring rights to this software to
3 # the public domain worldwide. This software is distributed without
4 # any warranty.
5 #
6 # For details, see <https://creativecommons.org/publicdomain/zero/1.0/>.
7
8 cmake_minimum_required (VERSION 3.10 FATAL_ERROR)
9
10 set(XXHASH_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
11
12 file(STRINGS "${XXHASH_DIR}/xxhash.h" XXHASH_VERSION_MAJOR REGEX "^#define XXH_VERSION_MAJOR +([0-9]+) *$")
13 string(REGEX REPLACE "^#define XXH_VERSION_MAJOR +([0-9]+) *$" "\\1" XXHASH_VERSION_MAJOR "${XXHASH_VERSION_MAJOR}")
14 file(STRINGS "${XXHASH_DIR}/xxhash.h" XXHASH_VERSION_MINOR REGEX "^#define XXH_VERSION_MINOR +([0-9]+) *$")
15 string(REGEX REPLACE "^#define XXH_VERSION_MINOR +([0-9]+) *$" "\\1" XXHASH_VERSION_MINOR "${XXHASH_VERSION_MINOR}")
16 file(STRINGS "${XXHASH_DIR}/xxhash.h" XXHASH_VERSION_RELEASE REGEX "^#define XXH_VERSION_RELEASE +([0-9]+) *$")
17 string(REGEX REPLACE "^#define XXH_VERSION_RELEASE +([0-9]+) *$" "\\1" XXHASH_VERSION_RELEASE "${XXHASH_VERSION_RELEASE}")
18 set(XXHASH_VERSION_STRING "${XXHASH_VERSION_MAJOR}.${XXHASH_VERSION_MINOR}.${XXHASH_VERSION_RELEASE}")
19 set(XXHASH_LIB_VERSION ${XXHASH_VERSION_STRING})
20 set(XXHASH_LIB_SOVERSION "${XXHASH_VERSION_MAJOR}")
21 mark_as_advanced(XXHASH_VERSION_MAJOR XXHASH_VERSION_MINOR XXHASH_VERSION_RELEASE XXHASH_VERSION_STRING XXHASH_LIB_VERSION XXHASH_LIB_SOVERSION)
22
23 if("${CMAKE_VERSION}" VERSION_LESS "3.13")
24 #message(WARNING "CMake ${CMAKE_VERSION} has no CMP0077 policy: options will erase uncached/untyped normal vars!")
25 else()
26 cmake_policy (SET CMP0077 NEW)
27 endif()
28 cmake_policy (SET CMP0048 NEW)
29 project(xxHash
30 VERSION ${XXHASH_VERSION_STRING}
31 LANGUAGES C)
32
33 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
34 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Project build type" FORCE)
35 set_property(CACHE CMAKE_BUILD_TYPE
36 PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
37 endif()
38 if(NOT CMAKE_CONFIGURATION_TYPES)
39 message(STATUS "xxHash build type: ${CMAKE_BUILD_TYPE}")
40 endif()
41
42 # Enable assert() statements in debug builds
43 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
44 if("${CMAKE_VERSION}" VERSION_LESS "3.12")
45 # add_compile_definitions is not available for older cmake => do nothing
46 else()
47 add_compile_definitions(XXH_DEBUGLEVEL=1)
48 endif()
49 endif()
50
51 option(BUILD_SHARED_LIBS "Build shared library" ON)
52 option(XXHASH_BUILD_XXHSUM "Build the xxhsum binary" ON)
53
54 # If XXHASH is being bundled in another project, we don't want to
55 # install anything. However, we want to let people override this, so
56 # we'll use the XXHASH_BUNDLED_MODE variable to let them do that; just
57 # set it to OFF in your project before you add_subdirectory(xxhash/cmake_unofficial).
58 if(NOT DEFINED XXHASH_BUNDLED_MODE)
59 if("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
60 set(XXHASH_BUNDLED_MODE OFF)
61 else()
62 set(XXHASH_BUNDLED_MODE ON)
63 endif()
64 endif()
65 set(XXHASH_BUNDLED_MODE ${XXHASH_BUNDLED_MODE} CACHE BOOL "" FORCE)
66 mark_as_advanced(XXHASH_BUNDLED_MODE)
67
68 # Allow people to choose whether to build shared or static libraries
69 # via the BUILD_SHARED_LIBS option unless we are in bundled mode, in
70 # which case we always use static libraries.
71 include(CMakeDependentOption)
72 CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON "NOT XXHASH_BUNDLED_MODE" OFF)
73
74 # detect architecture for DISPATCH mode
75 CMAKE_HOST_SYSTEM_INFORMATION(RESULT PLATFORM QUERY OS_PLATFORM)
76 message(STATUS "Architecture: ${PLATFORM}")
77
78 # libxxhash
79 if((DEFINED DISPATCH) AND (DEFINED PLATFORM))
80 # Only support DISPATCH option on x86_64.
81 if(("${PLATFORM}" STREQUAL "x86_64") OR ("${PLATFORM}" STREQUAL "AMD64"))
82 set(XXHSUM_DISPATCH ON)
83 message(STATUS "Enable xxHash dispatch mode")
84 add_library(xxhash "${XXHASH_DIR}/xxh_x86dispatch.c"
85 "${XXHASH_DIR}/xxhash.c"
86 )
87 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXXHSUM_DISPATCH=1")
88 else()
89 add_library(xxhash "${XXHASH_DIR}/xxhash.c")
90 endif()
91 else()
92 add_library(xxhash "${XXHASH_DIR}/xxhash.c")
93 endif()
94 add_library(${PROJECT_NAME}::xxhash ALIAS xxhash)
95
96 target_include_directories(xxhash
97 PUBLIC
98 $<BUILD_INTERFACE:${XXHASH_DIR}>
99 $<INSTALL_INTERFACE:include/>)
100 if (BUILD_SHARED_LIBS)
101 target_compile_definitions(xxhash PUBLIC XXH_EXPORT)
102 endif ()
103 set_target_properties(xxhash PROPERTIES
104 SOVERSION "${XXHASH_LIB_SOVERSION}"
105 VERSION "${XXHASH_VERSION_STRING}")
106
107 if(XXHASH_BUILD_XXHSUM)
108 set(XXHSUM_DIR "${XXHASH_DIR}/cli")
109 # xxhsum
110 set(XXHSUM_SOURCES)
111 if (XXHSUM_DISPATCH)
112 list(APPEND XXHSUM_SOURCES "${XXHASH_DIR}/xxh_x86dispatch.c")
113 endif()
114 list(APPEND XXHSUM_SOURCES "${XXHSUM_DIR}/xxhsum.c"
115 "${XXHSUM_DIR}/xsum_arch.c"
116 "${XXHSUM_DIR}/xsum_os_specific.c"
117 "${XXHSUM_DIR}/xsum_output.c"
118 "${XXHSUM_DIR}/xsum_sanity_check.c"
119 "${XXHSUM_DIR}/xsum_bench.c"
120 )
121 add_executable(xxhsum ${XXHSUM_SOURCES})
122 add_executable(${PROJECT_NAME}::xxhsum ALIAS xxhsum)
123
124 target_link_libraries(xxhsum PRIVATE xxhash)
125 target_include_directories(xxhsum PRIVATE "${XXHASH_DIR}")
126 endif(XXHASH_BUILD_XXHSUM)
127
128 # Extra warning flags
129 include (CheckCCompilerFlag)
130 if (XXHASH_C_FLAGS)
131 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XXHASH_C_FLAGS}")
132 endif()
133
134 if(NOT XXHASH_BUNDLED_MODE)
135 include(GNUInstallDirs)
136
137 install(TARGETS xxhash
138 EXPORT xxHashTargets
139 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
140 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
141 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
142 install(FILES "${XXHASH_DIR}/xxhash.h"
143 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
144 install(FILES "${XXHASH_DIR}/xxh3.h"
145 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
146 if(DISPATCH)
147 install(FILES "${XXHASH_DIR}/xxh_x86dispatch.h"
148 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
149 endif()
150 if(XXHASH_BUILD_XXHSUM)
151 install(TARGETS xxhsum
152 EXPORT xxHashTargets
153 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
154 install(FILES "${XXHSUM_DIR}/xxhsum.1"
155 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
156 endif(XXHASH_BUILD_XXHSUM)
157
158 include(CMakePackageConfigHelpers)
159
160 set(xxHash_VERSION_CONFIG "${PROJECT_BINARY_DIR}/xxHashConfigVersion.cmake")
161 set(xxHash_PROJECT_CONFIG "${PROJECT_BINARY_DIR}/xxHashConfig.cmake")
162 set(xxHash_TARGETS_CONFIG "${PROJECT_BINARY_DIR}/xxHashTargets.cmake")
163 set(xxHash_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/xxHash/")
164 write_basic_package_version_file(${xxHash_VERSION_CONFIG}
165 VERSION ${XXHASH_VERSION_STRING}
166 COMPATIBILITY AnyNewerVersion)
167 configure_package_config_file(
168 ${PROJECT_SOURCE_DIR}/xxHashConfig.cmake.in
169 ${xxHash_PROJECT_CONFIG}
170 INSTALL_DESTINATION ${xxHash_CONFIG_INSTALL_DIR})
171 export(EXPORT xxHashTargets
172 FILE ${xxHash_TARGETS_CONFIG}
173 NAMESPACE ${PROJECT_NAME}::)
174
175 install(FILES ${xxHash_PROJECT_CONFIG} ${xxHash_VERSION_CONFIG}
176 DESTINATION ${xxHash_CONFIG_INSTALL_DIR})
177 install(EXPORT xxHashTargets
178 DESTINATION ${xxHash_CONFIG_INSTALL_DIR}
179 NAMESPACE ${PROJECT_NAME}::)
180
181 # configure and install pkg-config
182 include(JoinPaths.cmake)
183 set(PREFIX ${CMAKE_INSTALL_PREFIX})
184 set(EXECPREFIX "\${prefix}")
185 join_paths(INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
186 join_paths(LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
187 set(VERSION "${XXHASH_VERSION_STRING}")
188 configure_file(${XXHASH_DIR}/libxxhash.pc.in ${CMAKE_BINARY_DIR}/libxxhash.pc @ONLY)
189
190 install(FILES ${CMAKE_BINARY_DIR}/libxxhash.pc
191 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
192
193 endif(NOT XXHASH_BUNDLED_MODE)
194
195 include(CPack)