Skip to content

Commit

Permalink
CMake: Install blosc2Config.cmake
Browse files Browse the repository at this point in the history
This adds a CMake installer to conserve targets and properties
on install, so CMake users do not need to write `Findblosc2.cmake`
files anymore.

This also helps to preserve transitive dependencies on CMake
targets, especially useful for fully static builds, e.g., for
Python wheels.
  • Loading branch information
ax3l committed Jul 26, 2023
1 parent 2714de0 commit 0ea519c
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 131 deletions.
126 changes: 109 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -440,6 +423,115 @@ 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)

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
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)
Expand Down
2 changes: 1 addition & 1 deletion bench/b2nd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit 0ea519c

Please sign in to comment.