CMakeLists.txt 6.4 KB

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