CMakeLists.txt 4.4 KB

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