Commit f7228d77 authored by Corentin Le Molgat's avatar Corentin Le Molgat

Use CMake namespace gflags:: for export and alias target

Now use gflags::gflags instead of gflags

note: seems already in use in gRPC
cf https://github.com/grpc/grpc/blob/master/cmake/gflags.cmake#L30
parent 8b39845d
......@@ -14,9 +14,9 @@
##
## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
## settings are such that only the static single-threaded library is built without
## installation of the gflags files. The "gflags" target is in this case an ALIAS
## installation of the gflags files. The "gflags::gflags" target is in this case an ALIAS
## library target for the "gflags_nothreads_static" library target. Targets which
## depend on the gflags library should link to the "gflags" library target.
## depend on the gflags library should link to the "gflags::gflags" library target.
##
## Example CMakeLists.txt of user project which requires separate gflags installation:
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
......@@ -26,7 +26,7 @@
## find_package(gflags REQUIRED)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## target_link_libraries(foo gflags::gflags)
##
## Example CMakeLists.txt of user project which requires separate single-threaded static gflags installation:
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
......@@ -36,7 +36,7 @@
## find_package(gflags COMPONENTS nothreads_static)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## target_link_libraries(foo gflags::gflags)
##
## Example CMakeLists.txt of super-project which contains gflags source tree:
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
......@@ -46,7 +46,7 @@
## add_subdirectory(gflags)
##
## add_executable(foo src/foo.cc)
## target_link_libraries(foo gflags)
## target_link_libraries(foo gflags::gflags)
##
## Variables to configure the source files:
## - GFLAGS_IS_A_DLL
......@@ -495,11 +495,11 @@ if (GFLAGS_IS_SUBPROJECT)
foreach (type IN ITEMS static shared)
foreach (opts IN ITEMS "_nothreads" "")
if (TARGET gflags${opts}_${type})
add_library (gflags ALIAS gflags${opts}_${type})
add_library (gflags::gflags ALIAS gflags${opts}_${type})
break ()
endif ()
endforeach ()
if (TARGET gflags)
if (TARGET gflags::gflags)
break ()
endif ()
endforeach ()
......@@ -546,7 +546,11 @@ if (INSTALL_HEADERS)
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (EXPORT ${EXPORT_NAME} DESTINATION ${CONFIG_INSTALL_DIR})
install (
EXPORT ${EXPORT_NAME}
DESTINATION ${CONFIG_INSTALL_DIR}
NAMESPACE gflags::
)
if (UNIX)
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
endif ()
......@@ -560,7 +564,10 @@ endif ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS ${TARGETS} FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake")
export (
TARGETS ${TARGETS}
NAMESPACE gflags::
FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake")
if (REGISTER_BUILD_DIR)
export (PACKAGE ${PACKAGE_NAME})
endif ()
......
......@@ -49,7 +49,7 @@ if (NOT DEFINED @PACKAGE_PREFIX@_SHARED)
else ()
set (@PACKAGE_PREFIX@_SHARED FALSE)
endif ()
elseif (TARGET @PACKAGE_NAME@_shared OR TARGET @PACKAGE_NAME@_nothreads_shared)
elseif (TARGET gflags::@PACKAGE_NAME@_shared OR TARGET gflags::@PACKAGE_NAME@_nothreads_shared)
set (@PACKAGE_PREFIX@_SHARED TRUE)
else ()
set (@PACKAGE_PREFIX@_SHARED FALSE)
......@@ -64,7 +64,7 @@ if (NOT DEFINED @PACKAGE_PREFIX@_NOTHREADS)
else ()
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
endif ()
elseif (TARGET @PACKAGE_NAME@_static OR TARGET @PACKAGE_NAME@_shared)
elseif (TARGET gflags::@PACKAGE_NAME@_static OR TARGET gflags::@PACKAGE_NAME@_shared)
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
else ()
set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
......@@ -77,15 +77,15 @@ if (NOT @PACKAGE_PREFIX@_TARGET)
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_NAME@_TARGET})
elseif (@PACKAGE_PREFIX@_SHARED)
if (@PACKAGE_PREFIX@_NOTHREADS)
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_shared)
set (@PACKAGE_PREFIX@_TARGET gflags::@PACKAGE_NAME@_nothreads_shared)
else ()
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_shared)
set (@PACKAGE_PREFIX@_TARGET gflags::@PACKAGE_NAME@_shared)
endif ()
else ()
if (@PACKAGE_PREFIX@_NOTHREADS)
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_nothreads_static)
set (@PACKAGE_PREFIX@_TARGET gflags::@PACKAGE_NAME@_nothreads_static)
else ()
set (@PACKAGE_PREFIX@_TARGET @PACKAGE_NAME@_static)
set (@PACKAGE_PREFIX@_TARGET gflags::@PACKAGE_NAME@_static)
endif ()
endif ()
endif ()
......@@ -94,12 +94,12 @@ if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET})
" Try a different combination of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS.")
endif ()
# add more convenient "@PACKAGE_NAME@" import target
if (NOT TARGET @PACKAGE_NAME@)
# add more convenient "gflags::@PACKAGE_NAME@" import target
if (NOT TARGET gflags::@PACKAGE_NAME@)
if (@PACKAGE_PREFIX@_SHARED)
add_library (@PACKAGE_NAME@ SHARED IMPORTED)
add_library (gflags::@PACKAGE_NAME@ SHARED IMPORTED)
else ()
add_library (@PACKAGE_NAME@ STATIC IMPORTED)
add_library (gflags::@PACKAGE_NAME@ STATIC IMPORTED)
endif ()
# copy INTERFACE_* properties
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
......@@ -112,20 +112,20 @@ if (NOT TARGET @PACKAGE_NAME@)
)
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME})
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
set_target_properties(@PACKAGE_NAME@ PROPERTIES
set_target_properties(gflags::@PACKAGE_NAME@ PROPERTIES
INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
)
endif ()
endforeach ()
# copy IMPORTED_*_<CONFIG> properties
get_target_property (_@PACKAGE_PREFIX@_CONFIGURATIONS ${@PACKAGE_PREFIX@_TARGET} IMPORTED_CONFIGURATIONS)
set_target_properties (@PACKAGE_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_PREFIX@_CONFIGURATIONS}")
set_target_properties (gflags::@PACKAGE_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_PREFIX@_CONFIGURATIONS}")
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
IMPLIB
LOCATION
LINK_DEPENDENT_LIBRARIES
LINK_INTERFACE_LIBRARIES
LINK_INTERFACE_LANGUAGES
LINK_INTERFACE_LANGUAGES
LINK_INTERFACE_MULTIPLICITY
NO_SONAME
SONAME
......@@ -133,7 +133,7 @@ if (NOT TARGET @PACKAGE_NAME@)
foreach (_@PACKAGE_PREFIX@_CONFIG IN LISTS _@PACKAGE_PREFIX@_CONFIGURATIONS)
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG})
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
set_target_properties(@PACKAGE_NAME@ PROPERTIES
set_target_properties(gflags::@PACKAGE_NAME@ PROPERTIES
IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
)
endif ()
......
......@@ -7,4 +7,4 @@ project (gflags_${TEST_NAME})
find_package (gflags REQUIRED)
add_executable (foo main.cc)
target_link_libraries (foo gflags)
target_link_libraries (foo gflags::gflags)
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