CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. set(LIB_NAME libcurl)
  25. set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library")
  26. add_definitions(-DBUILDING_LIBCURL)
  27. if(BUILD_SHARED_LIBS)
  28. set(CURL_STATICLIB NO)
  29. else()
  30. set(CURL_STATICLIB YES)
  31. endif()
  32. # Use:
  33. # * CURL_STATICLIB
  34. configure_file(curl_config.h.cmake
  35. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
  36. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  37. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
  38. list(APPEND HHEADERS
  39. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
  40. )
  41. if(WIN32 AND NOT CURL_STATICLIB)
  42. list(APPEND CSOURCES libcurl.rc)
  43. endif()
  44. # SET(CSOURCES
  45. # # memdebug.c -not used
  46. # # nwlib.c - Not used
  47. # # strtok.c - specify later
  48. # # strtoofft.c - specify later
  49. # )
  50. # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
  51. # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
  52. # IF(CURL_MALLOC_DEBUG)
  53. # SET(CSOURCES ${CSOURCES}
  54. # memdebug.c
  55. # )
  56. # ENDIF(CURL_MALLOC_DEBUG)
  57. # # only build compat strtoofft if we need to
  58. # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  59. # SET(CSOURCES ${CSOURCES}
  60. # strtoofft.c
  61. # )
  62. # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  63. # The rest of the build
  64. include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
  65. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
  66. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
  67. include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
  68. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  69. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  70. if(USE_ARES)
  71. include_directories(${CARES_INCLUDE_DIR})
  72. endif()
  73. add_library(
  74. ${LIB_NAME}
  75. ${HHEADERS} ${CSOURCES}
  76. )
  77. add_library(
  78. ${PROJECT_NAME}::${LIB_NAME}
  79. ALIAS ${LIB_NAME}
  80. )
  81. if(NOT BUILD_SHARED_LIBS)
  82. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  83. endif()
  84. target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
  85. set_target_properties(${LIB_NAME} PROPERTIES
  86. COMPILE_DEFINITIONS BUILDING_LIBCURL
  87. OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
  88. )
  89. if(HIDES_CURL_PRIVATE_SYMBOLS)
  90. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  91. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  92. endif()
  93. # Remove the "lib" prefix since the library is already named "libcurl".
  94. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  95. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  96. if(CURL_HAS_LTO)
  97. set_target_properties(${LIB_NAME} PROPERTIES
  98. INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
  99. INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
  100. endif()
  101. if(WIN32)
  102. if(BUILD_SHARED_LIBS)
  103. if(MSVC)
  104. # Add "_imp" as a suffix before the extension to avoid conflicting with
  105. # the statically linked "libcurl.lib"
  106. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  107. endif()
  108. endif()
  109. endif()
  110. target_include_directories(${LIB_NAME} INTERFACE
  111. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  112. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  113. if(CURL_ENABLE_EXPORT_TARGET)
  114. install(TARGETS ${LIB_NAME}
  115. EXPORT ${TARGETS_EXPORT_NAME}
  116. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  117. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  118. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  119. )
  120. export(TARGETS ${LIB_NAME}
  121. FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  122. NAMESPACE ${PROJECT_NAME}::
  123. )
  124. endif()