CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # a simple way to detect that we are using CMAKE
  2. add_definitions(-DUSING_CMAKE)
  3. set(INTERNAL_LIBS ${PROJECT_SOURCE_DIR}/internal-complibs)
  4. # Hide symbols by default unless they're specifically exported.
  5. # This makes it easier to keep the set of exported symbols the
  6. # same across all compilers/platforms.
  7. set(CMAKE_C_VISIBILITY_PRESET hidden)
  8. # includes
  9. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
  10. if(NOT DEACTIVATE_LZ4)
  11. if (LZ4_FOUND)
  12. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_INCLUDE_DIR})
  13. else(LZ4_FOUND)
  14. set(LZ4_LOCAL_DIR ${INTERNAL_LIBS}/lz4-1.8.1.2)
  15. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_LOCAL_DIR})
  16. endif(LZ4_FOUND)
  17. endif(NOT DEACTIVATE_LZ4)
  18. if(NOT DEACTIVATE_SNAPPY)
  19. if (SNAPPY_FOUND)
  20. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_INCLUDE_DIR})
  21. else(SNAPPY_FOUND)
  22. set(SNAPPY_LOCAL_DIR ${INTERNAL_LIBS}/snappy-1.1.1)
  23. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_LOCAL_DIR})
  24. endif(SNAPPY_FOUND)
  25. endif(NOT DEACTIVATE_SNAPPY)
  26. if(NOT DEACTIVATE_ZLIB)
  27. if (ZLIB_FOUND)
  28. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
  29. else(ZLIB_FOUND)
  30. set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/zlib-1.2.8)
  31. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_LOCAL_DIR})
  32. endif(ZLIB_FOUND)
  33. endif(NOT DEACTIVATE_ZLIB)
  34. if (NOT DEACTIVATE_ZSTD)
  35. if (ZSTD_FOUND)
  36. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIR})
  37. else (ZSTD_FOUND)
  38. set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.3.4)
  39. set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
  40. endif (ZSTD_FOUND)
  41. endif (NOT DEACTIVATE_ZSTD)
  42. include_directories(${BLOSC_INCLUDE_DIRS})
  43. # library sources
  44. set(SOURCES blosc.c blosclz.c fastcopy.c shuffle-generic.c bitshuffle-generic.c
  45. blosc-common.h blosc-export.h)
  46. if(COMPILER_SUPPORT_SSE2)
  47. message(STATUS "Adding run-time support for SSE2")
  48. set(SOURCES ${SOURCES} shuffle-sse2.c bitshuffle-sse2.c)
  49. endif(COMPILER_SUPPORT_SSE2)
  50. if(COMPILER_SUPPORT_AVX2)
  51. message(STATUS "Adding run-time support for AVX2")
  52. set(SOURCES ${SOURCES} shuffle-avx2.c bitshuffle-avx2.c)
  53. endif(COMPILER_SUPPORT_AVX2)
  54. set(SOURCES ${SOURCES} shuffle.c)
  55. # library install directory
  56. set(lib_dir lib${LIB_SUFFIX})
  57. set(version_string ${BLOSC_VERSION_MAJOR}.${BLOSC_VERSION_MINOR}.${BLOSC_VERSION_PATCH})
  58. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  59. if(WIN32)
  60. # try to use the system library
  61. find_package(Threads)
  62. if(NOT Threads_FOUND)
  63. message(STATUS "using the internal pthread library for win32 systems.")
  64. set(SOURCES ${SOURCES} win32/pthread.c)
  65. else(NOT Threads_FOUND)
  66. set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
  67. endif(NOT Threads_FOUND)
  68. else(WIN32)
  69. find_package(Threads REQUIRED)
  70. set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
  71. endif(WIN32)
  72. if(NOT DEACTIVATE_LZ4)
  73. if(LZ4_FOUND)
  74. set(LIBS ${LIBS} ${LZ4_LIBRARY})
  75. else(LZ4_FOUND)
  76. file(GLOB LZ4_FILES ${LZ4_LOCAL_DIR}/*.c)
  77. set(SOURCES ${SOURCES} ${LZ4_FILES})
  78. endif(LZ4_FOUND)
  79. endif(NOT DEACTIVATE_LZ4)
  80. if(NOT DEACTIVATE_SNAPPY)
  81. if(SNAPPY_FOUND)
  82. set(LIBS ${LIBS} ${SNAPPY_LIBRARY})
  83. else(SNAPPY_FOUND)
  84. file(GLOB SNAPPY_FILES ${SNAPPY_LOCAL_DIR}/*.cc)
  85. set(SOURCES ${SOURCES} ${SNAPPY_FILES})
  86. endif(SNAPPY_FOUND)
  87. endif(NOT DEACTIVATE_SNAPPY)
  88. if(NOT DEACTIVATE_ZLIB)
  89. if(ZLIB_FOUND)
  90. set(LIBS ${LIBS} ${ZLIB_LIBRARY})
  91. else(ZLIB_FOUND)
  92. file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c)
  93. set(SOURCES ${SOURCES} ${ZLIB_FILES})
  94. endif(ZLIB_FOUND)
  95. endif(NOT DEACTIVATE_ZLIB)
  96. if (NOT DEACTIVATE_ZSTD)
  97. if (ZSTD_FOUND)
  98. set(LIBS ${LIBS} ${ZSTD_LIBRARY})
  99. else (ZSTD_FOUND)
  100. file(GLOB ZSTD_FILES
  101. ${ZSTD_LOCAL_DIR}/common/*.c
  102. ${ZSTD_LOCAL_DIR}/compress/*.c
  103. ${ZSTD_LOCAL_DIR}/decompress/*.c)
  104. set(SOURCES ${SOURCES} ${ZSTD_FILES})
  105. endif (ZSTD_FOUND)
  106. endif (NOT DEACTIVATE_ZSTD)
  107. # targets
  108. if (BUILD_SHARED)
  109. add_library(blosc_shared SHARED ${SOURCES})
  110. set_target_properties(blosc_shared PROPERTIES OUTPUT_NAME blosc)
  111. set_target_properties(blosc_shared PROPERTIES
  112. VERSION ${version_string}
  113. SOVERSION 1 # Change this when an ABI change happens
  114. )
  115. set_property(
  116. TARGET blosc_shared
  117. APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_SHARED_LIBRARY)
  118. endif()
  119. # Based on the target architecture and hardware features supported
  120. # by the C compiler, set hardware architecture optimization flags
  121. # for specific shuffle implementations.
  122. if(COMPILER_SUPPORT_SSE2)
  123. if (MSVC)
  124. # MSVC targets SSE2 by default on 64-bit configurations, but not 32-bit configurations.
  125. if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
  126. set_source_files_properties(shuffle-sse2.c bitshuffle-sse2.c PROPERTIES COMPILE_FLAGS "/arch:SSE2")
  127. endif (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
  128. else (MSVC)
  129. set_source_files_properties(shuffle-sse2.c bitshuffle-sse2.c PROPERTIES COMPILE_FLAGS -msse2)
  130. endif (MSVC)
  131. # Define a symbol for the shuffle-dispatch implementation
  132. # so it knows SSE2 is supported even though that file is
  133. # compiled without SSE2 support (for portability).
  134. set_property(
  135. SOURCE shuffle.c
  136. APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_SSE2_ENABLED)
  137. endif(COMPILER_SUPPORT_SSE2)
  138. if(COMPILER_SUPPORT_AVX2)
  139. if (MSVC)
  140. set_source_files_properties(shuffle-avx2.c bitshuffle-avx2.c PROPERTIES COMPILE_FLAGS "/arch:AVX2")
  141. else (MSVC)
  142. set_source_files_properties(shuffle-avx2.c bitshuffle-avx2.c PROPERTIES COMPILE_FLAGS -mavx2)
  143. endif (MSVC)
  144. # Define a symbol for the shuffle-dispatch implementation
  145. # so it knows AVX2 is supported even though that file is
  146. # compiled without AVX2 support (for portability).
  147. set_property(
  148. SOURCE shuffle.c
  149. APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_AVX2_ENABLED)
  150. endif(COMPILER_SUPPORT_AVX2)
  151. # When the option has been selected to compile the test suite,
  152. # compile an additional version of blosc_shared which exports
  153. # some normally-hidden symbols (to facilitate unit testing).
  154. if (BUILD_TESTS)
  155. add_library(blosc_shared_testing SHARED ${SOURCES})
  156. set_target_properties(blosc_shared_testing PROPERTIES OUTPUT_NAME blosc_testing)
  157. set_property(
  158. TARGET blosc_shared_testing
  159. APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_SHARED_LIBRARY)
  160. set_property(
  161. TARGET blosc_shared_testing
  162. APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_TESTING)
  163. # TEMP : CMake doesn't automatically add -lpthread here like it does
  164. # for the blosc_shared target. Force it for now.
  165. if(UNIX)
  166. set_property(
  167. TARGET blosc_shared_testing
  168. APPEND PROPERTY LINK_FLAGS "-lpthread")
  169. endif()
  170. endif()
  171. if (BUILD_SHARED)
  172. target_link_libraries(blosc_shared ${LIBS})
  173. target_include_directories(blosc_shared PUBLIC ${BLOSC_INCLUDE_DIRS})
  174. endif()
  175. if (BUILD_TESTS)
  176. target_link_libraries(blosc_shared_testing ${LIBS})
  177. target_include_directories(blosc_shared_testing PUBLIC ${BLOSC_INCLUDE_DIRS})
  178. endif()
  179. if(BUILD_STATIC)
  180. add_library(blosc_static STATIC ${SOURCES})
  181. set_target_properties(blosc_static PROPERTIES OUTPUT_NAME blosc)
  182. if (MSVC)
  183. set_target_properties(blosc_static PROPERTIES PREFIX lib)
  184. endif()
  185. target_link_libraries(blosc_static ${LIBS})
  186. target_include_directories(blosc_static PUBLIC ${BLOSC_INCLUDE_DIRS})
  187. endif(BUILD_STATIC)
  188. # install
  189. if(BLOSC_INSTALL)
  190. install(FILES blosc.h blosc-export.h DESTINATION include COMPONENT DEV)
  191. if(BUILD_SHARED)
  192. install(TARGETS blosc_shared DESTINATION ${lib_dir} COMPONENT LIB)
  193. endif(BUILD_SHARED)
  194. if(BUILD_STATIC)
  195. install(TARGETS blosc_static DESTINATION ${lib_dir} COMPONENT DEV)
  196. endif(BUILD_STATIC)
  197. endif(BLOSC_INSTALL)