2
0

CMakeLists.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. set(LIB_NAME libcurl)
  2. if(BUILD_SHARED_LIBS)
  3. set(CURL_STATICLIB NO)
  4. else()
  5. set(CURL_STATICLIB YES)
  6. endif()
  7. # Use:
  8. # * CURL_STATICLIB
  9. configure_file(curl_config.h.cmake
  10. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
  11. transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
  12. include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
  13. list(APPEND HHEADERS
  14. ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
  15. )
  16. if(MSVC)
  17. list(APPEND CSOURCES libcurl.rc)
  18. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
  19. endif()
  20. # SET(CSOURCES
  21. # # memdebug.c -not used
  22. # # nwlib.c - Not used
  23. # # strtok.c - specify later
  24. # # strtoofft.c - specify later
  25. # )
  26. # # if we have Kerberos 4, right now this is never on
  27. # #OPTION(CURL_KRB4 "Use Kerberos 4" OFF)
  28. # IF(CURL_KRB4)
  29. # SET(CSOURCES ${CSOURCES}
  30. # krb4.c
  31. # security.c
  32. # )
  33. # ENDIF(CURL_KRB4)
  34. # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
  35. # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
  36. # IF(CURL_MALLOC_DEBUG)
  37. # SET(CSOURCES ${CSOURCES}
  38. # memdebug.c
  39. # )
  40. # ENDIF(CURL_MALLOC_DEBUG)
  41. # # only build compat strtoofft if we need to
  42. # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  43. # SET(CSOURCES ${CSOURCES}
  44. # strtoofft.c
  45. # )
  46. # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
  47. # The rest of the build
  48. include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
  49. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
  50. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
  51. include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
  52. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  53. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  54. if(USE_ARES)
  55. include_directories(${CARES_INCLUDE_DIR})
  56. endif()
  57. add_library(
  58. ${LIB_NAME}
  59. ${HHEADERS} ${CSOURCES}
  60. )
  61. if(MSVC AND NOT BUILD_SHARED_LIBS)
  62. set_target_properties(${LIB_NAME} PROPERTIES STATIC_LIBRARY_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
  63. endif()
  64. if(NOT BUILD_SHARED_LIBS)
  65. set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
  66. endif()
  67. target_link_libraries(${LIB_NAME} ${CURL_LIBS})
  68. if(WIN32)
  69. add_definitions(-D_USRDLL)
  70. endif()
  71. set_target_properties(${LIB_NAME} PROPERTIES COMPILE_DEFINITIONS BUILDING_LIBCURL)
  72. if(HIDES_CURL_PRIVATE_SYMBOLS)
  73. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
  74. set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
  75. endif()
  76. # Remove the "lib" prefix since the library is already named "libcurl".
  77. set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
  78. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
  79. if(WIN32)
  80. if(BUILD_SHARED_LIBS)
  81. # Add "_imp" as a suffix before the extension to avoid conflicting with the statically linked "libcurl.lib"
  82. set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
  83. endif()
  84. endif()
  85. target_include_directories(${LIB_NAME} INTERFACE
  86. $<INSTALL_INTERFACE:include>
  87. $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
  88. install(TARGETS ${LIB_NAME}
  89. EXPORT ${TARGETS_EXPORT_NAME}
  90. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  91. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  92. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  93. )
  94. export(TARGETS ${LIB_NAME}
  95. APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
  96. NAMESPACE CURL::
  97. )