Skip to content

Commit d024e14

Browse files
committed
CMake: use imported targets where possible
1 parent 810f961 commit d024e14

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ endif()
110110

111111

112112
if(WITH_THREADS)
113+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
113114
find_package(Threads)
114115
endif()
115116

@@ -189,11 +190,13 @@ check_symbol_exists(htobe64 "endian.h" LIBVNCSERVER_HAVE_HTOBE64)
189190
check_symbol_exists(OSSwapHostToBigInt64 "libkern/OSByteOrder.h" LIBVNCSERVER_HAVE_OSSWAPHOSTTOBIGINT64)
190191

191192
if(Threads_FOUND)
192-
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
193+
list(APPEND ADDITIONAL_RAW_LIBS ${CMAKE_THREAD_LIBS_INIT})
194+
list(APPEND ADDITIONAL_TARGETS Threads::Threads)
193195
endif()
194196
if(ZLIB_FOUND)
195197
set(LIBVNCSERVER_HAVE_LIBZ 1)
196-
list(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES})
198+
list(APPEND ADDITIONAL_RAW_LIBS ${ZLIB_LIBRARIES})
199+
list(APPEND ADDITIONAL_TARGETS ZLIB::ZLIB)
197200
endif()
198201
if(LZO_FOUND)
199202
set(LIBVNCSERVER_HAVE_LZO 1)
@@ -209,7 +212,8 @@ else()
209212
unset(PNG_LIBRARIES) # would otherwise contain -NOTFOUND, confusing target_link_libraries()
210213
endif()
211214
if(OPENSSL_FOUND)
212-
list(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES})
215+
list(APPEND ADDITIONAL_RAW_LIBS ${OPENSSL_LIBRARIES})
216+
list(APPEND ADDITIONAL_TARGETS OpenSSL::SSL OpenSSL::Crypto)
213217
endif()
214218
if(SYSTEMD_FOUND)
215219
add_definitions(-DLIBVNCSERVER_WITH_SYSTEMD)
@@ -364,7 +368,6 @@ elseif(OPENSSL_FOUND)
364368
${LIBVNCSERVER_SOURCES}
365369
${LIBVNCSERVER_DIR}/rfbssl_openssl.c
366370
)
367-
include_directories(${OPENSSL_INCLUDE_DIR})
368371
else()
369372
set(LIBVNCCLIENT_SOURCES
370373
${LIBVNCCLIENT_SOURCES}
@@ -385,7 +388,6 @@ endif()
385388

386389
if(ZLIB_FOUND)
387390
add_definitions(-DLIBVNCSERVER_HAVE_LIBZ)
388-
include_directories(${ZLIB_INCLUDE_DIR})
389391
set(LIBVNCSERVER_SOURCES
390392
${LIBVNCSERVER_SOURCES}
391393
${LIBVNCSERVER_DIR}/zlib.c
@@ -454,9 +456,11 @@ endif()
454456

455457
target_link_libraries(vncclient
456458
${ADDITIONAL_LIBS}
459+
${ADDITIONAL_TARGETS}
457460
)
458461
target_link_libraries(vncserver
459462
${ADDITIONAL_LIBS}
463+
${ADDITIONAL_TARGETS}
460464
${PNG_LIBRARIES}
461465
)
462466

@@ -535,14 +539,14 @@ foreach(e ${LIBVNCSERVER_EXAMPLES})
535539
add_executable(examples_${e} ${LIBVNCSRVEXAMPLE_DIR}/${e}.c)
536540
set_target_properties(examples_${e} PROPERTIES OUTPUT_NAME ${e})
537541
set_target_properties(examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
538-
target_link_libraries(examples_${e} vncserver ${CMAKE_THREAD_LIBS_INIT})
542+
target_link_libraries(examples_${e} vncserver Threads::Threads)
539543
endforeach(e ${LIBVNCSERVER_EXAMPLES})
540544

541545
foreach(e ${LIBVNCCLIENT_EXAMPLES})
542546
add_executable(client_examples_${e} ${LIBVNCCLIEXAMPLE_DIR}/${e}.c ${LIBVNCCLIEXAMPLE_DIR}/${${e}_EXTRA_SOURCES} )
543547
set_target_properties(client_examples_${e} PROPERTIES OUTPUT_NAME ${e})
544548
set_target_properties(client_examples_${e} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples)
545-
target_link_libraries(client_examples_${e} vncclient ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES})
549+
target_link_libraries(client_examples_${e} vncclient Threads::Threads ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES})
546550
endforeach(e ${LIBVNCCLIENT_EXAMPLES})
547551

548552

@@ -638,9 +642,9 @@ function(get_link_libraries OUT EXTRA_LIBS)
638642
endfunction()
639643

640644
if(NOT WIN32)
641-
get_link_libraries(PRIVATE_LIBS "${PNG_LIBRARIES}")
645+
get_link_libraries(PRIVATE_LIBS "${PNG_LIBRARIES};${ADDITIONAL_RAW_LIBS}")
642646
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libvncserver.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc @ONLY)
643-
get_link_libraries(PRIVATE_LIBS "")
647+
get_link_libraries(PRIVATE_LIBS "${ADDITIONAL_RAW_LIBS}")
644648
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libvncclient.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc @ONLY)
645649
endif()
646650

0 commit comments

Comments
 (0)