Unverified Commit 05a3192d authored by Jan-Willem Blokland's avatar Jan-Willem Blokland Committed by GitHub
Browse files

Bugfix/cmake (#16)

* CMake: (fix) Changed names of the resulting config files.

Changed the name LibaecTargets.cmake, LibaecConfig.cmake and
LibaecConfigVersion.cmake to libaecTargets.cmake, libaecConfig.cmake
and libaecConfigVersion.cmake such that these files can be found
by cmake on a Linux machine.

* CMake: (feature) Better integration with HDF5.

- Changed the build such that always a static and shared library
  with be built.
- Rewritten CMake config files such that
  - One can select the shared or static library.
  - Set several libaec variables such one can, for example,
    check if the libaec library is found.
  - Set several Szip variables for the same reason as for
    setting the libaec variables. This is useful for a better
    integration with HDF5 when building HDF5 from scratch.
parent 7a822331
cmake_minimum_required(VERSION 3.13...3.19)
project(libaec LANGUAGES C VERSION 1.0.4)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
project(libaec LANGUAGES C VERSION 1.0.5)
# Automatically export symbls for Windows DLLs
# Automatically export symbols for Windows DLLs
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(CMAKE_C_STANDARD 99)
......@@ -61,6 +60,18 @@ if(AEC_FUZZING)
target_link_options(aec PUBLIC ${FUZZ_TARGET_SAN_FLAGS})
endif()
# Install the cmake files.
set(libaec_CONFIG_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config.cmake.in)
set(libaec_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config.cmake)
configure_file(${libaec_CONFIG_IN} ${libaec_CONFIG_OUT} @ONLY)
set(libaec_CONFIG_VERSION_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config-version.cmake.in)
set(libaec_CONFIG_VERSION_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config-version.cmake)
configure_file(${libaec_CONFIG_VERSION_IN} ${libaec_CONFIG_VERSION_OUT} @ONLY)
install(FILES ${libaec_CONFIG_OUT}
DESTINATION cmake)
install(FILES ${libaec_CONFIG_VERSION_OUT}
DESTINATION cmake)
# Cpack configuration mainly for Windows installer
set(CPACK_PACKAGE_NAME "libaec")
set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
......
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/LibaecTargets.cmake")
check_required_components(libaec)
set(PACKAGE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
set(PACKAGE_VERSION_MINOR @PROJECT_VERSION_MINOR@)
set(PACKAGE_VERSION_PATCH @PROJECT_VERSION_PATCH@)
set(PACKAGE_VERSION @PROJECT_VERSION@)
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION OR
PACKAGE_VERSION_MAJOR GREATER PACKAGE_FIND_VERSION_MAJOR)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
# libaec-config.cmake
# ----------------
#
# Finds the AEC library, specify the starting search path in libaec_ROOT.
#
# Static vs. shared
# -----------------
# To make use of the static library instead of the shared one, one needs
# to set the variable libaec_USE_STATIC_LIBS to ON before calling find_package.
# Example:
# set(libaec_USE_STATIC_LIBS ON)
# find_package(libaec CONFIG)
#
# This will define the following variables:
#
# libaec_FOUND - True if the system has the AEC library.
# libaec_VERSION - The version of the AEC library which was found.
# SZIP_FOUND - True if the system has the SZIP library.
# SZIP_VERSION - The version of the SZIP library which was found.
# SZIP_LIBRARIES - All the required libraries to make use of SZIP.
#
# and the following imported targets:
#
# libaec::aec - The AEC library.
# libaec::sz - The SZIP compatible version of the AEC library.
find_path(libaec_INCLUDE_DIR NAMES libaec.h DOC "AEC include directory")
find_path(SZIP_INCLUDE_DIR NAMES szlib.h DOC "SZIP include directory")
if (libaec_USE_STATIC_LIBS)
if (WIN32)
find_library(libaec_LIBRARY NAMES aec_static.lib DOC "AEC library")
find_library(SZIP_LIBRARY NAMES szip_static.lib DOC "SZIP compatible version of the AEC library")
else ()
find_library(libaec_LIBRARY NAMES libaec.a DOC "AEC library")
find_library(SZIP_LIBRARY NAMES libsz.a DOC "SZIP compatible version of the AEC library")
endif ()
else ()
if (WIN32)
find_library(libaec_LIBRARY NAMES aec.lib DOC "AEC library")
find_library(SZIP_LIBRARY NAMES szip.lib DOC "SZIP compatible version of the AEC library")
else ()
find_library(libaec_LIBRARY NAMES libaec.so DOC "AEC library")
find_library(SZIP_LIBRARY NAMES libsz.so DOC "SZIP compatible version of the AEC library")
endif ()
endif ()
# Check version here
if (libaec_INCLUDE_DIR AND libaec_LIBRARY)
set(libaec_VERSION "@PROJECT_VERSION@")
set(SZIP_VERSION "2.0.1")
endif ()
include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
find_package_handle_standard_args(libaec
FOUND_VAR libaec_FOUND
REQUIRED_VARS libaec_LIBRARY libaec_INCLUDE_DIR SZIP_LIBRARY SZIP_INCLUDE_DIR
VERSION_VAR libaec_VERSION
CONFIG_MODE
)
if (libaec_FOUND)
if (libaec_USE_STATIC_LIBS)
add_library(libaec::aec STATIC IMPORTED)
else ()
add_library(libaec::aec SHARED IMPORTED)
endif ()
set_target_properties(libaec::aec PROPERTIES
IMPORTED_LOCATION "${libaec_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${libaec_INCLUDE_DIR}"
)
# SZIP
if (libaec_USE_STATIC_LIBS)
add_library(libaec::sz STATIC IMPORTED)
else ()
add_library(libaec::sz SHARED IMPORTED)
endif ()
set_target_properties(libaec::sz PROPERTIES
IMPORTED_LOCATION "${SZIP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SZIP_INCLUDE_DIR}"
)
# Set SZIP variables.
set(SZIP_FOUND TRUE)
set(SZIP_LIBRARIES "${SZIP_LIBRARY}")
endif ()
mark_as_advanced(
libaec_LIBRARY
libaec_INCLUDE_DIR
SZIP_LIBRARY
SZIP_INCLUDE_DIR
)
# Main library aec
add_library(aec
add_library(aec OBJECT
encode.c
encode_accessors.c
decode.c)
add_library(libaec::aec ALIAS aec)
target_include_directories(aec
PUBLIC
......@@ -11,23 +10,41 @@ target_include_directories(aec
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..>"
"$<INSTALL_INTERFACE:include>")
set_target_properties(aec
# Create both static and shared aec library.
add_library(aec_static STATIC "$<TARGET_OBJECTS:aec>")
target_link_libraries(aec_static PUBLIC aec)
set_target_properties(aec_static
PROPERTIES
OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,aec_static,aec>)
add_library(aec_shared SHARED "$<TARGET_OBJECTS:aec>")
target_link_libraries(aec_shared PUBLIC aec)
set_target_properties(aec_shared
PROPERTIES
VERSION 0.0.10
SOVERSION 0
OUTPUT_NAME aec
PUBLIC_HEADER ../include/libaec.h)
# Wrapper for compatibility with szip
add_library(sz sz_compat.c)
add_library(libaec::sz ALIAS sz)
add_library(sz OBJECT sz_compat.c)
target_link_libraries(sz PUBLIC aec)
# Create both static and shared szip library.
add_library(sz_static STATIC "$<TARGET_OBJECTS:sz>" "$<TARGET_OBJECTS:aec>")
set_target_properties(sz_static
PROPERTIES
OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,szip_static,sz>)
target_link_libraries(sz_static PUBLIC sz)
set_target_properties(sz
add_library(sz_shared SHARED "$<TARGET_OBJECTS:sz>" "$<TARGET_OBJECTS:aec>")
target_link_libraries(sz_shared PUBLIC sz)
set_target_properties(sz_shared
PROPERTIES
VERSION 2.0.1
SOVERSION 2
OUTPUT_NAME $<IF:$<BOOL:${WIN32}>,szip,sz>
PUBLIC_HEADER ../include/szlib.h)
target_link_libraries(sz PUBLIC aec)
# Simple client for testing and benchmarking.
# Can also be used stand-alone
......@@ -61,25 +78,4 @@ if(UNIX)
COMPONENT doc)
endif()
install(TARGETS aec sz aec_client
EXPORT LibaecTargets)
install(EXPORT LibaecTargets
FILE LibaecTargets.cmake
NAMESPACE libaec::
DESTINATION lib/cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/../Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/LibaecConfig.cmake"
INSTALL_DESTINATION lib/cmake)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/LibaecConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/LibaecConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LibaecConfigVersion.cmake"
DESTINATION lib/cmake)
install(TARGETS aec_static aec_shared sz_static sz_shared aec_client)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment