CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.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(WIN32)
  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. # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
  47. # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
  48. # IF(CURL_MALLOC_DEBUG)
  49. # SET(CSOURCES ${CSOURCES}
  50. # memdebug.c
  51. # )
  52. # ENDIF(CURL_MALLOC_DEBUG)
  53. # # only build compat strtoofft if we need to
  54. # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  55. # SET(CSOURCES ${CSOURCES}
  56. # strtoofft.c
  57. # )
  58. # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  59. # The rest of the build
  60. include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
  61. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
  62. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
  63. include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
  64. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  65. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  66. if(USE_ARES)
  67. include_directories(${CARES_INCLUDE_DIR})
  68. endif()
  69. add_library(
  70. ${LIB_NAME}
  71. ${HHEADERS} ${CSOURCES}
  72. )
  73. add_library(
  74. ${PROJECT_NAME}::${LIB_NAME}
  75. ALIAS ${LIB_NAME}
  76. )
  77. if(NOT BUILD_SHARED_LIBS)
  78. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  79. endif()
  80. target_link_libraries(${LIB_NAME} ${CURL_LIBS})
  81. if(WIN32)
  82. add_definitions(-D_USRDLL)
  83. endif()
  84. set_target_properties(${LIB_NAME} PROPERTIES COMPILE_DEFINITIONS BUILDING_LIBCURL)
  85. if(HIDES_CURL_PRIVATE_SYMBOLS)
  86. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  87. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  88. endif()
  89. # Remove the "lib" prefix since the library is already named "libcurl".
  90. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  91. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  92. if(CURL_HAS_LTO)
  93. set_target_properties(${LIB_NAME} PROPERTIES
  94. INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
  95. INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
  96. endif()
  97. if(WIN32)
  98. if(BUILD_SHARED_LIBS)
  99. # Add "_imp" as a suffix before the extension to avoid conflicting with the statically linked "libcurl.lib"
  100. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  101. endif()
  102. endif()
  103. target_include_directories(${LIB_NAME} INTERFACE
  104. $<INSTALL_INTERFACE:include>
  105. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  106. install(TARGETS ${LIB_NAME}
  107. EXPORT ${TARGETS_EXPORT_NAME}
  108. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  109. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  110. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  111. )
  112. export(TARGETS ${LIB_NAME}
  113. APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  114. NAMESPACE ${PROJECT_NAME}::
  115. )