"Fossies" - the Fresh Open Source Software Archive

Member "uriparser-0.9.5/CMakeLists.txt" (18 Mar 2021, 15356 Bytes) of package /linux/www/uriparser-0.9.5.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "CMakeLists.txt": 0.9.4_vs_0.9.5.

    1 # uriparser - RFC 3986 URI parsing library
    2 #
    3 # Copyright (C) 2018, Sebastian Pipping <sebastian@pipping.org>
    4 # All rights reserved.
    5 #
    6 # Redistribution and use in source  and binary forms, with or without
    7 # modification, are permitted provided  that the following conditions
    8 # are met:
    9 #
   10 #     1. Redistributions  of  source  code   must  retain  the  above
   11 #        copyright notice, this list  of conditions and the following
   12 #        disclaimer.
   13 #
   14 #     2. Redistributions  in binary  form  must  reproduce the  above
   15 #        copyright notice, this list  of conditions and the following
   16 #        disclaimer  in  the  documentation  and/or  other  materials
   17 #        provided with the distribution.
   18 #
   19 #     3. Neither the  name of the  copyright holder nor the  names of
   20 #        its contributors may be used  to endorse or promote products
   21 #        derived from  this software  without specific  prior written
   22 #        permission.
   23 #
   24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   25 # "AS IS" AND  ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT
   26 # LIMITED TO,  THE IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS
   27 # FOR  A  PARTICULAR  PURPOSE  ARE  DISCLAIMED.  IN  NO  EVENT  SHALL
   28 # THE  COPYRIGHT HOLDER  OR CONTRIBUTORS  BE LIABLE  FOR ANY  DIRECT,
   29 # INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   30 # (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS OR
   31 # SERVICES; LOSS OF USE, DATA,  OR PROFITS; OR BUSINESS INTERRUPTION)
   32 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   33 # STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
   34 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   35 # OF THE POSSIBILITY OF SUCH DAMAGE.
   36 #
   37 cmake_minimum_required(VERSION 3.3)
   38 
   39 project(uriparser
   40     VERSION
   41         0.9.5
   42     LANGUAGES
   43         C
   44 )
   45 
   46 # See https://verbump.de/ for what these numbers do
   47 set(URIPARSER_SO_CURRENT    1)
   48 set(URIPARSER_SO_REVISION  28)
   49 set(URIPARSER_SO_AGE        0)
   50 
   51 include(CheckCCompilerFlag)
   52 include(CheckFunctionExists)
   53 include(CheckLibraryExists)
   54 include(CheckSymbolExists)
   55 include(CMakePackageConfigHelpers)
   56 include(GNUInstallDirs)
   57 
   58 #
   59 # Configuration
   60 #
   61 option(BUILD_SHARED_LIBS "Build shared libraries (rather than static ones)" ON)
   62 option(URIPARSER_BUILD_DOCS "Build API documentation (requires Doxygen, Graphviz, and (optional) Qt's qhelpgenerator)" ON)
   63 option(URIPARSER_BUILD_TESTS "Build test suite (requires GTest >=1.8.0)" ON)
   64 option(URIPARSER_BUILD_TOOLS "Build tools (e.g. CLI \"uriparse\")" ON)
   65 option(URIPARSER_BUILD_CHAR "Build code supporting data type 'char'" ON)
   66 option(URIPARSER_BUILD_WCHAR_T "Build code supporting data type 'wchar_t'" ON)
   67 option(URIPARSER_ENABLE_INSTALL "Enable installation of uriparser" ON)
   68 option(URIPARSER_WARNINGS_AS_ERRORS "Treat all compiler warnings as errors" OFF)
   69 set(URIPARSER_MSVC_RUNTIME "" CACHE STRING "Use of specific runtime library (/MT /MTd /MD /MDd) with MSVC")
   70 
   71 if(NOT URIPARSER_BUILD_CHAR AND NOT URIPARSER_BUILD_WCHAR_T)
   72     message(SEND_ERROR "One or more of URIPARSER_BUILD_CHAR and URIPARSER_BUILD_WCHAR_T needs to be enabled.")
   73 endif()
   74 if(URIPARSER_BUILD_TESTS AND NOT (URIPARSER_BUILD_CHAR AND URIPARSER_BUILD_WCHAR_T))
   75     message(SEND_ERROR "URIPARSER_BUILD_TESTS=ON requires both URIPARSER_BUILD_CHAR=ON and URIPARSER_BUILD_WCHAR_T=ON.")
   76 endif()
   77 if(URIPARSER_BUILD_TOOLS AND NOT URIPARSER_BUILD_CHAR)
   78     message(SEND_ERROR "URIPARSER_BUILD_TOOLS=ON requires URIPARSER_BUILD_CHAR=ON.")
   79 endif()
   80 
   81 macro(uriparser_apply_msvc_runtime_to ref)
   82     string(REGEX REPLACE "/M[DT]d?" ${URIPARSER_MSVC_RUNTIME} ${ref} "${${ref}}")
   83 endmacro()
   84 
   85 if(MSVC AND URIPARSER_MSVC_RUNTIME)
   86     uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS)
   87     uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS_DEBUG)
   88     uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS_RELEASE)
   89 endif()
   90 
   91 macro(uriparser_install)
   92     if(URIPARSER_ENABLE_INSTALL)
   93         install(${ARGN})
   94     endif()
   95 endmacro()
   96 
   97 #
   98 # Compiler checks
   99 #
  100 set(URIPARSER_EXTRA_COMPILE_FLAGS)
  101 
  102 check_c_compiler_flag("-fvisibility=hidden" URIPARSER_COMPILER_SUPPORTS_VISIBILITY)
  103 if(URIPARSER_COMPILER_SUPPORTS_VISIBILITY)
  104     set(URIPARSER_EXTRA_COMPILE_FLAGS "${URIPARSER_EXTRA_COMPILE_FLAGS} -fvisibility=hidden")
  105 endif()
  106 
  107 if(URIPARSER_WARNINGS_AS_ERRORS)
  108     if(MSVC)
  109         add_definitions(/WX)
  110     else()
  111         set(URIPARSER_EXTRA_COMPILE_FLAGS "${URIPARSER_EXTRA_COMPILE_FLAGS} -Werror")
  112     endif()
  113 endif()
  114 
  115 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${URIPARSER_EXTRA_COMPILE_FLAGS}")
  116 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${URIPARSER_EXTRA_COMPILE_FLAGS}")
  117 
  118 #
  119 # config.h
  120 #
  121 check_symbol_exists(wprintf wchar.h HAVE_WPRINTF)
  122 check_function_exists(reallocarray HAVE_REALLOCARRAY)  # no luck with CheckSymbolExists
  123 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/UriConfig.h.in config.h)
  124 
  125 #
  126 # C library
  127 #
  128 set(API_HEADER_FILES
  129     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/UriBase.h
  130     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/UriDefsAnsi.h
  131     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/UriDefsConfig.h
  132     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/UriDefsUnicode.h
  133     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/Uri.h
  134     ${CMAKE_CURRENT_SOURCE_DIR}/include/uriparser/UriIp4.h
  135 )
  136 set(LIBRARY_CODE_FILES
  137     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriCommon.c
  138     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriCommon.h
  139     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriCompare.c
  140     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriEscape.c
  141     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriFile.c
  142     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriIp4Base.c
  143     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriIp4Base.h
  144     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriIp4.c
  145     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriMemory.c
  146     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriMemory.h
  147     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriNormalizeBase.c
  148     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriNormalizeBase.h
  149     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriNormalize.c
  150     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriParseBase.c
  151     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriParseBase.h
  152     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriParse.c
  153     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriQuery.c
  154     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriRecompose.c
  155     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriResolve.c
  156     ${CMAKE_CURRENT_SOURCE_DIR}/src/UriShorten.c
  157 )
  158 
  159 add_library(uriparser
  160     ${API_HEADER_FILES}
  161     ${LIBRARY_CODE_FILES}
  162 )
  163 
  164 if(NOT MSVC)
  165     math(EXPR URIPARSER_SO_CURRENT_MINUS_AGE "${URIPARSER_SO_CURRENT} - ${URIPARSER_SO_AGE}")
  166     set_property(TARGET uriparser PROPERTY VERSION ${URIPARSER_SO_CURRENT_MINUS_AGE}.${URIPARSER_SO_AGE}.${URIPARSER_SO_REVISION})
  167     set_property(TARGET uriparser PROPERTY SOVERSION ${URIPARSER_SO_CURRENT_MINUS_AGE})
  168     if(WIN32)
  169         set_target_properties(uriparser PROPERTIES
  170             OUTPUT_NAME uriparser
  171             RUNTIME_OUTPUT_NAME uriparser-${URIPARSER_SO_CURRENT_MINUS_AGE}
  172             ARCHIVE_OUTPUT_NAME uriparser)
  173     endif()
  174 endif()
  175 
  176 set_property(
  177     TARGET
  178         uriparser
  179     PROPERTY
  180         PUBLIC_HEADER "${API_HEADER_FILES}"
  181 )
  182 
  183 target_compile_definitions(uriparser PRIVATE URI_LIBRARY_BUILD)
  184 if (NOT BUILD_SHARED_LIBS)
  185     target_compile_definitions(uriparser PUBLIC URI_STATIC_BUILD)
  186 endif()
  187 if(NOT URIPARSER_BUILD_CHAR)
  188     target_compile_definitions(uriparser PUBLIC URI_NO_ANSI)
  189 endif()
  190 if(NOT URIPARSER_BUILD_WCHAR_T)
  191     target_compile_definitions(uriparser PUBLIC URI_NO_UNICODE)
  192 endif()
  193 if(URIPARSER_COMPILER_SUPPORTS_VISIBILITY)
  194     target_compile_definitions(uriparser PRIVATE URI_VISIBILITY)
  195 endif()
  196 
  197 target_include_directories(uriparser
  198     PUBLIC
  199         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  200         $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  201     PRIVATE
  202         ${CMAKE_CURRENT_BINARY_DIR}  # for config.h
  203 )
  204 
  205 uriparser_install(
  206     TARGETS
  207         uriparser
  208     EXPORT
  209         uriparser
  210     ARCHIVE
  211         DESTINATION
  212             ${CMAKE_INSTALL_LIBDIR}
  213     LIBRARY
  214         DESTINATION
  215             ${CMAKE_INSTALL_LIBDIR}
  216     RUNTIME
  217         DESTINATION
  218             ${CMAKE_INSTALL_BINDIR}
  219     PUBLIC_HEADER
  220         DESTINATION
  221             ${CMAKE_INSTALL_INCLUDEDIR}/uriparser
  222 )
  223 
  224 #
  225 # C command line tool
  226 #
  227 if(URIPARSER_BUILD_TOOLS)
  228     add_executable(uriparse
  229         ${CMAKE_CURRENT_SOURCE_DIR}/tool/uriparse.c
  230     )
  231 
  232     target_link_libraries(uriparse PUBLIC uriparser)
  233 
  234     if(HAIKU)
  235         # Function inet_ntop needs -lsocket or -lnetwork (see pull request #45)
  236         check_library_exists(socket inet_ntop "" HAVE_LIBSOCKET__INET_NTOP)
  237         check_library_exists(network inet_ntop "" HAVE_LIBNETWORK__INET_NTOP)
  238         if(HAVE_LIBSOCKET__INET_NTOP)
  239             target_link_libraries(uriparse PUBLIC socket)
  240         endif()
  241         if(HAVE_LIBNETWORK__INET_NTOP)
  242             target_link_libraries(uriparse PUBLIC network)
  243         endif()
  244     endif()
  245 
  246     if(WIN32)
  247         target_link_libraries(uriparse PUBLIC ws2_32)
  248     endif()
  249 
  250     uriparser_install(
  251         TARGETS
  252             uriparse
  253         DESTINATION
  254             ${CMAKE_INSTALL_BINDIR}
  255     )
  256 endif()
  257 
  258 #
  259 # C++ test runner
  260 #
  261 if(URIPARSER_BUILD_TESTS)
  262     enable_language(CXX)
  263 
  264     if(MSVC AND URIPARSER_MSVC_RUNTIME)
  265         uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS)
  266         uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS_DEBUG)
  267         uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS_RELEASE)
  268     endif()
  269 
  270     enable_testing()
  271 
  272     find_package(GTest 1.8.0 REQUIRED)
  273 
  274     add_executable(testrunner
  275         ${CMAKE_CURRENT_SOURCE_DIR}/test/FourSuite.cpp
  276         ${CMAKE_CURRENT_SOURCE_DIR}/test/MemoryManagerSuite.cpp
  277         ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp
  278         ${CMAKE_CURRENT_SOURCE_DIR}/test/VersionSuite.cpp
  279 
  280         # These library code files have non-public symbols that the test suite
  281         # needs to link to, so they appear here as well:
  282         ${API_HEADER_FILES}
  283         ${LIBRARY_CODE_FILES}
  284     )
  285 
  286     target_compile_definitions(testrunner PRIVATE URI_STATIC_BUILD)
  287 
  288     if(MSVC)
  289         target_compile_definitions(testrunner PRIVATE -D_CRT_SECURE_NO_WARNINGS)
  290     endif()
  291 
  292     target_include_directories(testrunner SYSTEM PRIVATE
  293         ${GTEST_INCLUDE_DIRS}
  294     )
  295 
  296     target_include_directories(testrunner PRIVATE
  297         ${CMAKE_CURRENT_SOURCE_DIR}/include
  298         ${CMAKE_CURRENT_BINARY_DIR}  # for config.h
  299     )
  300 
  301     target_link_libraries(testrunner PUBLIC
  302         ${GTEST_BOTH_LIBRARIES}
  303     )
  304 
  305     # NOTE: uriparser does not use pthreads itself but gtest does
  306     find_package(Threads REQUIRED)
  307     target_link_libraries(testrunner PRIVATE Threads::Threads)
  308 
  309     if(MSVC)
  310         # Specify unwind semantics so that MSVC knowns how to handle exceptions
  311         target_compile_options(testrunner PRIVATE /EHsc)
  312     endif()
  313 
  314     add_test(
  315         NAME
  316             test
  317         COMMAND
  318             testrunner
  319     )
  320 
  321     add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
  322 endif()
  323 
  324 #
  325 # Doxygen API documentation
  326 #
  327 if(URIPARSER_BUILD_DOCS)
  328     find_package(Doxygen REQUIRED dot doxygen)
  329 
  330     set(QHG_LOCATION "" CACHE FILEPATH "Path to qhelpgenerator program (default: auto-detect)")
  331     if(NOT QHG_LOCATION)
  332         find_package(Qt5Help QUIET)
  333         if(TARGET Qt5::qhelpgenerator)
  334             get_target_property(QHG_LOCATION Qt5::qhelpgenerator LOCATION)
  335             mark_as_advanced(Qt5Core_DIR)
  336             mark_as_advanced(Qt5Gui_DIR)
  337             mark_as_advanced(Qt5Help_DIR)
  338             mark_as_advanced(Qt5Sql_DIR)
  339             mark_as_advanced(Qt5Widgets_DIR)
  340         endif()
  341     endif()
  342 
  343     include(FindHTMLHelp)
  344 
  345     # Generate Doxyfile
  346     if(HTML_HELP_COMPILER)
  347         set(GENERATE_HTMLHELP YES)
  348     else()
  349         set(GENERATE_HTMLHELP NO)
  350     endif()
  351     if(QHG_LOCATION)
  352         set(GENERATE_QHP YES)
  353     else()
  354         set(GENERATE_QHP NO)
  355     endif()
  356     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in doc/Doxyfile @ONLY)
  357     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/release.sh.in doc/release.sh @ONLY)
  358 
  359     add_custom_target(doc
  360         ALL
  361         COMMAND
  362             ${DOXYGEN_EXECUTABLE}
  363             Doxyfile
  364         WORKING_DIRECTORY
  365             ${CMAKE_CURRENT_BINARY_DIR}/doc
  366         COMMENT
  367             "Generating API documentation with Doxygen"
  368         VERBATIM
  369     )
  370 
  371     uriparser_install(
  372         DIRECTORY
  373             ${CMAKE_CURRENT_BINARY_DIR}/doc/html
  374         DESTINATION
  375             ${CMAKE_INSTALL_DOCDIR}
  376     )
  377     if(QHG_LOCATION)
  378         uriparser_install(
  379             FILES
  380                 ${CMAKE_CURRENT_BINARY_DIR}/doc/uriparser-${PROJECT_VERSION}.qch
  381             DESTINATION
  382                 ${CMAKE_INSTALL_DOCDIR}
  383         )
  384     endif()
  385 endif()
  386 
  387 #
  388 # CMake files for find_package(uriparser [..] CONFIG [..])
  389 #
  390 configure_package_config_file(
  391         ${CMAKE_CURRENT_SOURCE_DIR}/cmake/uriparser-config.cmake.in
  392         cmake/uriparser-config.cmake
  393     INSTALL_DESTINATION
  394         ${CMAKE_INSTALL_LIBDIR}/cmake/uriparser-${PROJECT_VERSION}/
  395 )
  396 write_basic_package_version_file(
  397     cmake/uriparser-config-version.cmake
  398     COMPATIBILITY SameMajorVersion  # i.e. semver
  399 )
  400 export(
  401     TARGETS
  402         uriparser
  403     FILE
  404         cmake/uriparser-targets.cmake  # not going to be installed
  405 )
  406 uriparser_install(
  407     FILES
  408         ${CMAKE_CURRENT_BINARY_DIR}/cmake/uriparser-config.cmake
  409         ${CMAKE_CURRENT_BINARY_DIR}/cmake/uriparser-config-version.cmake
  410     DESTINATION
  411         ${CMAKE_INSTALL_LIBDIR}/cmake/uriparser-${PROJECT_VERSION}/
  412 )
  413 uriparser_install(
  414     EXPORT
  415         uriparser
  416     DESTINATION
  417         ${CMAKE_INSTALL_LIBDIR}/cmake/uriparser-${PROJECT_VERSION}/
  418     NAMESPACE
  419         uriparser::
  420 )
  421 
  422 #
  423 # pkg-config file
  424 #
  425 if(NOT MSVC)
  426     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/liburiparser.pc.in liburiparser.pc @ONLY)
  427     uriparser_install(
  428         FILES
  429             ${CMAKE_CURRENT_BINARY_DIR}/liburiparser.pc
  430         DESTINATION
  431             ${CMAKE_INSTALL_LIBDIR}/pkgconfig/
  432     )
  433 endif()
  434 
  435 #
  436 # Summary
  437 #
  438 message(STATUS "===========================================================================")
  439 message(STATUS "")
  440 message(STATUS "Configuration")
  441 message(STATUS "  Build type ............. ${CMAKE_BUILD_TYPE}")
  442 message(STATUS "  Shared libraries ....... ${BUILD_SHARED_LIBS}")
  443 message(STATUS "  Compiler flags")
  444 message(STATUS "    C .................... ${CMAKE_C_FLAGS}")
  445 message(STATUS "    C++ .................. ${CMAKE_CXX_FLAGS}")
  446 message(STATUS "  Linker flags")
  447 message(STATUS "    Executable ........... ${CMAKE_EXE_LINKER_FLAGS}")
  448 message(STATUS "    Module ............... ${CMAKE_MODULE_LINKER_FLAGS}")
  449 message(STATUS "    Shared ............... ${CMAKE_SHARED_LINKER_FLAGS}")
  450 message(STATUS "  Paths")
  451 message(STATUS "    Prefix ............... ${CMAKE_INSTALL_PREFIX}")
  452 message(STATUS "    qhelpgenerator ....... ${QHG_LOCATION}")
  453 message(STATUS "")
  454 message(STATUS "  Features")
  455 message(STATUS "    Code for char * ...... ${URIPARSER_BUILD_CHAR}")
  456 message(STATUS "    Code for wchar_t * ... ${URIPARSER_BUILD_WCHAR_T}")
  457 message(STATUS "    Tools ................ ${URIPARSER_BUILD_TOOLS}")
  458 message(STATUS "    Test suite ........... ${URIPARSER_BUILD_TESTS}")
  459 message(STATUS "    Documentation ........ ${URIPARSER_BUILD_DOCS}")
  460 message(STATUS "")
  461 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  462     message(STATUS "Continue with")
  463     message(STATUS "  make")
  464     message(STATUS "  make test")
  465     message(STATUS "  sudo make install")
  466     message(STATUS "")
  467 endif()
  468 message(STATUS "===========================================================================")