CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. # CMake build system for Blosc
  2. # ============================
  3. #
  4. # Available options:
  5. #
  6. # BUILD_STATIC: default ON
  7. # build the static version of the Blosc library
  8. # BUILD_SHARED: default ON
  9. # build the shared library version of the Blosc library
  10. # BUILD_TESTS: default ON
  11. # build test programs and generates the "test" target
  12. # BUILD_BENCHMARKS: default ON
  13. # build the benchmark program
  14. # DEACTIVATE_AVX2: default OFF
  15. # do not attempt to build with AVX2 instructions
  16. # DEACTIVATE_LZ4: default OFF
  17. # do not include support for the LZ4 library
  18. # DEACTIVATE_SNAPPY: default OFF
  19. # do not include support for the Snappy library
  20. # DEACTIVATE_ZLIB: default OFF
  21. # do not include support for the Zlib library
  22. # DEACTIVATE_ZSTD: default OFF
  23. # do not include support for the Zstd library
  24. # PREFER_EXTERNAL_LZ4: default OFF
  25. # when found, use the installed LZ4 libs instead of included
  26. # sources
  27. # PREFER_EXTERNAL_SNAPPY: default OFF
  28. # when found, use the installed Snappy libs instead of included
  29. # sources
  30. # PREFER_EXTERNAL_ZLIB: default OFF
  31. # when found, use the installed zlib libs instead of included
  32. # sources
  33. # PREFER_EXTERNAL_ZSTD: default OFF
  34. # when found, use the installed zstd libs instead of included
  35. # sources
  36. # TEST_INCLUDE_BENCH_SHUFFLE_1: default ON
  37. # add a test that runs the benchmark program passing "shuffle" with 1
  38. # thread as second parameter
  39. # TEST_INCLUDE_BENCH_SHUFFLE_N: default ON
  40. # add a test that runs the benchmark program passing "shuffle" with all
  41. # threads as second parameter
  42. # TEST_INCLUDE_BENCH_BITSHUFFLE_1: default ON
  43. # add a test that runs the benchmark program passing "bitshuffle" with 1
  44. # thread as second parameter
  45. # TEST_INCLUDE_BENCH_BITSHUFFLE_N: default ON
  46. # add a test that runs the benchmark program passing "bitshuffle" with
  47. # all threads as second parameter
  48. # TEST_INCLUDE_BENCH_SUITE: default OFF
  49. # add a test that runs the benchmark program passing "suite"
  50. # as first parameter
  51. # TEST_INCLUDE_BENCH_SUITE_PARALLEL: default OFF
  52. # add a test that runs the benchmark program passing "parallel"
  53. # as first parameter
  54. # TEST_INCLUDE_BENCH_HARDSUITE: default OFF
  55. # add a test that runs the benchmark program passing "hardsuite"
  56. # as first parameter
  57. # TEST_INCLUDE_BENCH_EXTREMESUITE: default OFF
  58. # add a test that runs the benchmark program passing "extremesuite"
  59. # as first parameter
  60. # TEST_INCLUDE_BENCH_DEBUGSUITE: default OFF
  61. # add a test that runs the benchmark program passing "debugsuite"
  62. # as first parameter
  63. #
  64. # Components:
  65. #
  66. # LIB: includes blosc.so
  67. # DEV: static includes blosc.a and blosc.h
  68. cmake_minimum_required(VERSION 2.8.12)
  69. if (NOT CMAKE_VERSION VERSION_LESS 3.3)
  70. cmake_policy(SET CMP0063 NEW)
  71. endif()
  72. project(blosc)
  73. # parse the full version numbers from blosc.h
  74. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/blosc/blosc.h _blosc_h_contents)
  75. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MAJOR[ \t]+([0-9]+).*"
  76. "\\1" BLOSC_VERSION_MAJOR ${_blosc_h_contents})
  77. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MINOR[ \t]+([0-9]+).*"
  78. "\\1" BLOSC_VERSION_MINOR ${_blosc_h_contents})
  79. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_RELEASE[ \t]+([0-9]+).*"
  80. "\\1" BLOSC_VERSION_PATCH ${_blosc_h_contents})
  81. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_STRING[ \t]+\"([-0-9A-Za-z.]+)\".*"
  82. "\\1" BLOSC_VERSION_STRING ${_blosc_h_contents})
  83. message("Configuring for Blosc version: " ${BLOSC_VERSION_STRING})
  84. # options
  85. option(BUILD_STATIC
  86. "Build a static version of the blosc library." ON)
  87. option(BUILD_SHARED
  88. "Build a shared library version of the blosc library." ON)
  89. option(BUILD_TESTS
  90. "Build test programs form the blosc compression library" ON)
  91. option(BUILD_BENCHMARKS
  92. "Build benchmark programs form the blosc compression library" ON)
  93. option(DEACTIVATE_AVX2
  94. "Do not attempt to build with AVX2 instructions" OFF)
  95. option(DEACTIVATE_LZ4
  96. "Do not include support for the LZ4 library." OFF)
  97. option(DEACTIVATE_SNAPPY
  98. "Do not include support for the Snappy library." OFF)
  99. option(DEACTIVATE_ZLIB
  100. "Do not include support for the Zlib library." OFF)
  101. option(DEACTIVATE_ZSTD
  102. "Do not include support for the Zstd library." OFF)
  103. option(PREFER_EXTERNAL_LZ4
  104. "Find and use external LZ4 library instead of included sources." OFF)
  105. option(PREFER_EXTERNAL_SNAPPY
  106. "Find and use external Snappy library instead of included sources." OFF)
  107. option(PREFER_EXTERNAL_ZLIB
  108. "Find and use external Zlib library instead of included sources." OFF)
  109. option(PREFER_EXTERNAL_ZSTD
  110. "Find and use external Zstd library instead of included sources." OFF)
  111. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
  112. if(NOT DEACTIVATE_LZ4)
  113. if(PREFER_EXTERNAL_LZ4)
  114. find_package(LZ4)
  115. else()
  116. message(STATUS "Using LZ4 internal sources.")
  117. endif(PREFER_EXTERNAL_LZ4)
  118. # HAVE_LZ4 will be set to true because even if the library is
  119. # not found, we will use the included sources for it
  120. set(HAVE_LZ4 TRUE)
  121. endif(NOT DEACTIVATE_LZ4)
  122. if(NOT DEACTIVATE_SNAPPY)
  123. if(PREFER_EXTERNAL_SNAPPY)
  124. find_package(Snappy)
  125. else()
  126. message(STATUS "Using Snappy internal sources.")
  127. endif(PREFER_EXTERNAL_SNAPPY)
  128. # HAVE_SNAPPY will be set to true because even if the library is not found,
  129. # we will use the included sources for it
  130. set(HAVE_SNAPPY TRUE)
  131. endif(NOT DEACTIVATE_SNAPPY)
  132. if(NOT DEACTIVATE_ZLIB)
  133. # import the ZLIB_ROOT environment variable to help finding the zlib library
  134. if(PREFER_EXTERNAL_ZLIB)
  135. set(ZLIB_ROOT $ENV{ZLIB_ROOT})
  136. find_package(ZLIB)
  137. if (NOT ZLIB_FOUND )
  138. message(STATUS "No zlib found. Using internal sources.")
  139. endif (NOT ZLIB_FOUND )
  140. else()
  141. message(STATUS "Using zlib internal sources.")
  142. endif(PREFER_EXTERNAL_ZLIB)
  143. # HAVE_ZLIB will be set to true because even if the library is not found,
  144. # we will use the included sources for it
  145. set(HAVE_ZLIB TRUE)
  146. endif(NOT DEACTIVATE_ZLIB)
  147. if (NOT DEACTIVATE_ZSTD)
  148. if (PREFER_EXTERNAL_ZSTD)
  149. find_package(Zstd)
  150. else ()
  151. message(STATUS "Using ZSTD internal sources.")
  152. endif (PREFER_EXTERNAL_ZSTD)
  153. # HAVE_ZSTD will be set to true because even if the library is
  154. # not found, we will use the included sources for it
  155. set(HAVE_ZSTD TRUE)
  156. endif (NOT DEACTIVATE_ZSTD)
  157. # create the config.h file
  158. configure_file ("blosc/config.h.in" "blosc/config.h" )
  159. # now make sure that you set the build directory on your "Include" path when compiling
  160. include_directories("${PROJECT_BINARY_DIR}/blosc/")
  161. # If the build type is not set, default to Release.
  162. set(BLOSC_DEFAULT_BUILD_TYPE Release)
  163. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  164. message(STATUS "No build type specified. Defaulting to '${BLOSC_DEFAULT_BUILD_TYPE}'.")
  165. set(CMAKE_BUILD_TYPE ${BLOSC_DEFAULT_BUILD_TYPE} CACHE STRING
  166. "Choose the type of build." FORCE)
  167. # Set the possible values of build type for cmake-gui
  168. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  169. "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  170. endif()
  171. if(APPLE)
  172. # enable @rpath in the install name for any shared library being built. See #175.
  173. set(CMAKE_MACOSX_RPATH TRUE)
  174. endif()
  175. # Based on the target system's processor and the compiler being used,
  176. # set build variables indicating which hardware features can be targeted
  177. # by the compiler. Note we DO NOT check which hardware features are supported
  178. # by this (the host) system, because we want to be able to support compiling
  179. # for newer hardware on older machines as well as cross-compilation.
  180. message(STATUS "Building for system processor ${CMAKE_SYSTEM_PROCESSOR}")
  181. if(CMAKE_SYSTEM_PROCESSOR STREQUAL i386 OR
  182. CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR
  183. CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR
  184. CMAKE_SYSTEM_PROCESSOR STREQUAL amd64 OR
  185. CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)
  186. if(CMAKE_C_COMPILER_ID STREQUAL GNU)
  187. # We need C99 (GNU99 more exactly)
  188. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  189. set(COMPILER_SUPPORT_SSE2 TRUE)
  190. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.7 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.7)
  191. set(COMPILER_SUPPORT_AVX2 TRUE)
  192. else()
  193. set(COMPILER_SUPPORT_AVX2 FALSE)
  194. endif()
  195. elseif(CMAKE_C_COMPILER_ID STREQUAL Clang)
  196. set(COMPILER_SUPPORT_SSE2 TRUE)
  197. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.2 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.2)
  198. set(COMPILER_SUPPORT_AVX2 TRUE)
  199. else()
  200. set(COMPILER_SUPPORT_AVX2 FALSE)
  201. endif()
  202. elseif(CMAKE_C_COMPILER_ID STREQUAL Intel)
  203. set(COMPILER_SUPPORT_SSE2 TRUE)
  204. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0)
  205. # icc (ICC) 15.0.3 does not work compiling AVX2 code
  206. # (perhaps my machine does not have AVX2 and the compiler
  207. # cannot generate code for that?)
  208. set(COMPILER_SUPPORT_AVX2 FALSE)
  209. else()
  210. set(COMPILER_SUPPORT_AVX2 FALSE)
  211. endif()
  212. elseif(MSVC)
  213. set(COMPILER_SUPPORT_SSE2 TRUE)
  214. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 18.00.30501 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 18.00.30501)
  215. set(COMPILER_SUPPORT_AVX2 TRUE)
  216. else()
  217. set(COMPILER_SUPPORT_AVX2 FALSE)
  218. endif()
  219. else()
  220. set(COMPILER_SUPPORT_SSE2 FALSE)
  221. set(COMPILER_SUPPORT_AVX2 FALSE)
  222. # Unrecognized compiler. Emit a warning message to let the user know hardware-acceleration won't be available.
  223. message(WARNING "Unable to determine which ${CMAKE_SYSTEM_PROCESSOR} hardware features are supported by the C compiler (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}).")
  224. endif()
  225. else()
  226. # If the target system processor isn't recognized, emit a warning message to alert the user
  227. # that hardware-acceleration support won't be available but allow configuration to proceed.
  228. message(WARNING "Unrecognized system processor ${CMAKE_SYSTEM_PROCESSOR}. Cannot determine which hardware features (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}) supports, so hardware-accelerated implementations will not be available.")
  229. endif()
  230. # disable AVX2 if specified
  231. if(DEACTIVATE_AVX2)
  232. set(COMPILER_SUPPORT_AVX2 FALSE)
  233. endif()
  234. # flags
  235. # Set -Wall and other useful warning flags.
  236. if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  237. add_compile_options(-Wall -Wwrite-strings -Wno-unused-function)
  238. endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  239. # @NOTE: -O3 is enabled in Release mode (CMAKE_BUILD_TYPE="Release")
  240. # Set the "-msse2" build flag if supported.
  241. if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  242. if(COMPILER_SUPPORT_SSE2)
  243. add_compile_options(-msse2)
  244. endif(COMPILER_SUPPORT_SSE2)
  245. endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  246. if(MSVC)
  247. if(NOT CMAKE_C_FLAGS)
  248. set(CMAKE_C_FLAGS "/Ox" CACHE STRING "C flags." FORCE)
  249. endif(NOT CMAKE_C_FLAGS)
  250. # Turn off misguided "secure CRT" warnings in MSVC.
  251. # Microsoft wants people to use the MS-specific <function>_s
  252. # versions of certain C functions but this is difficult to do
  253. # in platform-independent code.
  254. add_definitions( -D_CRT_SECURE_NO_WARNINGS )
  255. endif(MSVC)
  256. if(WIN32)
  257. # For some supporting headers
  258. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/blosc")
  259. endif(WIN32)
  260. if(HAIKU)
  261. # Haiku have posix_memalign, required by test_common.h
  262. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200112L")
  263. endif(HAIKU)
  264. if (NOT DEFINED BLOSC_IS_SUBPROJECT)
  265. if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
  266. set (BLOSC_IS_SUBPROJECT FALSE)
  267. else ()
  268. set (BLOSC_IS_SUBPROJECT TRUE)
  269. message(STATUS "Detected that BLOSC is used a subproject.")
  270. endif ()
  271. endif ()
  272. if (NOT DEFINED BLOSC_INSTALL)
  273. if (BLOSC_IS_SUBPROJECT)
  274. set(BLOSC_INSTALL FALSE)
  275. else()
  276. set(BLOSC_INSTALL TRUE)
  277. endif()
  278. endif()
  279. # subdirectories
  280. add_subdirectory(blosc)
  281. if(BUILD_TESTS)
  282. enable_testing()
  283. add_subdirectory(tests)
  284. add_subdirectory(compat)
  285. endif(BUILD_TESTS)
  286. if(BUILD_BENCHMARKS)
  287. add_subdirectory(bench)
  288. endif(BUILD_BENCHMARKS)
  289. # uninstall target
  290. if (BLOSC_INSTALL)
  291. configure_file(
  292. "${CMAKE_CURRENT_SOURCE_DIR}/blosc.pc.in"
  293. "${CMAKE_CURRENT_BINARY_DIR}/blosc.pc"
  294. @ONLY)
  295. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/blosc.pc"
  296. DESTINATION lib/pkgconfig COMPONENT DEV)
  297. configure_file(
  298. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  299. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  300. IMMEDIATE @ONLY)
  301. add_custom_target(uninstall
  302. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  303. endif()
  304. # packaging
  305. if (NOT BLOSC_IS_SUBPROJECT)
  306. include(InstallRequiredSystemLibraries)
  307. set(CPACK_GENERATOR TGZ ZIP)
  308. set(CPACK_SOURCE_GENERATOR TGZ ZIP)
  309. set(CPACK_PACKAGE_VERSION_MAJOR ${BLOSC_VERSION_MAJOR})
  310. set(CPACK_PACKAGE_VERSION_MINOR ${BLOSC_VERSION_MINOR})
  311. set(CPACK_PACKAGE_VERSION_PATCH ${BLOSC_VERSION_PATCH})
  312. set(CPACK_PACKAGE_VERSION ${BLOSC_STRING_VERSION})
  313. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  314. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  315. "A blocking, shuffling and lossless compression library")
  316. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSES/BLOSC.txt")
  317. set(CPACK_SOURCE_IGNORE_FILES "/build.*;.*~;\\\\.git.*;\\\\.DS_Store")
  318. set(CPACK_STRIP_FILES TRUE)
  319. set(CPACK_SOURCE_STRIP_FILES TRUE)
  320. include(CPack)
  321. endif()