From e86e947cb2930baa87a845041f438a62f709a9f3 Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Tue, 3 Dec 2019 17:09:24 -0500 Subject: [PATCH 1/4] cmake: Use CMAKE_PROJECT_NAME instead of PROJECT_NAME This is consistent with other usages of the file. PROJECT_NAME is only useful if there are subprojects, and there aren't any here. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67c1a0f..8abaf59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,7 @@ if(NOT TARGET uninstall) endif() include(CMakePackageConfigHelpers) -set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets") configure_package_config_file( "Config.cmake.in" "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake" From 57cd52b0462864fa3adad13bb1833ed28d797274 Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Tue, 3 Dec 2019 17:11:43 -0500 Subject: [PATCH 2/4] cmake: Use TARGETS_EXPORT_NAME var throughout file Previously, it was totally unused. --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8abaf59..f072108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,12 +73,14 @@ else() endif(MSVC) endif() +set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets") + # export targets for find_package config mode 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 @@ -121,7 +123,6 @@ if(NOT TARGET uninstall) endif() include(CMakePackageConfigHelpers) -set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets") configure_package_config_file( "Config.cmake.in" "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake" @@ -138,6 +139,6 @@ install(FILES DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} COMPONENT tinyxml2_config) -install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2:: +install(EXPORT ${TARGETS_EXPORT_NAME} NAMESPACE tinyxml2:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} COMPONENT tinyxml2_config) From 588c6577dd04a62b3a082702e110b40d5be4e728 Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Tue, 3 Dec 2019 22:27:03 +0000 Subject: [PATCH 3/4] cmake: Clarify comment around exported cmake script The `export()` command purely exports a cmake script into the build directory; it is not related to find_package at all. It is technically not necessary. The main use case would be a user copying it into their internal cmake/ dir in their project, and then using `include()`'ing that file in their cmake. The `install(EXPORT...` command is what actually generates a cmake module that is put on the filesystem in a location that can be found by `find_package` when in config mode. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f072108..584f02a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,8 @@ endif() set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets") -# 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}/${TARGETS_EXPORT_NAME}.cmake) @@ -139,6 +140,7 @@ install(FILES DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} COMPONENT tinyxml2_config) +# 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) From 60e96163cad7e38ee03e89cb00451f9f3d8b76b1 Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Tue, 3 Dec 2019 22:35:33 +0000 Subject: [PATCH 4/4] cmake: Move TARGETS_EXPORT_NAME to top --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 584f02a..6247593 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -73,8 +75,6 @@ else() endif(MSVC) endif() -set(TARGETS_EXPORT_NAME "${CMAKE_PROJECT_NAME}Targets") - # Export cmake script that can be used by downstream project # via `include()` export(TARGETS tinyxml2