Skip to content

Commit

Permalink
Merge branch 'master' into fix-forced-build-type
Browse files Browse the repository at this point in the history
  • Loading branch information
brarcher authored Oct 20, 2019
2 parents 401856d + ca33ec0 commit 67c53e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
26 changes: 20 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,29 +490,43 @@ set(EXPORT_NAME ${PROJECT_NAME})
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/${EXPORT_NAME}/cmake
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(EXPORT check-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/check-targets.cmake"
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-targets.cmake"
NAMESPACE Check::
)

install(EXPORT check-targets
NAMESPACE Check::
FILE check-targets.cmake
FILE "${EXPORT_NAME}-targets.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake"
"${CMAKE_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)

# Store the current build directory in the CMake user package registry.
# This helps dependent projects use a package from the current
# project’s build tree, i.e. without installing it.

# In CMake 3.14 and below the export(PACKAGE) command populated
# the user package registry by default and users needed to set
# the CMAKE_EXPORT_NO_PACKAGE_REGISTRY to disable it,
# e.g. in automated build and packaging environments. Since
# the user package registry is stored outside the build tree,
# this side effect should not be enabled by default.
# Therefore CMake 3.15 and above prefer that export(PACKAGE) does nothing
# unless an explicit CMAKE_EXPORT_PACKAGE_REGISTRY variable is set.
export(PACKAGE "${PROJECT_NAME}")

2 changes: 1 addition & 1 deletion cmake/check-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/check-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_NAME@-targets.cmake")

17 changes: 14 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ set(HEADERS

configure_file(check.h.in check.h @ONLY)

# To maintain compatibility with the Autotools installation
# we specifically create both shared and static libraries
# as that is what Autotools script has been doing.
# Normally CMake would create the system's native default library type.

add_library(check STATIC ${SOURCES} ${HEADERS})

# We would like to create an OBJECT library but currently they are
Expand Down Expand Up @@ -138,32 +143,38 @@ endif (MSVC)
# More configuration for exporting

set(LIBRARY_OUTPUT_NAME "check")
list(APPEND public_headers "${CMAKE_CURRENT_BINARY_DIR}/check.h")
list(APPEND public_headers "${CMAKE_BINARY_DIR}/check_stdint.h")

set_target_properties(check PROPERTIES
OUTPUT_NAME ${LIBRARY_OUTPUT_NAME}
PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h
PUBLIC_HEADER "${public_headers}"
)

if (MSVC)
# "On Windows you should probably give each library a different name,
# since there is a ".lib" file for both shared and static".
# https://stackoverflow.com/a/2152157/4716395
set(LIBRARY_OUTPUT_NAME "checkStatic")
# "Dynamic-Link Library" (DLL) is Microsoft terminology.
# So we call it this:
set(LIBRARY_OUTPUT_NAME "checkDynamic")
endif (MSVC)
set_target_properties(checkShared PROPERTIES
OUTPUT_NAME ${LIBRARY_OUTPUT_NAME}
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h
PUBLIC_HEADER "${public_headers}"
)
target_include_directories(check
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
target_include_directories(checkShared
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)

Expand Down

0 comments on commit 67c53e2

Please sign in to comment.