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