Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Refactor targets export variable and improve comments #789

Merged
merged 4 commits into from Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions CMakeLists.txt
Expand Up @@ -48,6 +48,8 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# to distinguish between debug and release lib
set(CMAKE_DEBUG_POSTFIX "d")

set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets")

add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)

set_target_properties(tinyxml2 PROPERTIES
Expand All @@ -73,12 +75,13 @@ else()
endif(MSVC)
endif()

# export targets for find_package config mode
# Export cmake script that can be used by downstream project
# via `include()`
export(TARGETS tinyxml2
FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
FILE ${CMAKE_BINARY_DIR}/${TARGETS_EXPORT_NAME}.cmake)

install(TARGETS tinyxml2
EXPORT ${CMAKE_PROJECT_NAME}Targets
EXPORT ${TARGETS_EXPORT_NAME}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT tinyxml2_runtime
Expand Down Expand Up @@ -121,7 +124,6 @@ if(NOT TARGET uninstall)
endif()

include(CMakePackageConfigHelpers)
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
configure_package_config_file(
"Config.cmake.in"
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
Expand All @@ -138,6 +140,7 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
COMPONENT tinyxml2_config)

install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2::
# Export targets for find_package config mode
install(EXPORT ${TARGETS_EXPORT_NAME} NAMESPACE tinyxml2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
COMPONENT tinyxml2_config)