1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-10-23 03:48:32 +03:00

cmake: tidy up passing compiler and linker options

- prefer `set_property()` over `target_compile_options()`, to use
  the modern style.

  Follow-up to 8017592163 #939

- prefer to append to compiler/linker options in examples/tests.
  To prevent accidentally overriding a previously set option.

  Follow-up to 14a709a72f #1686
  Follow-up to 854cfa8292 #1524

- replace `LINK_FLAGS` with `LINK_OPTIONS` that superceded it, for
  CMake 3.13+.

  Follow-up to 854cfa8292 #1524
  https://cmake.org/cmake/help/v4.1/prop_tgt/LINK_OPTIONS.html

Closes #1690
This commit is contained in:
Viktor Szakats
2025-09-28 02:04:32 +02:00
parent a7b3fdb416
commit 61d51cb449
4 changed files with 12 additions and 6 deletions

View File

@@ -52,7 +52,8 @@ foreach(_example IN LISTS noinst_PROGRAMS)
"${PROJECT_BINARY_DIR}/src"
"${PROJECT_SOURCE_DIR}/src")
target_link_libraries(${_example} ${LIB_SELECTED} ${LIBSSH2_LIBS})
set_target_properties(${_example} PROPERTIES COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}" UNITY_BUILD OFF)
set_property(TARGET ${_example} APPEND PROPERTY COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}")
set_target_properties(${_example} PROPERTIES UNITY_BUILD OFF)
endforeach()
libssh2_add_target_to_copy_dependencies(

View File

@@ -113,7 +113,7 @@ if(BUILD_STATIC_LIBS OR BUILD_STATIC_FOR_TESTS)
add_library(${LIB_STATIC} STATIC ${_sources})
add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
target_compile_definitions(${LIB_STATIC} PRIVATE ${CRYPTO_BACKEND_DEFINE} ${_libssh2_definitions})
target_compile_options(${LIB_STATIC} PRIVATE "${LIBSSH2_PICKY_C_FLAGS}")
set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}")
target_link_libraries(${LIB_STATIC} PRIVATE ${LIBSSH2_LIBS})
set_target_properties(${LIB_STATIC} PROPERTIES
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${_libssh2_soversion}" VERSION "${_libssh2_libversion}"
@@ -157,7 +157,7 @@ if(BUILD_SHARED_LIBS)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "libssh2.rc")
endif()
target_compile_definitions(${LIB_SHARED} PRIVATE ${CRYPTO_BACKEND_DEFINE} ${_libssh2_definitions} ${LIB_SHARED_DEFINITIONS})
target_compile_options(${LIB_SHARED} PRIVATE "${LIBSSH2_PICKY_C_FLAGS}" "${LIB_SHARED_C_FLAGS}")
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}" "${LIB_SHARED_C_FLAGS}")
target_link_libraries(${LIB_SHARED} PRIVATE ${LIBSSH2_LIBS})
set_target_properties(${LIB_SHARED} PROPERTIES
PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${_libssh2_soversion}" VERSION "${_libssh2_libversion}"

View File

@@ -76,7 +76,7 @@ target_include_directories(runner PRIVATE
"${PROJECT_BINARY_DIR}/src"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/include")
set_target_properties(runner PROPERTIES COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}")
set_property(TARGET runner APPEND PROPERTY COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}")
target_link_libraries(runner PRIVATE libssh2 ${LIBSSH2_LIBS})
foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
@@ -98,7 +98,8 @@ foreach(_test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
"${PROJECT_BINARY_DIR}/src"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/include")
set_target_properties(${_test} PROPERTIES COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}" UNITY_BUILD OFF)
set_property(TARGET ${_test} APPEND PROPERTY COMPILE_OPTIONS "${LIBSSH2_PICKY_C_FLAGS}")
set_target_properties(${_test} PROPERTIES UNITY_BUILD OFF)
target_link_libraries(${_test} PRIVATE runner ${_lib_for_tests} ${LIBSSH2_LIBS})
# build a single test with gcov

View File

@@ -13,7 +13,11 @@ target_include_directories(ssh2_client_fuzzer PRIVATE
"${PROJECT_SOURCE_DIR}/include")
if(LIB_FUZZING_ENGINE)
if(LIB_FUZZING_ENGINE STREQUAL "-fsanitize=fuzzer") # FIXME: compiler-specific
set_target_properties(ssh2_client_fuzzer PROPERTIES LINK_FLAGS "${LIB_FUZZING_ENGINE}")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
set_property(TARGET ssh2_client_fuzzer APPEND PROPERTY LINK_OPTIONS "${LIB_FUZZING_ENGINE}")
else()
set_property(TARGET ssh2_client_fuzzer APPEND PROPERTY LINK_FLAGS "${LIB_FUZZING_ENGINE}")
endif()
else()
target_link_libraries(ssh2_client_fuzzer ${LIB_FUZZING_ENGINE})
endif()