From: Viktor Szakats Date: Fri, 7 Feb 2025 12:44:39 +0000 (+0100) Subject: cmake: misc tidy-ups X-Git-Tag: curl-8_13_0~463 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=45f7cb7695b0fe0c61f71bdfbe31d161d50a5f51;p=thirdparty%2Fcurl.git cmake: misc tidy-ups - replace `add_compile_options()`, `add_definitions()` with directory properties. To harmonize this across all scripts. The new commands are verbose, but describe better how they work. The syntax is also closer to setting target properties, helps grepping. - prefer `CMAKE_INSTALL_PREFIX` over `--prefix` (in tests, CI). - tidy up cmake invocations. - formatting. Closes #16238 --- diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index b71d35fac0..edf1814f9c 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -589,6 +589,7 @@ jobs: fi if [ -n '${{ matrix.build.generate }}' ]; then cmake -B . -G Ninja \ + -DCMAKE_INSTALL_PREFIX="$HOME/curl" \ -DCMAKE_C_COMPILER_TARGET=$(uname -m)-pc-linux-gnu -DBUILD_STATIC_LIBS=ON \ -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON \ ${{ matrix.build.generate }} @@ -637,7 +638,7 @@ jobs: - name: 'cmake install' if: ${{ matrix.build.generate }} - run: cmake --install . --prefix $HOME/curl --strip + run: cmake --install . --strip - name: 'build tests' if: ${{ matrix.build.install_steps != 'skipall' }} diff --git a/.github/workflows/non-native.yml b/.github/workflows/non-native.yml index e620b970fe..62c6782bb3 100644 --- a/.github/workflows/non-native.yml +++ b/.github/workflows/non-native.yml @@ -311,7 +311,7 @@ jobs: https://github.com/libressl/portable/releases/download/v${{ env.libressl-version }}/libressl-${{ env.libressl-version }}.tar.gz | tar -x cd libressl-${{ env.libressl-version }} # FIXME: on the 4.0.1 release, delete '-DHAVE_ENDIAN_H=0' - cmake . \ + cmake -B . \ -DHAVE_ENDIAN_H=0 \ -DCMAKE_INSTALL_PREFIX="$HOME/libressl" \ -DCMAKE_SYSTEM_NAME=iOS \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 3541228460..9e5a97a776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,9 +202,9 @@ if(WIN32) set(ENABLE_UNICODE ON) endif() if(ENABLE_UNICODE) - add_definitions("-DUNICODE" "-D_UNICODE") + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "UNICODE" "_UNICODE") if(MINGW) - add_compile_options("-municode") + set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-municode") endif() endif() @@ -216,7 +216,7 @@ if(WIN32) set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string") if(CURL_TARGET_WINDOWS_VERSION) - add_definitions("-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") # Apply to all feature checks endif() @@ -513,7 +513,7 @@ endif() # If we are on AIX, do the _ALL_SOURCE magic if(CMAKE_SYSTEM_NAME STREQUAL "AIX") - add_definitions("-D_ALL_SOURCE") + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_ALL_SOURCE") endif() # If we are on Haiku, make sure that the network library is brought in. @@ -605,8 +605,8 @@ if(ENABLE_IPV6) if(WIN32) check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "winsock2.h;ws2tcpip.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) else() - check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR) check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) + check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR) if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) if(NOT DOS AND NOT AMIGA) message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") @@ -1932,7 +1932,7 @@ endif() include(CMake/OtherTests.cmake) -add_definitions("-DHAVE_CONFIG_H") +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "HAVE_CONFIG_H") if(WIN32) list(APPEND CURL_LIBS "ws2_32" "bcrypt") diff --git a/appveyor.sh b/appveyor.sh index 9b30f2379e..021bf494b2 100644 --- a/appveyor.sh +++ b/appveyor.sh @@ -56,7 +56,7 @@ if [ "${BUILD_SYSTEM}" = 'CMake' ]; then [ "${PRJ_CFG}" = 'Release' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=' [[ "${PRJ_GEN}" = *'Visual Studio'* ]] && options+=' -DCMAKE_VS_GLOBALS=TrackFileAccess=false' # shellcheck disable=SC2086 - cmake -B "_bld${_chkprefill}" "-G${PRJ_GEN}" ${TARGET} \ + cmake -B "_bld${_chkprefill}" -G "${PRJ_GEN}" ${TARGET} \ -DCURL_USE_OPENSSL="${OPENSSL}" \ -DCURL_USE_SCHANNEL="${SCHANNEL}" \ -DHTTP_ONLY="${HTTP_ONLY}" \ diff --git a/docs/HTTP3.md b/docs/HTTP3.md index b7050039b4..eee26a65c9 100644 --- a/docs/HTTP3.md +++ b/docs/HTTP3.md @@ -251,7 +251,7 @@ You can build curl with cmake: % cd .. % git clone https://github.com/curl/curl % cd curl - % cmake . -B bld -DCURL_USE_OPENSSL=ON -DUSE_OPENSSL_QUIC=ON + % cmake -B bld -DCURL_USE_OPENSSL=ON -DUSE_OPENSSL_QUIC=ON % cmake --build bld % cmake --install bld diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 12f5a1936b..244835814a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -23,7 +23,7 @@ ########################################################################### set(LIB_NAME "libcurl") set(LIBCURL_OUTPUT_NAME "libcurl" CACHE STRING "Basename of the curl library") -add_definitions("-DBUILDING_LIBCURL") +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_LIBCURL") configure_file("curl_config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/curl_config.h") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 715a471a75..ab4ebf96ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ # ########################################################################### set(EXE_NAME curl) -add_definitions("-DBUILDING_CURL") +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_CURL") set(_curl_cfiles_gen "") set(_curl_hfiles_gen "") diff --git a/tests/cmake/test.sh b/tests/cmake/test.sh index 88786917d9..52987e0273 100755 --- a/tests/cmake/test.sh +++ b/tests/cmake/test.sh @@ -28,9 +28,9 @@ fi if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then rm -rf bld-curl - cmake ../.. -B bld-curl + cmake ../.. -B bld-curl -DCMAKE_INSTALL_PREFIX="${PWD}/bld-curl/_pkg" cmake --build bld-curl - cmake --install bld-curl --prefix bld-curl/_pkg + cmake --install bld-curl rm -rf bld-find_package cmake -B bld-find_package \ -DTEST_INTEGRATION_MODE=find_package \