• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.haxx.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###########################################################################
22set(LIB_NAME libcurl)
23
24if(BUILD_SHARED_LIBS)
25  set(CURL_STATICLIB NO)
26else()
27  set(CURL_STATICLIB YES)
28endif()
29
30# Use:
31# * CURL_STATICLIB
32configure_file(curl_config.h.cmake
33  ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
34
35transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
36include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
37
38list(APPEND HHEADERS
39  ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
40  )
41
42if(MSVC)
43  list(APPEND CSOURCES libcurl.rc)
44endif()
45
46# SET(CSOURCES
47# #  memdebug.c -not used
48# # nwlib.c - Not used
49# # strtok.c - specify later
50# # strtoofft.c - specify later
51# )
52
53# #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
54# MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
55# IF(CURL_MALLOC_DEBUG)
56# SET(CSOURCES ${CSOURCES}
57# memdebug.c
58# )
59# ENDIF(CURL_MALLOC_DEBUG)
60
61# # only build compat strtoofft if we need to
62# IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
63# SET(CSOURCES ${CSOURCES}
64# strtoofft.c
65# )
66# ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
67
68
69# The rest of the build
70
71include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
72include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
73include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
74include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
75include_directories(${CMAKE_CURRENT_SOURCE_DIR})
76include_directories(${CMAKE_CURRENT_BINARY_DIR})
77if(USE_ARES)
78  include_directories(${CARES_INCLUDE_DIR})
79endif()
80
81add_library(
82  ${LIB_NAME}
83  ${HHEADERS} ${CSOURCES}
84  )
85
86add_library(
87  ${PROJECT_NAME}::${LIB_NAME}
88  ALIAS ${LIB_NAME}
89  )
90
91if(MSVC AND NOT BUILD_SHARED_LIBS)
92  set_target_properties(${LIB_NAME} PROPERTIES STATIC_LIBRARY_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
93endif()
94
95if(NOT BUILD_SHARED_LIBS)
96    set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
97endif()
98
99target_link_libraries(${LIB_NAME} ${CURL_LIBS})
100
101if(WIN32)
102  add_definitions(-D_USRDLL)
103endif()
104
105set_target_properties(${LIB_NAME} PROPERTIES COMPILE_DEFINITIONS BUILDING_LIBCURL)
106
107if(HIDES_CURL_PRIVATE_SYMBOLS)
108  set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
109  set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
110endif()
111
112# Remove the "lib" prefix since the library is already named "libcurl".
113set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
114set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
115
116if(CURL_HAS_LTO)
117  set_target_properties(${LIB_NAME} PROPERTIES
118    INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
119    INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
120endif()
121
122if(WIN32)
123  if(BUILD_SHARED_LIBS)
124    # Add "_imp" as a suffix before the extension to avoid conflicting with the statically linked "libcurl.lib"
125    set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
126  endif()
127endif()
128
129target_include_directories(${LIB_NAME} INTERFACE
130  $<INSTALL_INTERFACE:include>
131  $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
132
133install(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
140export(TARGETS ${LIB_NAME}
141       APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
142       NAMESPACE ${PROJECT_NAME}::
143)
144