From 6c7c022b194ea7f0f4a2e8ab5835c5688a2b88d4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 3 Jun 2022 15:44:32 +0200 Subject: [PATCH] Avoid temporary cmake variables Modern cmake has better support for adding source files and libraries incrementally, so let's use that to clean things up. --- common/network/CMakeLists.txt | 6 ++---- common/rdr/CMakeLists.txt | 9 ++++----- common/rfb/CMakeLists.txt | 37 ++++++++++++----------------------- tests/perf/CMakeLists.txt | 15 +++++++------- vncviewer/CMakeLists.txt | 29 ++++++++++++--------------- win/rfb_win32/CMakeLists.txt | 6 ++---- 6 files changed, 41 insertions(+), 61 deletions(-) diff --git a/common/network/CMakeLists.txt b/common/network/CMakeLists.txt index d00ca452..2f7c7ad3 100644 --- a/common/network/CMakeLists.txt +++ b/common/network/CMakeLists.txt @@ -1,15 +1,13 @@ include_directories(${CMAKE_SOURCE_DIR}/common) -set(NETWORK_SOURCES +add_library(network STATIC Socket.cxx TcpSocket.cxx) if(NOT WIN32) - set(NETWORK_SOURCES ${NETWORK_SOURCES} UnixSocket.cxx) + target_sources(network PRIVATE UnixSocket.cxx) endif() -add_library(network STATIC ${NETWORK_SOURCES}) - if(WIN32) target_link_libraries(network ws2_32) endif() diff --git a/common/rdr/CMakeLists.txt b/common/rdr/CMakeLists.txt index fa6ca281..46b36cd5 100644 --- a/common/rdr/CMakeLists.txt +++ b/common/rdr/CMakeLists.txt @@ -16,16 +16,15 @@ add_library(rdr STATIC ZlibInStream.cxx ZlibOutStream.cxx) -set(RDR_LIBRARIES ${ZLIB_LIBRARIES} os) +target_link_libraries(rdr ${ZLIB_LIBRARIES} os) + if(GNUTLS_FOUND) - set(RDR_LIBRARIES ${RDR_LIBRARIES} ${GNUTLS_LIBRARIES}) + target_link_libraries(rdr ${GNUTLS_LIBRARIES}) endif() if(WIN32) - set(RDR_LIBRARIES ${RDR_LIBRARIES} ws2_32) + target_link_libraries(rdr ws2_32) endif() -target_link_libraries(rdr ${RDR_LIBRARIES}) - if(UNIX) libtool_create_control_file(rdr) endif() diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 630bf7b6..07728453 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR} ${PIXMAN_INCLUDE_DIR}) -set(RFB_SOURCES +add_library(rfb STATIC Blacklist.cxx Congestion.cxx CConnection.cxx @@ -64,48 +64,37 @@ set(RFB_SOURCES encodings.cxx util.cxx) +target_link_libraries(rfb os rdr) +target_link_libraries(rfb ${JPEG_LIBRARIES} ${PIXMAN_LIBRARY}) + if(ENABLE_H264 AND NOT H264_LIBS STREQUAL "NONE") - set(RFB_SOURCES ${RFB_SOURCES} H264Decoder.cxx H264DecoderContext.cxx) + target_sources(rfb PRIVATE H264Decoder.cxx H264DecoderContext.cxx) if(H264_LIBS STREQUAL "LIBAV") - set(RFB_SOURCES ${RFB_SOURCES} H264LibavDecoderContext.cxx) + target_sources(rfb PRIVATE H264LibavDecoderContext.cxx) elseif(H264_LIBS STREQUAL "WIN") - set(RFB_SOURCES ${RFB_SOURCES} H264WinDecoderContext.cxx) + target_sources(rfb PRIVATE H264WinDecoderContext.cxx) endif() endif() if(UNIX) - set(RFB_SOURCES ${RFB_SOURCES} Logger_syslog.cxx) + target_sources(rfb PRIVATE Logger_syslog.cxx) endif() if(WIN32) include_directories(${CMAKE_SOURCE_DIR}/win) - set(RFB_SOURCES ${RFB_SOURCES} WinPasswdValidator.cxx) + target_sources(rfb PRIVATE WinPasswdValidator.cxx) endif(WIN32) -set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PIXMAN_LIBRARY} os rdr) - if(UNIX AND NOT APPLE) - set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx - UnixPasswordValidator.h pam.c pam.h) - set(RFB_LIBRARIES ${RFB_LIBRARIES} ${PAM_LIBS}) + target_sources(rfb PRIVATE UnixPasswordValidator.cxx pam.c) + target_link_libraries(rfb ${PAM_LIBS}) endif() if(GNUTLS_FOUND) - set(RFB_SOURCES - ${RFB_SOURCES} - CSecurityTLS.cxx - SSecurityTLS.cxx - ) - set(RFB_LIBRARIES - ${RFB_LIBRARIES} - ${GNUTLS_LIBRARIES} - ) + target_sources(rfb PRIVATE CSecurityTLS.cxx SSecurityTLS.cxx) + target_link_libraries(rfb ${GNUTLS_LIBRARIES}) endif() -add_library(rfb STATIC ${RFB_SOURCES}) - -target_link_libraries(rfb ${RFB_LIBRARIES}) - if(UNIX) libtool_create_control_file(rfb) endif() diff --git a/tests/perf/CMakeLists.txt b/tests/perf/CMakeLists.txt index d60b2882..b4cff208 100644 --- a/tests/perf/CMakeLists.txt +++ b/tests/perf/CMakeLists.txt @@ -16,21 +16,20 @@ target_link_libraries(encperf test_util rfb) if (BUILD_VIEWER) include_directories(${FLTK_INCLUDE_DIR}) - set(FBPERF_SOURCES + add_executable(fbperf fbperf.cxx ${CMAKE_SOURCE_DIR}/vncviewer/PlatformPixelBuffer.cxx ${CMAKE_SOURCE_DIR}/vncviewer/Surface.cxx) if(WIN32) - set(FBPERF_SOURCES ${FBPERF_SOURCES} ${CMAKE_SOURCE_DIR}/vncviewer/Surface_Win32.cxx) + target_sources(fbperf PRIVATE ${CMAKE_SOURCE_DIR}/vncviewer/Surface_Win32.cxx) elseif(APPLE) - set(FBPERF_SOURCES - ${FBPERF_SOURCES} ${CMAKE_SOURCE_DIR}/vncviewer/Surface_OSX.cxx - ${FBPERF_SOURCES} ${CMAKE_SOURCE_DIR}/vncviewer/keysym2ucs.c - ${FBPERF_SOURCES} ${CMAKE_SOURCE_DIR}/vncviewer/cocoa.mm) + target_sources(fbperf PRIVATE + ${CMAKE_SOURCE_DIR}/vncviewer/Surface_OSX.cxx + ${CMAKE_SOURCE_DIR}/vncviewer/keysym2ucs.c + ${CMAKE_SOURCE_DIR}/vncviewer/cocoa.mm) else() - set(FBPERF_SOURCES ${FBPERF_SOURCES} ${CMAKE_SOURCE_DIR}/vncviewer/Surface_X11.cxx) + target_sources(fbperf PRIVATE ${CMAKE_SOURCE_DIR}/vncviewer/Surface_X11.cxx) endif() - add_executable(fbperf ${FBPERF_SOURCES}) target_link_libraries(fbperf test_util rfb ${FLTK_LIBRARIES} ${GETTEXT_LIBRARIES}) if(WIN32) target_link_libraries(fbperf msimg32) diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt index b076347c..51b5f3ea 100644 --- a/vncviewer/CMakeLists.txt +++ b/vncviewer/CMakeLists.txt @@ -2,7 +2,8 @@ include_directories(${FLTK_INCLUDE_DIR}) include_directories(${GETTEXT_INCLUDE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/common) -set(VNCVIEWER_SOURCES + +add_executable(vncviewer menukey.cxx BaseTouchHandler.cxx CConn.cxx @@ -21,36 +22,32 @@ set(VNCVIEWER_SOURCES MonitorIndicesParameter.cxx vncviewer.cxx) +if(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(vncviewer PROPERTIES WIN32_EXECUTABLE TRUE) +endif() + if(WIN32) # Since vncviewer.rc is generated, local includes will be looking # in the wrong directory. We need to help it out. include_directories(${CMAKE_CURRENT_SOURCE_DIR}) configure_file(vncviewer.rc.in vncviewer.rc) - set(VNCVIEWER_SOURCES - ${VNCVIEWER_SOURCES} - ${CMAKE_CURRENT_BINARY_DIR}/vncviewer.rc) + target_sources(vncviewer PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/vncviewer.rc) endif() if(WIN32) - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} Win32TouchHandler.cxx win32.c) + target_sources(vncviewer PRIVATE Win32TouchHandler.cxx win32.c) elseif(APPLE) - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} cocoa.mm osx_to_qnum.c) + target_sources(vncviewer PRIVATE cocoa.mm osx_to_qnum.c) else() - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} GestureHandler.cxx XInputTouchHandler.cxx xkb_to_qnum.c) + target_sources(vncviewer PRIVATE GestureHandler.cxx XInputTouchHandler.cxx xkb_to_qnum.c) endif() if(WIN32) - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} Surface_Win32.cxx) + target_sources(vncviewer PRIVATE Surface_Win32.cxx) elseif(APPLE) - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} Surface_OSX.cxx) -else() - set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} Surface_X11.cxx) -endif() - -if(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - add_executable(vncviewer WIN32 ${VNCVIEWER_SOURCES}) + target_sources(vncviewer PRIVATE Surface_OSX.cxx) else() - add_executable(vncviewer ${VNCVIEWER_SOURCES}) + target_sources(vncviewer PRIVATE Surface_X11.cxx) endif() target_link_libraries(vncviewer rfb network rdr os ${FLTK_LIBRARIES} ${GETTEXT_LIBRARIES} ${H264_LIBRARIES}) diff --git a/win/rfb_win32/CMakeLists.txt b/win/rfb_win32/CMakeLists.txt index 305247a8..682873e7 100644 --- a/win/rfb_win32/CMakeLists.txt +++ b/win/rfb_win32/CMakeLists.txt @@ -1,4 +1,4 @@ -set(RFB_WIN32_SOURCES +add_library(rfb_win32 STATIC AboutDialog.cxx Clipboard.cxx CurrentUser.cxx @@ -32,9 +32,7 @@ set(RFB_WIN32_SOURCES WMWindowCopyRect.cxx) if(BUILD_WINVNC) - set(RFB_WIN32_SOURCES ${RFB_WIN32_SOURCES} CleanDesktop.cxx) + target_sources(rfb_win32 PRIVATE ${RFB_WIN32_SOURCES} CleanDesktop.cxx) endif() -add_library(rfb_win32 STATIC ${RFB_WIN32_SOURCES}) - target_link_libraries(rfb_win32 user32.lib comctl32.lib wtsapi32.lib version.lib) -- 2.39.5