1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) 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.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# SPDX-License-Identifier: curl 22# 23########################################################################### 24set(EXE_NAME curl) 25add_definitions(-DBUILDING_CURL) 26 27if(USE_MANUAL) 28 # Use the C locale to ensure that only ASCII characters appear in the 29 # embedded text. NROFF and MANOPT are set in the parent CMakeLists.txt 30 add_custom_command( 31 OUTPUT tool_hugehelp.c 32 COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_setup.h\"" > tool_hugehelp.c 33 COMMAND ${CMAKE_COMMAND} -E echo "#ifndef HAVE_LIBZ" >> tool_hugehelp.c 34 COMMAND env LC_ALL=C "${NROFF}" ${NROFF_MANOPT} 35 "${CURL_BINARY_DIR}/docs/curl.1" | 36 "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" >> tool_hugehelp.c 37 COMMAND ${CMAKE_COMMAND} -E echo "#else" >> tool_hugehelp.c 38 COMMAND env LC_ALL=C "${NROFF}" ${NROFF_MANOPT} 39 "${CURL_BINARY_DIR}/docs/curl.1" | 40 "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" -c >> tool_hugehelp.c 41 COMMAND ${CMAKE_COMMAND} -E echo "#endif /* HAVE_LIBZ */" >> tool_hugehelp.c 42 DEPENDS 43 generate-curl.1 44 "${CURL_BINARY_DIR}/docs/curl.1" 45 "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" 46 "${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h" 47 VERBATIM) 48else() 49 add_custom_command( 50 OUTPUT tool_hugehelp.c 51 COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_hugehelp.h\"" > tool_hugehelp.c 52 DEPENDS 53 "${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h" 54 VERBATIM) 55 56endif() 57 58transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") 59include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake) 60 61if(WIN32) 62 list(APPEND CURL_CFILES curl.rc) 63endif() 64 65# CURL_CFILES, CURLX_CFILES, CURL_HFILES, CURLTOOL_LIBCURL_CFILES 66# come from Makefile.inc 67if(BUILD_STATIC_CURL) 68 set(CURLX_CFILES ${CURLTOOL_LIBCURL_CFILES}) 69endif() 70 71if(ENABLE_CURLDEBUG) 72 # We must compile this source separately to avoid memdebug.h redefinitions 73 # applying to them. 74 set_source_files_properties(../lib/curl_multibyte.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) 75endif() 76 77add_executable( 78 ${EXE_NAME} 79 ${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES} 80 ) 81 82add_executable( 83 ${PROJECT_NAME}::${EXE_NAME} 84 ALIAS ${EXE_NAME} 85 ) 86 87add_library( 88 curltool # special libcurltool library just for unittests 89 STATIC 90 EXCLUDE_FROM_ALL 91 ${CURL_CFILES} ${CURLTOOL_LIBCURL_CFILES} ${CURL_HFILES} 92) 93target_compile_definitions(curltool PUBLIC UNITTESTS CURL_STATICLIB) 94target_link_libraries(curltool PRIVATE ${CURL_LIBS}) 95 96if(CURL_HAS_LTO) 97 set_target_properties(${EXE_NAME} PROPERTIES 98 INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE 99 INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE) 100endif() 101 102if(ENABLE_UNICODE AND MINGW) 103 target_link_libraries(${EXE_NAME} -municode) 104endif() 105 106source_group("curlX source files" FILES ${CURLX_CFILES}) 107source_group("curl source files" FILES ${CURL_CFILES}) 108source_group("curl header files" FILES ${CURL_HFILES}) 109 110include_directories( 111 ${CURL_SOURCE_DIR}/lib # To be able to reach "curl_setup_once.h" 112 ${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h" 113 ${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h" 114 # This is needed as tool_hugehelp.c is generated in the binary dir 115 ${CURL_SOURCE_DIR}/src # To be able to reach "tool_hugehelp.h" 116 ) 117 118#Build curl executable 119target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS}) 120 121################################################################################ 122 123#SET_TARGET_PROPERTIES(${EXE_NAME} ARCHIVE_OUTPUT_DIRECTORY "blah blah blah") 124#SET_TARGET_PROPERTIES(${EXE_NAME} RUNTIME_OUTPUT_DIRECTORY "blah blah blah") 125#SET_TARGET_PROPERTIES(${EXE_NAME} LIBRARY_OUTPUT_DIRECTORY "blah blah blah") 126 127#INCLUDE(ModuleInstall OPTIONAL) 128 129install(TARGETS ${EXE_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) 130export(TARGETS ${EXE_NAME} 131 FILE ${PROJECT_BINARY_DIR}/curl-target.cmake 132 NAMESPACE ${PROJECT_NAME}:: 133) 134