CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. if(WIN32)
  83. add_definitions(-D_USRDLL)
  84. endif()
  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. install(TARGETS ${LIB_NAME}
  114. EXPORT ${TARGETS_EXPORT_NAME}
  115. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  116. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  117. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  118. )
  119. export(TARGETS ${LIB_NAME}
  120. APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  121. NAMESPACE ${PROJECT_NAME}::
  122. )