diff --git a/Blosc2Config.cmake.in b/Blosc2Config.cmake.in new file mode 100644 index 000000000..f5685767b --- /dev/null +++ b/Blosc2Config.cmake.in @@ -0,0 +1,84 @@ +# only add PUBLIC dependencies as well +# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-a-package-configuration-file +include(CMakeFindDependencyMacro) + +# Search in _ROOT: +# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() + +# locate the installed FindABC.cmake modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + +# this section stores which configuration options were set +set(HAVE_THREADS @Threads_FOUND@) +set(HAVE_IPP @HAVE_IPP@) +set(HAVE_ZLIB_NG @HAVE_ZLIB_NG@) +set(DEACTIVATE_IPP @DEACTIVATE_IPP@) +set(DEACTIVATE_ZLIB @DEACTIVATE_ZLIB@) +set(DEACTIVATE_ZSTD @DEACTIVATE_ZSTD@) +set(PREFER_EXTERNAL_LZ4 @PREFER_EXTERNAL_LZ4@) +set(PREFER_EXTERNAL_ZLIB @PREFER_EXTERNAL_ZLIB@) +set(PREFER_EXTERNAL_ZSTD @PREFER_EXTERNAL_ZSTD@) + +# find dependencies and their targets, which are used in our Blosc2Targets.cmake +# additionally, the Blosc2_..._FOUND variables are used to support +# find_package(Blosc2 ... COMPONENTS ... ...) +# this enables downstream projects to express the need for specific features. +if(WIN32) + if(HAVE_THREADS) + find_dependency(Threads) + set(Blosc2_THREADS_FOUND TRUE) + else() + set(Blosc2_THREADS_FOUND FALSE) + endif() +else() + find_dependency(Threads) + set(Blosc2_THREADS_FOUND TRUE) +endif() + +if(NOT DEACTIVATE_IPP AND HAVE_IPP) + find_dependency(IPP) + set(Blosc2_IPP_FOUND FALSE) +else() + set(Blosc2_IPP_FOUND TRUE) +endif() + +if(PREFER_EXTERNAL_LZ4) + find_dependency(LZ4) +endif() +set(Blosc2_LZ4_FOUND TRUE) + +if(DEACTIVATE_ZLIB) + set(Blosc2_ZLIB_FOUND FALSE) +elseif(NOT DEACTIVATE_ZLIB AND PREFER_EXTERNAL_ZLIB) + if(HAVE_ZLIB_NG) + find_dependency(ZLIB_NG) + else() + find_dependency(ZLIB) + endif() + set(Blosc2_ZLIB_FOUND TRUE) +endif() + +if(DEACTIVATE_ZSTD) + set(Blosc2_ZSTD_FOUND FALSE) +elseif(NOT PREFER_EXTERNAL_ZSTD AND PREFER_EXTERNAL_ZSTD) + find_dependency(ZSTD) + set(Blosc2_ZSTD_FOUND TRUE) +endif() + +# define central Blosc2::blosc2_shared/static targets +include("${CMAKE_CURRENT_LIST_DIR}/Blosc2Targets.cmake") + +# check if components are fulfilled and set Blosc2__FOUND vars +# Blosc2_FIND_COMPONENTS is a list set by find_package(... COMPONENTS ... ...) +# likewise Blosc2_FIND_REQUIRED_... per component specified +foreach(comp ${Blosc2_FIND_COMPONENTS}) + if(NOT Blosc2_${comp}_FOUND) + if(Blosc2_FIND_REQUIRED_${comp}) + set(Blosc2_FOUND FALSE) + endif() + endif() +endforeach() + diff --git a/CMakeLists.txt b/CMakeLists.txt index 85d1e03c6..9d8c2a3f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,23 +385,6 @@ if(NOT DEFINED BLOSC_INSTALL) endif() endif() -# uninstall target -if(BLOSC_INSTALL) - include(GNUInstallDirs) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/blosc2.pc.in" - "${CMAKE_CURRENT_BINARY_DIR}/blosc2.pc" - @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/blosc2.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT DEV) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - @ONLY) - add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -endif() - # include directories include_directories(include) if(BUILD_PLUGINS) @@ -440,6 +423,120 @@ if(BUILD_EXAMPLES) add_subdirectory(examples) endif() +# collecting SOURCES is now complete +if(BUILD_SHARED) + target_sources(blosc2_shared PRIVATE ${SOURCES}) +endif() +if(BUILD_STATIC) + target_sources(blosc2_static PRIVATE ${SOURCES}) +endif() +if(BUILD_TESTS) + target_sources(blosc_testing PRIVATE ${SOURCES}) +endif() + +# install targets +if(BLOSC_INSTALL) + include(GNUInstallDirs) + + # C++ files + install(FILES ${PROJECT_SOURCE_DIR}/include/blosc2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT DEV) + install(FILES ${PROJECT_SOURCE_DIR}/include/b2nd.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT DEV) + install(FILES + ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-export.h + ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-common.h + ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-stdio.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/blosc2 COMPONENT DEV) + if(BUILD_PLUGINS) + install(FILES + ${PROJECT_SOURCE_DIR}/include/blosc2/filters-registry.h + ${PROJECT_SOURCE_DIR}/include/blosc2/codecs-registry.h + ${PROJECT_SOURCE_DIR}/include/blosc2/tuners-registry.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/blosc2 COMPONENT DEV) + endif() + + if(BUILD_SHARED) + install(TARGETS blosc2_shared + LIBRARY COMPONENT LIB + ARCHIVE COMPONENT DEV + RUNTIME COMPONENT LIB) + endif() + if(BUILD_STATIC) + install(TARGETS blosc2_static COMPONENT DEV) + endif() + + # config files + include(CMakePackageConfigHelpers) + + # we need a general location for Unix and Windows to install our + # Blosc2Config.cmake files to. This is defined in CMake: + # https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure + if(NOT Blosc2_INSTALL_CMAKEDIR) + if(CMAKE_INSTALL_CMAKEDIR) + set(Blosc2_INSTALL_CMAKEDIR "${CMAKE_INSTALL_CMAKEDIR}/Blosc2") + else() + if(WIN32) + set(Blosc2_INSTALL_CMAKEDIR "cmake") + else() + set(Blosc2_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Blosc2") + endif() + endif() + endif() + + # CMake config file + # This stores our targets and find and populates the targets we depend on, + # including third party interface libraries that we added. + set(Blosc2_INSTALL_TARGET_NAMES) + if(BUILD_SHARED) + list(APPEND Blosc2_INSTALL_TARGET_NAMES blosc2_shared) + endif() + if(BUILD_STATIC) + list(APPEND Blosc2_INSTALL_TARGET_NAMES blosc2_static) + endif() + configure_file( + ${PROJECT_SOURCE_DIR}/Blosc2Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/Blosc2Config.cmake + @ONLY + ) + install(TARGETS ${Blosc2_INSTALL_TARGET_NAMES} + EXPORT Blosc2Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + install(EXPORT Blosc2Targets + FILE Blosc2Targets.cmake + NAMESPACE Blosc2:: + DESTINATION ${Blosc2_INSTALL_CMAKEDIR} + ) + write_basic_package_version_file("Blosc2ConfigVersion.cmake" + VERSION ${BLOSC2_VERSION_STRING} + COMPATIBILITY SameMajorVersion + ) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/Blosc2Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/Blosc2ConfigVersion.cmake + DESTINATION ${Blosc2_INSTALL_CMAKEDIR} + ) + + # pkg-config .pc file + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/blosc2.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/blosc2.pc" + @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/blosc2.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT DEV) + + # uninstaller + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + @ONLY) + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +endif() + # packaging if(NOT BLOSC_IS_SUBPROJECT) diff --git a/bench/b2nd/CMakeLists.txt b/bench/b2nd/CMakeLists.txt index 65c45e319..89a4f6f61 100644 --- a/bench/b2nd/CMakeLists.txt +++ b/bench/b2nd/CMakeLists.txt @@ -12,5 +12,5 @@ foreach (source ${SOURCES}) get_filename_component(target_name ${source} NAME_WE) set(target b2nd_${target_name}) add_executable(${target} ${target_name}.c) - target_link_libraries(${target} blosc_testing ${LIBS}) + target_link_libraries(${target} PUBLIC blosc_testing ${LIBS}) endforeach (source) diff --git a/blosc/CMakeLists.txt b/blosc/CMakeLists.txt index a6d566db8..b44b71077 100644 --- a/blosc/CMakeLists.txt +++ b/blosc/CMakeLists.txt @@ -9,71 +9,161 @@ # A simple way to detect that we are using CMAKE add_definitions(-DUSING_CMAKE) -set(INTERNAL_LIBS ${PROJECT_SOURCE_DIR}/internal-complibs) +set(version_string ${BLOSC2_VERSION_MAJOR}.${BLOSC2_VERSION_MINOR}.${BLOSC2_VERSION_PATCH}) -# Hide symbols by default unless they're specifically exported. -# This makes it easier to keep the set of exported symbols the -# same across all compilers/platforms. -set(CMAKE_C_VISIBILITY_PRESET hidden) +# targets +if(BUILD_SHARED) + add_library(blosc2_shared SHARED) + # ALIAS for superbuilds that use Blosc2 as sub-project + # must be the same as the NAMESPACE in Blosc2Targets + add_library(Blosc2::blosc2_shared ALIAS blosc2_shared) + set_target_properties(blosc2_shared PROPERTIES + OUTPUT_NAME blosc2 + # Hide symbols by default unless they're specifically exported. + # This makes it easier to keep the set of exported symbols the + # same across all compilers/platforms. + C_VISIBILITY_PRESET hidden + ) + if(MSVC OR MINGW) + set_target_properties(blosc2_shared PROPERTIES PREFIX lib) + endif() + set_target_properties(blosc2_shared PROPERTIES + VERSION ${version_string} + SOVERSION 2 # Change this when an ABI change happens + ) + target_compile_definitions(blosc2_shared PUBLIC BLOSC_SHARED_LIBRARY) + target_include_directories(blosc2_shared PUBLIC + $ + $) +endif() +if(BUILD_STATIC) + add_library(blosc2_static STATIC) + # ALIAS for superbuilds that use Blosc2 as sub-project + # must be the same as the NAMESPACE in Blosc2Targets + add_library(Blosc2::blosc2_static ALIAS blosc2_static) + set_target_properties(blosc2_static PROPERTIES + OUTPUT_NAME blosc2 + POSITION_INDEPENDENT_CODE ON + # Hide symbols by default unless they're specifically exported. + # This makes it easier to keep the set of exported symbols the + # same across all compilers/platforms. + C_VISIBILITY_PRESET hidden + ) + if(MSVC OR MINGW) + set_target_properties(blosc2_static PROPERTIES PREFIX lib) + endif() + target_include_directories(blosc2_static PUBLIC + $ + $) +endif() +# When the option has been selected to compile the test suite, +# compile an additional version of blosc2_static which exports +# some normally-hidden symbols (to facilitate unit testing). +if(BUILD_TESTS) + add_library(blosc_testing STATIC) + set_target_properties(blosc_testing PROPERTIES OUTPUT_NAME blosc_testing) + if(MSVC OR MINGW) + set_target_properties(blosc_testing PROPERTIES PREFIX lib) + endif() + target_compile_definitions(blosc_testing PUBLIC + BLOSC_TESTING + BLOSC_SHARED_LIBRARY # for EXPORT macro + ) + target_include_directories(blosc_testing PUBLIC + $ + $) +endif() + +set(INTERNAL_LIBS ${PROJECT_SOURCE_DIR}/internal-complibs) -# includes -set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) +# link dependencies +# "link" dependent targets via target_link_libraries (preferred) and +# manually add includes / libs for others if(LZ4_FOUND) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_INCLUDE_DIR}) + if(BUILD_SHARED) + target_include_directories(blosc2_shared PUBLIC ${LZ4_INCLUDE_DIR}) + endif() + if(BUILD_STATIC) + target_include_directories(blosc2_static PUBLIC ${LZ4_INCLUDE_DIR}) + endif() + if(BUILD_TESTS) + target_include_directories(blosc_testing PUBLIC ${LZ4_INCLUDE_DIR}) + endif() else() set(LZ4_LOCAL_DIR ${INTERNAL_LIBS}/lz4-1.9.4) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_LOCAL_DIR}) + if(BUILD_SHARED) + target_include_directories(blosc2_shared PRIVATE ${LZ4_LOCAL_DIR}) + endif() + if(BUILD_STATIC) + target_include_directories(blosc2_static PRIVATE ${LZ4_LOCAL_DIR}) + endif() + if(BUILD_TESTS) + target_include_directories(blosc_testing PRIVATE ${LZ4_LOCAL_DIR}) + endif() endif() if(NOT DEACTIVATE_ZLIB) if(ZLIB_NG_FOUND) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_NG_INCLUDE_DIR}) + if(BUILD_SHARED) + target_link_libraries(blosc2_shared PUBLIC ZLIB_NG::ZLIB_NG) + endif() + if(BUILD_STATIC) + target_link_libraries(blosc2_static PUBLIC ZLIB_NG::ZLIB_NG) + endif() + if(BUILD_TESTS) + target_link_libraries(blosc_testing PUBLIC ZLIB_NG::ZLIB_NG) + endif() elseif(ZLIB_FOUND) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS}) + if(BUILD_SHARED) + target_link_libraries(blosc2_shared PUBLIC ZLIB::ZLIB) + endif() + if(BUILD_STATIC) + target_link_libraries(blosc2_static PUBLIC ZLIB::ZLIB) + endif() + if(BUILD_TESTS) + target_link_libraries(blosc_testing PUBLIC ZLIB::ZLIB) + endif() else() set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR}) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_LOCAL_DIR}) + if(BUILD_SHARED) + target_include_directories(blosc2_shared PRIVATE ${ZLIB_LOCAL_DIR}) + endif() + if(BUILD_STATIC) + target_include_directories(blosc2_static PRIVATE ${ZLIB_LOCAL_DIR}) + endif() + if(BUILD_TESTS) + target_include_directories(blosc_testing PRIVATE ${ZLIB_LOCAL_DIR}) + endif() endif() endif() if(NOT DEACTIVATE_ZSTD) if(ZSTD_FOUND) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIR}) + if(BUILD_SHARED) + target_include_directories(blosc2_shared PUBLIC ${ZSTD_INCLUDE_DIR}) + target_link_libraries(blosc2_shared PUBLIC ${ZSTD_LIBRARY}) + endif() + if(BUILD_STATIC) + target_include_directories(blosc2_static PUBLIC ${ZSTD_INCLUDE_DIR}) + target_link_libraries(blosc2_static PUBLIC ${ZSTD_LIBRARY}) + endif() + if(BUILD_TESTS) + target_include_directories(blosc_testing PUBLIC ${ZSTD_INCLUDE_DIR}) + target_link_libraries(blosc_testing PUBLIC ${ZSTD_LIBRARY}) + endif() else() set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.5.5) - set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_LOCAL_DIR} - ${ZSTD_LOCAL_DIR}/common) - endif() -endif() - -include_directories(${BLOSC_INCLUDE_DIRS}) - -# library sources -set(SOURCES ${SOURCES} blosc2.c blosclz.c fastcopy.c fastcopy.h schunk.c frame.c stune.c stune.h - context.h delta.c delta.h shuffle-generic.c bitshuffle-generic.c trunc-prec.c trunc-prec.h - timestamp.c sframe.c directories.c blosc2-stdio.c - b2nd.c b2nd_utils.c) -if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) - if(COMPILER_SUPPORT_SSE2) - message(STATUS "Adding run-time support for SSE2") - set(SOURCES ${SOURCES} shuffle-sse2.c bitshuffle-sse2.c) - endif() - if(COMPILER_SUPPORT_AVX2) - message(STATUS "Adding run-time support for AVX2") - set(SOURCES ${SOURCES} shuffle-avx2.c bitshuffle-avx2.c) + if(BUILD_SHARED) + target_include_directories(blosc2_shared PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common) + endif() + if(BUILD_STATIC) + target_include_directories(blosc2_static PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common) + endif() + if(BUILD_TESTS) + target_include_directories(blosc_testing PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common) + endif() endif() endif() -if(COMPILER_SUPPORT_NEON) - message(STATUS "Adding run-time support for NEON") - set(SOURCES ${SOURCES} shuffle-neon.c bitshuffle-neon.c) -endif() -if(COMPILER_SUPPORT_ALTIVEC) - message(STATUS "Adding run-time support for ALTIVEC") - set(SOURCES ${SOURCES} shuffle-altivec.c bitshuffle-altivec.c) -endif() -set(SOURCES ${SOURCES} shuffle.c) - -set(version_string ${BLOSC2_VERSION_MAJOR}.${BLOSC2_VERSION_MINOR}.${BLOSC2_VERSION_PATCH}) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) # pre 3.1 set(THREADS_PREFER_PTHREAD_FLAG TRUE) # CMake 3.1+ @@ -82,7 +172,7 @@ if(WIN32) find_package(Threads) if(NOT Threads_FOUND) message(STATUS "using the internal pthread library for win32 systems.") - set(SOURCES ${SOURCES} win32/pthread.c) + list(APPEND SOURCES blosc/win32/pthread.c) else() if(CMAKE_VERSION VERSION_LESS 3.1) set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) @@ -104,7 +194,7 @@ if(LZ4_FOUND) set(LIBS ${LIBS} ${LZ4_LIBRARY}) else() file(GLOB LZ4_FILES ${LZ4_LOCAL_DIR}/*.c) - set(SOURCES ${SOURCES} ${LZ4_FILES}) + list(APPEND SOURCES ${LZ4_FILES}) source_group("LZ4" FILES ${LZ4_FILES}) endif() @@ -116,7 +206,7 @@ if(NOT DEACTIVATE_ZLIB) else() set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR}) file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c) - set(SOURCES ${SOURCES} ${ZLIB_FILES}) + list(APPEND SOURCES ${ZLIB_FILES}) source_group("Zlib" FILES ${ZLIB_FILES}) endif() endif() @@ -140,7 +230,7 @@ if(NOT DEACTIVATE_ZSTD) file(GLOB ZSTD_DICT_FILES ${ZSTD_LOCAL_DIR}/dictBuilder/*.c) set(ZSTD_FILES ${ZSTD_COMMON_FILES} ${ZSTD_COMPRESS_FILES} ${ZSTD_DECOMPRESS_FILES} ${ZSTD_DICT_FILES}) - set(SOURCES ${SOURCES} ${ZSTD_FILES}) + list(APPEND SOURCES ${ZSTD_FILES}) source_group("Zstd" FILES ${ZSTD_FILES}) endif() endif() @@ -156,21 +246,49 @@ if(UNIX AND NOT APPLE) endif() -# targets -if(BUILD_SHARED) - add_library(blosc2_shared SHARED ${SOURCES}) - set_target_properties(blosc2_shared PROPERTIES OUTPUT_NAME blosc2) - if(MSVC OR MINGW) - set_target_properties(blosc2_shared PROPERTIES PREFIX lib) +# Blosc2 library source files +list(APPEND SOURCES + blosc/blosc2.c + blosc/blosclz.c + blosc/fastcopy.c + blosc/fastcopy.h + blosc/schunk.c + blosc/frame.c + blosc/stune.c + blosc/stune.h + blosc/context.h + blosc/delta.c + blosc/delta.h + blosc/shuffle-generic.c + blosc/bitshuffle-generic.c + blosc/trunc-prec.c + blosc/trunc-prec.h + blosc/timestamp.c + blosc/sframe.c + blosc/directories.c + blosc/blosc2-stdio.c + blosc/b2nd.c + blosc/b2nd_utils.c +) +if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + if(COMPILER_SUPPORT_SSE2) + message(STATUS "Adding run-time support for SSE2") + list(APPEND SOURCES blosc/shuffle-sse2.c blosc/bitshuffle-sse2.c) endif() - set_target_properties(blosc2_shared PROPERTIES - VERSION ${version_string} - SOVERSION 2 # Change this when an ABI change happens - ) - set_property( - TARGET blosc2_shared - APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_SHARED_LIBRARY) + if(COMPILER_SUPPORT_AVX2) + message(STATUS "Adding run-time support for AVX2") + list(APPEND SOURCES blosc/shuffle-avx2.c blosc/bitshuffle-avx2.c) + endif() +endif() +if(COMPILER_SUPPORT_NEON) + message(STATUS "Adding run-time support for NEON") + list(APPEND SOURCES blosc/shuffle-neon.c blosc/bitshuffle-neon.c) +endif() +if(COMPILER_SUPPORT_ALTIVEC) + message(STATUS "Adding run-time support for ALTIVEC") + list(APPEND SOURCES blosc/shuffle-altivec.c blosc/bitshuffle-altivec.c) endif() +list(APPEND SOURCES blosc/shuffle.c) # Based on the target architecture and hardware features supported # by the C compiler, set hardware architecture optimization flags @@ -270,68 +388,21 @@ if(COMPILER_SUPPORT_ALTIVEC) APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_ALTIVEC_ENABLED) endif() -# When the option has been selected to compile the test suite, -# compile an additional version of blosc2_static which exports -# some normally-hidden symbols (to facilitate unit testing). -if(BUILD_TESTS) - add_library(blosc_testing STATIC ${SOURCES}) - set_target_properties(blosc_testing PROPERTIES OUTPUT_NAME blosc_testing) - if(MSVC OR MINGW) - set_target_properties(blosc_testing PROPERTIES PREFIX lib) - endif() - set_property( - TARGET blosc_testing - APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_SHARED_LIBRARY) - set_property( - TARGET blosc_testing - APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_TESTING) -endif() - +# add libraries for dependencies that are not CMake targets if(BUILD_SHARED) - target_link_libraries(blosc2_shared ${LIBS}) + target_link_libraries(blosc2_shared PUBLIC ${LIBS}) target_include_directories(blosc2_shared PUBLIC ${BLOSC_INCLUDE_DIRS}) endif() -if(BUILD_TESTS) - target_link_libraries(blosc_testing ${LIBS}) - target_include_directories(blosc_testing PUBLIC ${BLOSC_INCLUDE_DIRS}) -endif() - if(BUILD_STATIC) - add_library(blosc2_static STATIC ${SOURCES}) - set_target_properties(blosc2_static PROPERTIES OUTPUT_NAME blosc2) - set_target_properties(blosc2_static PROPERTIES POSITION_INDEPENDENT_CODE ON) - if(MSVC OR MINGW) - set_target_properties(blosc2_static PROPERTIES PREFIX lib) - endif() - target_link_libraries(blosc2_static ${LIBS}) + target_link_libraries(blosc2_static PUBLIC ${LIBS}) target_include_directories(blosc2_static PUBLIC ${BLOSC_INCLUDE_DIRS}) endif() -# install -if(BLOSC_INSTALL) - install(FILES ${PROJECT_SOURCE_DIR}/include/blosc2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT DEV) - install(FILES ${PROJECT_SOURCE_DIR}/include/b2nd.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT DEV) - install(FILES - ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-export.h - ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-common.h - ${PROJECT_SOURCE_DIR}/include/blosc2/blosc2-stdio.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/blosc2 COMPONENT DEV) - if(BUILD_PLUGINS) - install(FILES - ${PROJECT_SOURCE_DIR}/include/blosc2/filters-registry.h - ${PROJECT_SOURCE_DIR}/include/blosc2/codecs-registry.h - ${PROJECT_SOURCE_DIR}/include/blosc2/tuners-registry.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/blosc2 COMPONENT DEV) - endif() - - if(BUILD_SHARED) - install(TARGETS blosc2_shared - LIBRARY COMPONENT LIB - ARCHIVE COMPONENT DEV - RUNTIME COMPONENT LIB) - endif() - if(BUILD_STATIC) - install(TARGETS blosc2_static COMPONENT DEV) - endif() +if(BUILD_TESTS) + target_link_libraries(blosc_testing PUBLIC ${LIBS}) + target_include_directories(blosc_testing PUBLIC ${BLOSC_INCLUDE_DIRS}) endif() + +# we use this variable in the CMake file one directory above ours +set(SOURCES ${SOURCES} PARENT_SCOPE) diff --git a/plugins/codecs/ndlz/CMakeLists.txt b/plugins/codecs/ndlz/CMakeLists.txt index 24424fa1f..5e06cfbb9 100644 --- a/plugins/codecs/ndlz/CMakeLists.txt +++ b/plugins/codecs/ndlz/CMakeLists.txt @@ -19,15 +19,13 @@ if(BUILD_TESTS) add_executable(test_ndlz test_ndlz.c) # Define the BLOSC_TESTING symbol so normally-hidden functions # aren't hidden from the view of the test programs. - set_property( - TARGET test_ndlz - APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_TESTING) + target_compile_definitions(test_ndlz PUBLIC BLOSC_TESTING) - target_link_libraries(test_ndlz blosc_testing) + target_link_libraries(test_ndlz PUBLIC blosc_testing) # tests - add_test(NAME test_plugin_test_ndlz - COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) + add_test(NAME test_plugin_test_ndlz + COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) # Copy test files file(GLOB TESTS_DATA ../../test_data/example_s*.b2nd) diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 96417dd7e..d8a4aea02 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -1,6 +1,3 @@ -# flags -link_directories(${PROJECT_BINARY_DIR}/blosc) - # look for fuzzing lib and link with it if found if(CMAKE_C_COMPILER_ID STREQUAL "Clang") enable_language(CXX) @@ -64,11 +61,10 @@ foreach(source ${SOURCES}) if(FUZZING_ENGINE_FOUND) set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX) - target_link_libraries(${target} ${FUZZING_ENGINE}) + target_link_libraries(${target} PUBLIC ${FUZZING_ENGINE}) endif() - target_link_libraries(${target} blosc2_static) - add_dependencies(${target} blosc2_static) + target_link_libraries(${target} PUBLIC blosc2_static) # run standalone fuzzer against each file file(GLOB COMPAT_FILES ${PROJECT_SOURCE_DIR}/compat/*.cdata)