Skip to content

Commit

Permalink
Rename CMake package name to upa, and add NAMESPACE upa::
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Sep 28, 2023
1 parent 47a0a18 commit be58fe0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
66 changes: 38 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ endif()

# Project settings
project(upa_url VERSION 0.0.1 LANGUAGES CXX)
# The ${lib_name} is used to create the config file name: ${lib_name}-config.cmake
# It also must be used as the package name argument to find_package
set(lib_name upa)
# The ${lib_target} is used to create an alias target: upa::${lib_target}
set(lib_target url)
# The ${upa_url_lib} is used to create the library filename
set(upa_url_lib upa_${lib_target})

set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard")

# Upa URL is top level project?
Expand Down Expand Up @@ -89,31 +97,31 @@ include_directories(deps)

# Are Upa URL and ICU libraries needed?
if (URL_BUILD_TESTS OR URL_BUILD_FUZZER OR URL_BUILD_EXAMPLES OR URL_INSTALL OR NOT URL_BUILD_TOOLS)
# Upa URL library name
set(upa_url_lib upa_url)

# This library depends on ICU
find_package(ICU REQUIRED COMPONENTS i18n uc)

if (URL_AMALGAMATED)
add_library(${upa_url_lib} STATIC
add_library(${lib_target} STATIC
single_include/upa/url.cpp)
target_include_directories(${upa_url_lib}
target_include_directories(${lib_target}
INTERFACE single_include)
else()
add_library(${upa_url_lib} STATIC
add_library(${lib_target} STATIC
src/url.cpp
src/url_idna.cpp
src/url_ip.cpp
src/url_percent_encode.cpp
src/url_search_params.cpp
src/url_utf.cpp)
target_include_directories(${upa_url_lib} PUBLIC
target_include_directories(${lib_target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
endif()
add_library(upa::url ALIAS ${upa_url_lib})
target_include_directories(${upa_url_lib} PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(${upa_url_lib} INTERFACE ICU::i18n ICU::uc)
add_library(upa::${lib_target} ALIAS ${lib_target})
set_target_properties(${lib_target} PROPERTIES
OUTPUT_NAME ${upa_url_lib})
target_include_directories(${lib_target} PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(${lib_target} INTERFACE ICU::i18n ICU::uc)
endif()

# Test targets
Expand Down Expand Up @@ -149,7 +157,7 @@ if (URL_BUILD_TESTS)
get_filename_component(test_name ${file} NAME_WE)

add_executable(${test_name} ${file})
target_link_libraries(${test_name} ${upa_url_lib})
target_link_libraries(${test_name} ${lib_target})

add_test(NAME ${test_name}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
Expand Down Expand Up @@ -177,15 +185,15 @@ if (URL_BUILD_FUZZER)
else()
add_executable(${fuzz_name} ${file})
endif()
target_link_libraries(${fuzz_name} ${upa_url_lib})
target_link_libraries(${fuzz_name} ${lib_target})
endforeach()
endif()

# Example's targets

if (URL_BUILD_EXAMPLES)
add_executable(urlparse examples/urlparse.cpp)
target_link_libraries(urlparse ${upa_url_lib})
target_link_libraries(urlparse ${lib_target})
endif()

# Tool's targets
Expand All @@ -203,47 +211,49 @@ if (URL_INSTALL AND NOT URL_AMALGAMATED)
include(CMakePackageConfigHelpers)

install(
DIRECTORY include/upa
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
TARGETS ${upa_url_lib}
EXPORT ${upa_url_lib}-targets
TARGETS ${lib_target}
EXPORT ${lib_target}-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
EXPORT ${upa_url_lib}-targets
FILE ${upa_url_lib}-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${upa_url_lib}
EXPORT ${lib_target}-targets
FILE ${lib_name}-targets.cmake
NAMESPACE upa::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${lib_name}
)

# generate the config file that includes the exports
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${upa_url_lib}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${upa_url_lib}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${upa_url_lib}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${lib_name}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${lib_name}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# generate the version file for the config file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${upa_url_lib}-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}-config-version.cmake
COMPATIBILITY SameMinorVersion
)

# install the generated configuration files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${upa_url_lib}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${upa_url_lib}-config-version.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${upa_url_lib}"
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${lib_name}
)

# generate the export targets for the build tree
# needs to be after the install(TARGETS) command
export(
EXPORT ${upa_url_lib}-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/${upa_url_lib}-targets.cmake
EXPORT ${lib_target}-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}-targets.cmake
NAMESPACE upa::
)
endif()
6 changes: 6 additions & 0 deletions cmake/upa-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(ICU REQUIRED COMPONENTS i18n uc)

include("${CMAKE_CURRENT_LIST_DIR}/upa-targets.cmake")
3 changes: 0 additions & 3 deletions cmake/upa_url-config.cmake.in

This file was deleted.

0 comments on commit be58fe0

Please sign in to comment.