CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2020, Daniel Stenberg, <[email protected]>, 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 cmcurl)
  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 AND NOT CURL_STATICLIB)
  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. # For windows we want to install OPENSSL_LIBRARIES dlls
  70. # and also copy them into the build tree so that testing
  71. # can find them.
  72. if(CMAKE_USE_OPENSSL AND OPENSSL_FOUND AND WIN32)
  73. find_file(CMAKE_EAY_DLL NAME libeay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
  74. find_file(CMAKE_SSL_DLL NAME ssleay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
  75. mark_as_advanced(CMAKE_EAY_DLL CMAKE_SSL_DLL)
  76. if(CMAKE_SSL_DLL AND CMAKE_EAY_DLL)
  77. set(CMAKE_CURL_SSL_DLLS ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
  78. ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
  79. add_custom_command(OUTPUT
  80. ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
  81. DEPENDS ${CMAKE_EAY_DLL}
  82. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_EAY_DLL}
  83. ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll)
  84. add_custom_command(OUTPUT
  85. ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll
  86. DEPENDS ${CMAKE_SSL_DLL}
  87. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SSL_DLL}
  88. ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
  89. install(PROGRAMS ${CMAKE_EAY_DLL} ${CMAKE_SSL_DLL} DESTINATION bin)
  90. endif()
  91. endif()
  92. add_library(
  93. ${LIB_NAME}
  94. ${HHEADERS} ${CSOURCES}
  95. ${CMAKE_CURL_SSL_DLLS}
  96. )
  97. add_library(
  98. ${PROJECT_NAME}::${LIB_NAME}
  99. ALIAS ${LIB_NAME}
  100. )
  101. if(NOT BUILD_SHARED_LIBS)
  102. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  103. endif()
  104. target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
  105. if(0) # This code not needed for building within CMake.
  106. if(WIN32)
  107. add_definitions(-D_USRDLL)
  108. endif()
  109. endif()
  110. set_target_properties(${LIB_NAME} PROPERTIES COMPILE_DEFINITIONS BUILDING_LIBCURL)
  111. if(0) # This code not needed for building within CMake.
  112. if(HIDES_CURL_PRIVATE_SYMBOLS)
  113. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  114. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  115. endif()
  116. # Remove the "lib" prefix since the library is already named "libcurl".
  117. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  118. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  119. if(CURL_HAS_LTO)
  120. set_target_properties(${LIB_NAME} PROPERTIES
  121. INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
  122. INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
  123. endif()
  124. if(WIN32)
  125. if(BUILD_SHARED_LIBS)
  126. # Add "_imp" as a suffix before the extension to avoid conflicting with the statically linked "libcurl.lib"
  127. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  128. endif()
  129. endif()
  130. target_include_directories(${LIB_NAME} INTERFACE
  131. $<INSTALL_INTERFACE:include>
  132. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  133. install(TARGETS ${LIB_NAME}
  134. EXPORT ${TARGETS_EXPORT_NAME}
  135. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  136. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  137. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  138. )
  139. export(TARGETS ${LIB_NAME}
  140. APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  141. NAMESPACE ${PROJECT_NAME}::
  142. )
  143. endif()