2
0

CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 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. # The rest of the build
  45. include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
  46. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
  47. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
  48. include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
  49. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  50. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  51. if(USE_ARES)
  52. include_directories(${CARES_INCLUDE_DIR})
  53. endif()
  54. add_library(
  55. ${LIB_NAME}
  56. ${HHEADERS} ${CSOURCES}
  57. )
  58. add_library(
  59. ${PROJECT_NAME}::${LIB_NAME}
  60. ALIAS ${LIB_NAME}
  61. )
  62. if(NOT BUILD_SHARED_LIBS)
  63. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  64. endif()
  65. target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
  66. transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
  67. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
  68. set_target_properties(${LIB_NAME} PROPERTIES
  69. COMPILE_DEFINITIONS BUILDING_LIBCURL
  70. OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
  71. )
  72. if(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
  73. CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
  74. CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
  75. CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
  76. CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD" OR
  77. # FreeBSD comes with the a.out and elf flavours
  78. # but a.out was supported up to version 3.x and
  79. # elf from 3.x. I cannot imagine someone running
  80. # CMake on those ancient systems
  81. CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
  82. CMAKE_SYSTEM_NAME STREQUAL "Haiku")
  83. math(EXPR CMAKESONAME "${VERSIONCHANGE} - ${VERSIONDEL}")
  84. set(CMAKEVERSION "${CMAKESONAME}.${VERSIONDEL}.${VERSIONADD}")
  85. set_target_properties(${LIB_NAME} PROPERTIES
  86. VERSION ${CMAKEVERSION}
  87. SOVERSION ${CMAKESONAME}
  88. )
  89. endif()
  90. if(HIDES_CURL_PRIVATE_SYMBOLS)
  91. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  92. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  93. endif()
  94. # Remove the "lib" prefix since the library is already named "libcurl".
  95. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  96. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  97. if(CURL_HAS_LTO)
  98. set_target_properties(${LIB_NAME} PROPERTIES
  99. INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
  100. INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
  101. endif()
  102. if(WIN32)
  103. if(BUILD_SHARED_LIBS)
  104. if(MSVC)
  105. # Add "_imp" as a suffix before the extension to avoid conflicting with
  106. # the statically linked "libcurl.lib"
  107. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  108. endif()
  109. endif()
  110. endif()
  111. target_include_directories(${LIB_NAME} INTERFACE
  112. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  113. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  114. if(CURL_ENABLE_EXPORT_TARGET)
  115. install(TARGETS ${LIB_NAME}
  116. EXPORT ${TARGETS_EXPORT_NAME}
  117. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  118. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  119. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  120. )
  121. export(TARGETS ${LIB_NAME}
  122. FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  123. NAMESPACE ${PROJECT_NAME}::
  124. )
  125. endif()