CMakeLists.txt 5.4 KB

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