Commit 03e6edb2 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Merge branch 'cmake_export' into 'master'

cmake export

Closes #4

See merge request !2
parents 7b7b61c7 608635af
Pipeline #61971 passed with stage
in 23 seconds
# cerfConfig.cmake
# ----------------
#
# cerf cmake module.
# This module sets the following variables in your project:
#
# ::
#
# cerf_FOUND - true if cerf and all required components found on the system
#
#
# Available components: shared static
#
# ::
#
# shared - search for only shared library
# static - search for only static library
# C - search for C library only
# CXX - search for CXX library only
#
#
# Exported targets:
#
# ::
#
# If cerf is found, this module defines the following :prop_tgt:`IMPORTED`
# targets. Target is shared _or_ static, so, for both, use separate, not
# overlapping, installations. ::
#
# cerf::cerf - the main cerf library with header attached.
# cerf::cerfcpp - the C++ cerf library
#
#
# Suggested usage:
#
# ::
#
# find_package(cerf)
# find_package(cerf 1.17.0 EXACT CONFIG REQUIRED COMPONENTS shared C)
#
#
# The following variables can be set to guide the search for this package:
#
# ::
#
# cerf_DIR - CMake variable, set to directory containing this Config file
# CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package
# PATH - environment variable, set to bin directory of this package
# CMAKE_DISABLE_FIND_PACKAGE_cerf - CMake variable, disables
# find_package(cerf) when not REQUIRED, perhaps to force internal build
@PACKAGE_INIT@
set(PN cerf)
set (_valid_components
static
shared
C
CXX
)
# check library style component
if(@BUILD_SHARED_LIBS@)
set(${PN}_shared_FOUND 1)
else()
set(${PN}_static_FOUND 1)
endif()
list(FIND ${PN}_FIND_COMPONENTS "shared" _seek_shared)
list(FIND ${PN}_FIND_COMPONENTS "static" _seek_static)
# check library language component
if(@CERF_CPP@)
set(${PN}_CXX_FOUND 1)
set(_target "cerfcpp")
else()
set(${PN}_C_FOUND 1)
set(_target "cerf")
endif()
list(FIND ${PN}_FIND_COMPONENTS "C" _seek_C)
list(FIND ${PN}_FIND_COMPONENTS "CXX" _seek_CXX)
check_required_components(${PN})
#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built this as a subproject
#-----------------------------------------------------------------------------
if(NOT TARGET ${PN}::${_target})
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
get_property(_loc TARGET ${PN}::${_target} PROPERTY LOCATION)
get_property(_ill TARGET ${PN}::${_target} PROPERTY INTERFACE_LINK_LIBRARIES)
get_property(_id TARGET ${PN}::${_target} PROPERTY INCLUDE_DIRECTORIES)
get_property(_iid TARGET ${PN}::${_target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
# message("cerf::${_target}")
# message("loc ${_loc}")
# message("ill ${_ill}")
# message("id ${_id}")
# message("iid ${_iid}")
endif()
set(lib cerf)
set(intf "c_interface")
if (${CERF_CPP})
set(lib cerfcpp)
set(intf "cxx_interface")
endif()
message(STATUS
"libcerf/lib: build library ${lib}, CERF_CPP=${CERF_CPP}, shared=${BUILD_SHARED_LIBS}")
......@@ -29,8 +31,13 @@ if(NOT MSVC)
target_link_libraries(${lib} m)
endif()
target_include_directories(${lib} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(
TARGETS ${lib}
EXPORT ${intf}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
......@@ -40,6 +47,22 @@ install(
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Headers)
include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/cerf")
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/cerfConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cerfConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cerfConfigVersion.cmake
VERSION ${CERF_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cerfConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cerfConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${intf}
NAMESPACE "cerf::"
FILE "cerfTargets.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
set(CPACK_PACKAGE_VENDOR "Forschungszentrum Jülich GmbH")
set(CPACK_PACKAGE_VERSION ${CERF_VERSION})
set(CPACK_GENERATOR "ZIP")
......
Supports Markdown
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