# Return result in variable: CURL_TEST_OUTPUT
macro(curl_internal_test _curl_test)
if(NOT DEFINED "${_curl_test}")
+ string(REPLACE ";" " " _cmake_required_flags "${CMAKE_REQUIRED_FLAGS}")
string(REPLACE ";" " " _cmake_required_definitions "${CMAKE_REQUIRED_DEFINITIONS}")
set(_curl_test_add_libraries "")
if(CMAKE_REQUIRED_LIBRARIES)
${PROJECT_BINARY_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c"
CMAKE_FLAGS
- "-DCOMPILE_DEFINITIONS:STRING=-D${_curl_test} ${CURL_TEST_DEFINES} ${_cmake_required_definitions}"
+ "-DCOMPILE_DEFINITIONS:STRING=-D${_curl_test} ${CURL_TEST_DEFINES} ${_cmake_required_flags} ${_cmake_required_definitions}"
"${_curl_test_add_libraries}"
OUTPUT_VARIABLE CURL_TEST_OUTPUT)
if(${_curl_test})
if(CURL_WERROR AND
((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
NOT DOS AND # Watt-32 headers use the '#include_next' GCC extension
- CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0 AND
- CMAKE_VERSION VERSION_GREATER_EQUAL 3.23.0) OR # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
+ CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0) OR
CMAKE_C_COMPILER_ID MATCHES "Clang"))
list(APPEND _picky "-pedantic-errors")
endif()
endif()
if(MSVC)
- if(CMAKE_C_FLAGS MATCHES "[/-]W[0-4]")
- string(REGEX REPLACE "[/-]W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
- endif()
+ string(REGEX REPLACE "[/-]W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
list(APPEND _picky "-W4")
elseif(BORLAND)
list(APPEND _picky "-w-") # Disable warnings on Borland to avoid changing 3rd party code.
endif()
if(_picky)
- string(REPLACE ";" " " _picky "${_picky}")
- string(APPEND CMAKE_C_FLAGS " ${_picky}")
- message(STATUS "Picky compiler options: ${_picky}")
+ string(REPLACE ";" " " _picky_tmp "${_picky}")
+ message(STATUS "Picky compiler options: ${_picky_tmp}")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "${_picky}")
+
+ # Apply to all feature checks
+ list(REMOVE_ITEM _picky "-pedantic-errors") # Must not pass to feature checks
+ string(REPLACE ";" " " _picky_tmp "${_picky}")
+ list(APPEND CMAKE_REQUIRED_FLAGS "${_picky_tmp}")
+
+ unset(_picky)
+ unset(_picky_tmp)
endif()
include(PickyWarnings)
if(CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
- string(APPEND CMAKE_C_FLAGS " -D_GNU_SOURCE") # Required for sendmmsg() and accept4()
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_GNU_SOURCE") # Required for accept4(), pipe2(), sendmmsg()
+ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") # Apply to all feature checks
endif()
option(ENABLE_DEBUG "Enable curl debug features (for developing curl itself)" OFF)
if(CURL_STATIC_CRT AND MSVC)
if(MSVC_VERSION GREATER_EQUAL 1900 OR BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
- string(APPEND CMAKE_C_FLAGS_RELEASE " -MT")
- string(APPEND CMAKE_C_FLAGS_DEBUG " -MTd")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Release>:-MT>")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Debug>:-MTd>")
else()
message(WARNING "Static CRT requires UCRT, static libcurl or no curl executable.")
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl
- string(APPEND CMAKE_C_FLAGS " -MP") # Parallel compilation
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-MP") # Parallel compilation
endif()
if(CURL_WERROR)
if(MSVC)
- string(APPEND CMAKE_C_FLAGS " -WX")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-WX")
else()
- string(APPEND CMAKE_C_FLAGS " -Werror") # This assumes clang or gcc style options
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Werror") # This assumes clang or gcc style options
endif()
endif()