Skip to content

Commit

Permalink
Modify CMakeLists.txt
Browse files Browse the repository at this point in the history
* Add URL_INSTALL option to control the generation of the install target

* Rename library target to "upa_url"

* Use ${upa_url_lib} variable for library target name
  • Loading branch information
rmisev committed Sep 25, 2023
1 parent ffaba93 commit 7a8a86d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 66 deletions.
128 changes: 65 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ option(URL_BUILD_TESTS "Build the URL tests." ON)
option(URL_BUILD_FUZZER "Build the URL fuzzer." OFF)
option(URL_BUILD_EXAMPLES "Build the URL examples." OFF)
option(URL_BUILD_TOOLS "Build tools." OFF)
option(URL_INSTALL "Generate the install target." ON)
# library options
option(URL_AMALGAMATED "Use amalgamated URL library source." OFF)
# tests build options
Expand Down Expand Up @@ -76,36 +77,35 @@ if (URL_TEST_VALGRIND)
separate_arguments(MEMORYCHECK_COMMAND)
endif()

# are URL and ICU libraries needed
if (URL_BUILD_TESTS OR URL_BUILD_FUZZER OR URL_BUILD_EXAMPLES)
set(URL_USE_LIBS ON)
endif()

include_directories(deps)

if (URL_USE_LIBS)
# 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)

find_package(ICU REQUIRED COMPONENTS i18n uc)

if (URL_AMALGAMATED)
add_library(upaurl STATIC
add_library(${upa_url_lib} STATIC
single_include/upa/url.cpp)
target_include_directories(upaurl
target_include_directories(${upa_url_lib}
INTERFACE single_include)
else()
add_library(upaurl STATIC
add_library(${upa_url_lib} 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(upaurl PUBLIC
target_include_directories(${upa_url_lib} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
endif()
add_library(upa::url ALIAS upaurl)
target_include_directories(upaurl PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(upaurl INTERFACE ICU::i18n ICU::uc)
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)
endif()

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

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

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

# Example's targets

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

# Tool's targets
Expand All @@ -190,50 +190,52 @@ endif()

# Install

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

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

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

install(
EXPORT upaurl-targets
FILE upaurl-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/upaurl
)

# generate the config file that includes the exports
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/upaurl-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/upaurl-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/upaurl
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}/upaurl-config-version.cmake
COMPATIBILITY SameMinorVersion
)

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

# generate the export targets for the build tree
# needs to be after the install(TARGETS) command
export(
EXPORT upaurl-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/upaurl-targets.cmake
)
if (URL_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

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

install(
TARGETS ${upa_url_lib}
EXPORT ${upa_url_lib}-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}
)

# 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}
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
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}"
)

# 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
)
endif()
3 changes: 3 additions & 0 deletions cmake/upa_url-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

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

This file was deleted.

0 comments on commit 7a8a86d

Please sign in to comment.