CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_TESTS: default ON
  9. # build test programs and generates the "test" target
  10. # BUILD_BENCHMARKS: default ON
  11. # build the benchmark program
  12. # DEACTIVATE_AVX2: default OFF
  13. # do not attempt to build with AVX2 instructions
  14. # DEACTIVATE_LZ4: default OFF
  15. # do not include support for the LZ4 library
  16. # DEACTIVATE_SNAPPY: default OFF
  17. # do not include support for the Snappy library
  18. # DEACTIVATE_ZLIB: default OFF
  19. # do not include support for the Zlib library
  20. # PREFER_EXTERNAL_LZ4: default OFF
  21. # when found, use the installed LZ4 libs instead of included
  22. # sources
  23. # PREFER_EXTERNAL_SNAPPY: default ON
  24. # when found, use the installed Snappy libs instead of included
  25. # sources
  26. # PREFER_EXTERNAL_ZLIB: default ON
  27. # when found, use the installed zlib libs instead of included
  28. # sources
  29. # TEST_INCLUDE_BENCH_SHUFFLE_1: default ON
  30. # add a test that runs the benchmark program passing "shuffle" with 1
  31. # thread as second parameter
  32. # TEST_INCLUDE_BENCH_SHUFFLE_N: default ON
  33. # add a test that runs the benchmark program passing "shuffle" with all
  34. # threads as second parameter
  35. # TEST_INCLUDE_BENCH_BITSHUFFLE_1: default ON
  36. # add a test that runs the benchmark program passing "bitshuffle" with 1
  37. # thread as second parameter
  38. # TEST_INCLUDE_BENCH_BITSHUFFLE_N: default ON
  39. # add a test that runs the benchmark program passing "bitshuffle" with
  40. # all threads as second parameter
  41. # TEST_INCLUDE_BENCH_SUITE: default OFF
  42. # add a test that runs the benchmark program passing "suite"
  43. # as first parameter
  44. # TEST_INCLUDE_BENCH_SUITE_PARALLEL: default OFF
  45. # add a test that runs the benchmark program passing "parallel"
  46. # as first parameter
  47. # TEST_INCLUDE_BENCH_HARDSUITE: default OFF
  48. # add a test that runs the benchmark program passing "hardsuite"
  49. # as first parameter
  50. # TEST_INCLUDE_BENCH_EXTREMESUITE: default OFF
  51. # add a test that runs the benchmark program passing "extremesuite"
  52. # as first parameter
  53. # TEST_INCLUDE_BENCH_DEBUGSUITE: default OFF
  54. # add a test that runs the benchmark program passing "debugsuite"
  55. # as first parameter
  56. #
  57. # Components:
  58. #
  59. # LIB: includes blosc.so
  60. # DEV: static includes blosc.a and blosc.h
  61. cmake_minimum_required(VERSION 2.8.10)
  62. project(blosc)
  63. # parse the full version numbers from blosc.h
  64. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/blosc/blosc.h _blosc_h_contents)
  65. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MAJOR[ \t]+([0-9]+).*"
  66. "\\1" BLOSC_VERSION_MAJOR ${_blosc_h_contents})
  67. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MINOR[ \t]+([0-9]+).*"
  68. "\\1" BLOSC_VERSION_MINOR ${_blosc_h_contents})
  69. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_RELEASE[ \t]+([0-9]+).*"
  70. "\\1" BLOSC_VERSION_PATCH ${_blosc_h_contents})
  71. string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_STRING[ \t]+\"([-0-9A-Za-z.]+)\".*"
  72. "\\1" BLOSC_VERSION_STRING ${_blosc_h_contents})
  73. message("Configuring for Blosc version: " ${BLOSC_VERSION_STRING})
  74. # options
  75. option(BUILD_STATIC
  76. "Build a static version of the blosc library." ON)
  77. option(BUILD_TESTS
  78. "Build test programs form the blosc compression library" ON)
  79. option(BUILD_BENCHMARKS
  80. "Build benchmark programs form the blosc compression library" ON)
  81. option(DEACTIVATE_AVX2
  82. "Do not attempt to build with AVX2 instructions" OFF)
  83. option(DEACTIVATE_LZ4
  84. "Do not include support for the LZ4 library." OFF)
  85. option(DEACTIVATE_SNAPPY
  86. "Do not include support for the SNAPPY library." OFF)
  87. option(DEACTIVATE_ZLIB
  88. "Do not include support for the ZLIB library." OFF)
  89. option(PREFER_EXTERNAL_LZ4
  90. "Find and use external LZ4 library instead of included sources." OFF)
  91. option(PREFER_EXTERNAL_SNAPPY
  92. "Find and use external Snappy library instead of included sources." ON)
  93. option(PREFER_EXTERNAL_ZLIB
  94. "Find and use external zlib library instead of included sources." ON)
  95. set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
  96. if(NOT DEACTIVATE_LZ4)
  97. if(PREFER_EXTERNAL_LZ4)
  98. find_package(LZ4)
  99. else()
  100. message(STATUS "Using LZ4 internal sources.")
  101. endif(PREFER_EXTERNAL_LZ4)
  102. # HAVE_LZ4 will be set to true because even if the library is
  103. # not found, we will use the included sources for it
  104. set(HAVE_LZ4 TRUE)
  105. endif(NOT DEACTIVATE_LZ4)
  106. if(NOT DEACTIVATE_SNAPPY)
  107. if(PREFER_EXTERNAL_SNAPPY)
  108. find_package(Snappy)
  109. else()
  110. message(STATUS "Using Snappy internal sources.")
  111. endif(PREFER_EXTERNAL_SNAPPY)
  112. # HAVE_SNAPPY will be set to true because even if the library is not found,
  113. # we will use the included sources for it
  114. set(HAVE_SNAPPY TRUE)
  115. endif(NOT DEACTIVATE_SNAPPY)
  116. if(NOT DEACTIVATE_ZLIB)
  117. # import the ZLIB_ROOT environment variable to help finding the zlib library
  118. if(PREFER_EXTERNAL_ZLIB)
  119. set(ZLIB_ROOT $ENV{ZLIB_ROOT})
  120. find_package(ZLIB)
  121. if (NOT ZLIB_FOUND )
  122. message(STATUS "No zlib found. Using internal sources.")
  123. endif (NOT ZLIB_FOUND )
  124. else()
  125. message(STATUS "Using zlib internal sources.")
  126. endif(PREFER_EXTERNAL_ZLIB)
  127. # HAVE_ZLIB will be set to true because even if the library is not found,
  128. # we will use the included sources for it
  129. set(HAVE_ZLIB TRUE)
  130. endif(NOT DEACTIVATE_ZLIB)
  131. # create the config.h file
  132. configure_file ("blosc/config.h.in" "blosc/config.h" )
  133. # now make sure that you set the build directory on your "Include" path when compiling
  134. include_directories("${PROJECT_BINARY_DIR}/blosc/")
  135. # If the build type is not set, default to Release.
  136. set(BLOSC_DEFAULT_BUILD_TYPE Release)
  137. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  138. message(STATUS "No build type specified. Defaulting to '${BLOSC_DEFAULT_BUILD_TYPE}'.")
  139. set(CMAKE_BUILD_TYPE ${BLOSC_DEFAULT_BUILD_TYPE} CACHE STRING
  140. "Choose the type of build." FORCE)
  141. # Set the possible values of build type for cmake-gui
  142. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  143. "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  144. endif()
  145. # Based on the target system's processor and the compiler being used,
  146. # set build variables indicating which hardware features can be targeted
  147. # by the compiler. Note we DO NOT check which hardware features are supported
  148. # by this (the host) system, because we want to be able to support compiling
  149. # for newer hardware on older machines as well as cross-compilation.
  150. message(STATUS "Building for system processor ${CMAKE_SYSTEM_PROCESSOR}")
  151. if(CMAKE_SYSTEM_PROCESSOR STREQUAL i386 OR
  152. CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR
  153. CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR
  154. CMAKE_SYSTEM_PROCESSOR STREQUAL amd64 OR
  155. CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)
  156. if(CMAKE_C_COMPILER_ID STREQUAL GNU)
  157. set(COMPILER_SUPPORT_SSE2 TRUE)
  158. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.7 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.7)
  159. set(COMPILER_SUPPORT_AVX2 TRUE)
  160. else()
  161. set(COMPILER_SUPPORT_AVX2 FALSE)
  162. endif()
  163. elseif(CMAKE_C_COMPILER_ID STREQUAL Clang)
  164. set(COMPILER_SUPPORT_SSE2 TRUE)
  165. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.2 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.2)
  166. set(COMPILER_SUPPORT_AVX2 TRUE)
  167. else()
  168. set(COMPILER_SUPPORT_AVX2 FALSE)
  169. endif()
  170. elseif(CMAKE_C_COMPILER_ID STREQUAL Intel)
  171. set(COMPILER_SUPPORT_SSE2 TRUE)
  172. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0)
  173. # icc (ICC) 15.0.3 does not work compiling AVX2 code
  174. # (perhaps my machine does not have AVX2 and the compiler
  175. # cannot generate code for that?)
  176. set(COMPILER_SUPPORT_AVX2 FALSE)
  177. else()
  178. set(COMPILER_SUPPORT_AVX2 FALSE)
  179. endif()
  180. elseif(MSVC)
  181. set(COMPILER_SUPPORT_SSE2 TRUE)
  182. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 18.00.30501 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 18.00.30501)
  183. set(COMPILER_SUPPORT_AVX2 TRUE)
  184. else()
  185. set(COMPILER_SUPPORT_AVX2 FALSE)
  186. endif()
  187. else()
  188. set(COMPILER_SUPPORT_SSE2 FALSE)
  189. set(COMPILER_SUPPORT_AVX2 FALSE)
  190. # Unrecognized compiler. Emit a warning message to let the user know hardware-acceleration won't be available.
  191. 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}).")
  192. endif()
  193. else()
  194. # If the target system processor isn't recognized, emit a warning message to alert the user
  195. # that hardware-acceleration support won't be available but allow configuration to proceed.
  196. 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.")
  197. endif()
  198. # disable AVX2 if specified
  199. if(DEACTIVATE_AVX2)
  200. set(COMPILER_SUPPORT_AVX2 FALSE)
  201. endif()
  202. # flags
  203. # @TODO: set -Wall
  204. # @NOTE: -O3 is enabled in Release mode (CMAKE_BUILD_TYPE="Release")
  205. # Set the "-msse2" build flag only if the CMAKE_C_FLAGS is not already set.
  206. # Probably "-msse2" should be appended to CMAKE_C_FLAGS_RELEASE.
  207. if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  208. if(NOT CMAKE_C_FLAGS AND COMPILER_SUPPORT_SSE2)
  209. set(CMAKE_C_FLAGS -msse2 CACHE STRING "C flags." FORCE)
  210. endif(NOT CMAKE_C_FLAGS AND COMPILER_SUPPORT_SSE2)
  211. endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
  212. if(MSVC)
  213. if(NOT CMAKE_C_FLAGS)
  214. set(CMAKE_C_FLAGS "/Ox" CACHE STRING "C flags." FORCE)
  215. endif(NOT CMAKE_C_FLAGS)
  216. # Turn off misguided "secure CRT" warnings in MSVC.
  217. # Microsoft wants people to use the MS-specific <function>_s
  218. # versions of certain C functions but this is difficult to do
  219. # in platform-independent code.
  220. add_definitions( -D_CRT_SECURE_NO_WARNINGS )
  221. endif(MSVC)
  222. if(WIN32)
  223. # For some supporting headers
  224. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/blosc")
  225. endif(WIN32)
  226. # subdirectories
  227. add_subdirectory(blosc)
  228. if(BUILD_TESTS)
  229. enable_testing()
  230. add_subdirectory(tests)
  231. endif(BUILD_TESTS)
  232. if(BUILD_BENCHMARKS)
  233. add_subdirectory(bench)
  234. endif(BUILD_BENCHMARKS)
  235. # uninstall target
  236. configure_file(
  237. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  238. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  239. IMMEDIATE @ONLY)
  240. add_custom_target(uninstall
  241. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  242. # packaging
  243. include(InstallRequiredSystemLibraries)
  244. set(CPACK_GENERATOR TGZ ZIP)
  245. set(CPACK_SOURCE_GENERATOR TGZ ZIP)
  246. set(CPACK_PACKAGE_VERSION_MAJOR ${BLOSC_VERSION_MAJOR})
  247. set(CPACK_PACKAGE_VERSION_MINOR ${BLOSC_VERSION_MINOR})
  248. set(CPACK_PACKAGE_VERSION_PATCH ${BLOSC_VERSION_PATCH})
  249. set(CPACK_PACKAGE_VERSION ${BLOSC_STRING_VERSION})
  250. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.rst")
  251. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  252. "A blocking, shuffling and lossless compression library")
  253. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSES/BLOSC.txt")
  254. set(CPACK_SOURCE_IGNORE_FILES "/build.*;.*~;\\\\.git.*;\\\\.DS_Store")
  255. set(CPACK_STRIP_FILES TRUE)
  256. set(CPACK_SOURCE_STRIP_FILES TRUE)
  257. include(CPack)