CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2021, 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. ###########################################################################
  22. set(LIB_NAME libcurl)
  23. set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library")
  24. if(BUILD_SHARED_LIBS)
  25. set(CURL_STATICLIB NO)
  26. else()
  27. set(CURL_STATICLIB YES)
  28. endif()
  29. # Use:
  30. # * CURL_STATICLIB
  31. configure_file(curl_config.h.cmake
  32. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
  33. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  34. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
  35. list(APPEND HHEADERS
  36. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
  37. )
  38. if(WIN32)
  39. list(APPEND CSOURCES libcurl.rc)
  40. endif()
  41. # SET(CSOURCES
  42. # # memdebug.c -not used
  43. # # nwlib.c - Not used
  44. # # strtok.c - specify later
  45. # # strtoofft.c - specify later
  46. # )
  47. # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
  48. # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
  49. # IF(CURL_MALLOC_DEBUG)
  50. # SET(CSOURCES ${CSOURCES}
  51. # memdebug.c
  52. # )
  53. # ENDIF(CURL_MALLOC_DEBUG)
  54. # # only build compat strtoofft if we need to
  55. # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  56. # SET(CSOURCES ${CSOURCES}
  57. # strtoofft.c
  58. # )
  59. # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  60. # The rest of the build
  61. include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
  62. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
  63. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
  64. include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
  65. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  66. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  67. if(USE_ARES)
  68. include_directories(${CARES_INCLUDE_DIR})
  69. endif()
  70. add_library(
  71. ${LIB_NAME}
  72. ${HHEADERS} ${CSOURCES}
  73. )
  74. add_library(
  75. ${PROJECT_NAME}::${LIB_NAME}
  76. ALIAS ${LIB_NAME}
  77. )
  78. if(NOT BUILD_SHARED_LIBS)
  79. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  80. endif()
  81. target_link_libraries(${LIB_NAME} ${CURL_LIBS})
  82. set_target_properties(${LIB_NAME} PROPERTIES
  83. COMPILE_DEFINITIONS BUILDING_LIBCURL
  84. OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
  85. )
  86. if(HIDES_CURL_PRIVATE_SYMBOLS)
  87. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  88. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  89. endif()
  90. # Remove the "lib" prefix since the library is already named "libcurl".
  91. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  92. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  93. if(CURL_HAS_LTO)
  94. set_target_properties(${LIB_NAME} PROPERTIES
  95. INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
  96. INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
  97. endif()
  98. if(WIN32)
  99. if(BUILD_SHARED_LIBS)
  100. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "_USRDLL")
  101. if(MSVC)
  102. # Add "_imp" as a suffix before the extension to avoid conflicting with
  103. # the statically linked "libcurl.lib"
  104. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  105. endif()
  106. endif()
  107. endif()
  108. target_include_directories(${LIB_NAME} INTERFACE
  109. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  110. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  111. install(TARGETS ${LIB_NAME}
  112. EXPORT ${TARGETS_EXPORT_NAME}
  113. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  114. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  115. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  116. )
  117. export(TARGETS ${LIB_NAME}
  118. APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  119. NAMESPACE ${PROJECT_NAME}::
  120. )