From 640c5503c1b74d518a34bbce0fb7392876e8fb6d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 30 Mar 2023 21:00:12 +0200 Subject: [PATCH] Prefer target_include_directories() It is more specific, and it properly sets up propagation when include directories also need to be used further down a dependency chain. --- common/network/CMakeLists.txt | 3 +-- common/os/CMakeLists.txt | 3 +-- common/rdr/CMakeLists.txt | 9 ++++----- common/rfb/CMakeLists.txt | 16 ++++++++-------- tests/perf/CMakeLists.txt | 4 ++-- tests/unit/CMakeLists.txt | 2 +- unix/common/CMakeLists.txt | 6 +++--- unix/tx/CMakeLists.txt | 10 +++++----- unix/vncconfig/CMakeLists.txt | 10 +++++----- unix/vncpasswd/CMakeLists.txt | 3 +-- unix/x0vncserver/CMakeLists.txt | 11 +++++------ vncviewer/CMakeLists.txt | 10 ++++------ win/vncconfig/CMakeLists.txt | 3 +-- win/winvnc/CMakeLists.txt | 4 ++-- win/wm_hooks/CMakeLists.txt | 5 +++-- 15 files changed, 46 insertions(+), 53 deletions(-) diff --git a/common/network/CMakeLists.txt b/common/network/CMakeLists.txt index b4cfb3c4..f08eaa31 100644 --- a/common/network/CMakeLists.txt +++ b/common/network/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) - add_library(network STATIC Socket.cxx TcpSocket.cxx) @@ -8,6 +6,7 @@ if(NOT WIN32) target_sources(network PRIVATE UnixSocket.cxx) endif() +target_include_directories(network PUBLIC ${CMAKE_SOURCE_DIR}/common) target_link_libraries(network os rdr rfb) if(WIN32) diff --git a/common/os/CMakeLists.txt b/common/os/CMakeLists.txt index deaf2f96..2573d088 100644 --- a/common/os/CMakeLists.txt +++ b/common/os/CMakeLists.txt @@ -1,10 +1,9 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) - add_library(os STATIC Mutex.cxx Thread.cxx os.cxx) +target_include_directories(os PUBLIC ${CMAKE_SOURCE_DIR}/common) target_link_libraries(os rdr) if(UNIX) diff --git a/common/rdr/CMakeLists.txt b/common/rdr/CMakeLists.txt index 05d8c195..30c2403a 100644 --- a/common/rdr/CMakeLists.txt +++ b/common/rdr/CMakeLists.txt @@ -1,6 +1,3 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS}) - add_library(rdr STATIC AESInStream.cxx AESOutStream.cxx @@ -19,14 +16,16 @@ add_library(rdr STATIC ZlibInStream.cxx ZlibOutStream.cxx) +target_include_directories(rdr PUBLIC ${CMAKE_SOURCE_DIR}/common) +target_include_directories(rdr SYSTEM PUBLIC ${ZLIB_INCLUDE_DIRS}) target_link_libraries(rdr ${ZLIB_LIBRARIES} os rfb) if(GNUTLS_FOUND) - include_directories(SYSTEM ${GNUTLS_INCLUDE_DIR}) + target_include_directories(rdr SYSTEM PUBLIC ${GNUTLS_INCLUDE_DIR}) target_link_libraries(rdr ${GNUTLS_LIBRARIES}) endif() if (NETTLE_FOUND) - include_directories(SYSTEM ${NETTLE_INCLUDE_DIRS}) + target_include_directories(rdr SYSTEM PUBLIC ${NETTLE_INCLUDE_DIRS}) target_link_libraries(rdr ${NETTLE_LIBRARIES}) target_link_directories(rdr PUBLIC ${NETTLE_LIBRARY_DIRS}) endif() diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index f8fbf45a..25c777a0 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -1,7 +1,3 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(SYSTEM ${JPEG_INCLUDE_DIR}) -include_directories(SYSTEM ${PIXMAN_INCLUDE_DIRS}) - add_library(rfb STATIC Blacklist.cxx Congestion.cxx @@ -66,6 +62,9 @@ add_library(rfb STATIC obfuscate.cxx util.cxx) +target_include_directories(rfb PUBLIC ${CMAKE_SOURCE_DIR}/common) +target_include_directories(rfb SYSTEM PUBLIC ${JPEG_INCLUDE_DIR}) +target_include_directories(rfb SYSTEM PUBLIC ${PIXMAN_INCLUDE_DIRS}) target_link_libraries(rfb os rdr network) target_link_libraries(rfb ${JPEG_LIBRARIES} ${PIXMAN_LIBRARIES}) target_link_directories(rfb PUBLIC ${PIXMAN_LIBRARY_DIRS}) @@ -77,7 +76,7 @@ if(ENABLE_H264 AND NOT H264_LIBS STREQUAL "NONE") elseif(H264_LIBS STREQUAL "WIN") target_sources(rfb PRIVATE H264WinDecoderContext.cxx) endif() - include_directories(SYSTEM ${H264_INCLUDE_DIRS}) + target_include_directories(rfb SYSTEM PUBLIC ${H264_INCLUDE_DIRS}) target_link_libraries(rfb ${H264_LIBRARIES}) target_link_directories(rfb PUBLIC ${H264_LIBRARY_DIRS}) endif() @@ -87,7 +86,7 @@ if(UNIX) endif() if(WIN32) - include_directories(${CMAKE_SOURCE_DIR}/win) + target_include_directories(rfb PUBLIC ${CMAKE_SOURCE_DIR}/win) target_sources(rfb PRIVATE WinPasswdValidator.cxx) endif(WIN32) @@ -98,14 +97,15 @@ endif() if(GNUTLS_FOUND) target_sources(rfb PRIVATE CSecurityTLS.cxx SSecurityTLS.cxx) - include_directories(SYSTEM ${GNUTLS_INCLUDE_DIR}) + target_include_directories(rfb SYSTEM PUBLIC ${GNUTLS_INCLUDE_DIR}) target_link_libraries(rfb ${GNUTLS_LIBRARIES}) endif() if (NETTLE_FOUND) target_sources(rfb PRIVATE CSecurityDH.cxx CSecurityMSLogonII.cxx CSecurityRSAAES.cxx SSecurityRSAAES.cxx) - include_directories(SYSTEM ${NETTLE_INCLUDE_DIRS} ${GMP_INCLUDE_DIRS}) + target_include_directories(rfb SYSTEM PUBLIC ${NETTLE_INCLUDE_DIRS} + ${GMP_INCLUDE_DIRS}) target_link_libraries(rfb ${HOGWEED_LIBRARIES} ${NETTLE_LIBRARIES} ${GMP_LIBRARIES}) target_link_directories(rfb PUBLIC ${HOGWEED_LIBRARY_DIRS} diff --git a/tests/perf/CMakeLists.txt b/tests/perf/CMakeLists.txt index 562adfc0..13061b9b 100644 --- a/tests/perf/CMakeLists.txt +++ b/tests/perf/CMakeLists.txt @@ -1,5 +1,4 @@ include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(SYSTEM ${GETTEXT_INCLUDE_DIR}) add_library(test_util STATIC util.cxx) @@ -13,7 +12,6 @@ add_executable(encperf encperf.cxx) target_link_libraries(encperf test_util rfb) if (BUILD_VIEWER) - include_directories(SYSTEM ${FLTK_INCLUDE_DIR}) add_executable(fbperf fbperf.cxx ${CMAKE_SOURCE_DIR}/vncviewer/PlatformPixelBuffer.cxx @@ -28,6 +26,8 @@ if (BUILD_VIEWER) else() target_sources(fbperf PRIVATE ${CMAKE_SOURCE_DIR}/vncviewer/Surface_X11.cxx) endif() + target_include_directories(fbperf SYSTEM PUBLIC ${FLTK_INCLUDE_DIR}) + target_include_directories(fbperf SYSTEM PUBLIC ${GETTEXT_INCLUDE_DIR}) target_link_libraries(fbperf test_util rfb ${FLTK_LIBRARIES} ${GETTEXT_LIBRARIES}) if(WIN32) target_link_libraries(fbperf msimg32) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 00f38b76..8e223052 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -1,6 +1,5 @@ include_directories(${CMAKE_SOURCE_DIR}/common) include_directories(${CMAKE_SOURCE_DIR}/vncviewer) -include_directories(SYSTEM ${GETTEXT_INCLUDE_DIR}) add_executable(conv conv.cxx) target_link_libraries(conv rfb) @@ -21,4 +20,5 @@ add_executable(unicode unicode.cxx) target_link_libraries(unicode rfb) add_executable(emulatemb emulatemb.cxx ../../vncviewer/EmulateMB.cxx) +target_include_directories(emulatemb SYSTEM PUBLIC ${GETTEXT_INCLUDE_DIR}) target_link_libraries(emulatemb rfb ${GETTEXT_LIBRARIES}) diff --git a/unix/common/CMakeLists.txt b/unix/common/CMakeLists.txt index 611e1956..87e2ae79 100644 --- a/unix/common/CMakeLists.txt +++ b/unix/common/CMakeLists.txt @@ -1,9 +1,9 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(${CMAKE_SOURCE_DIR}/unix/common) - add_library(unixcommon STATIC randr.cxx) +target_include_directories(unixcommon PUBLIC ${CMAKE_SOURCE_DIR}/common) +target_include_directories(unixcommon PUBLIC ${CMAKE_SOURCE_DIR}/unix/common) + if(UNIX) libtool_create_control_file(unixcommon) endif() diff --git a/unix/tx/CMakeLists.txt b/unix/tx/CMakeLists.txt index e913de3c..e28621a6 100644 --- a/unix/tx/CMakeLists.txt +++ b/unix/tx/CMakeLists.txt @@ -1,9 +1,9 @@ -include_directories(SYSTEM ${X11_INCLUDE_DIR}) - -include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(${CMAKE_SOURCE_DIR}/common/rfb) - add_library(tx STATIC TXWindow.cxx) +target_include_directories(tx SYSTEM PUBLIC ${X11_INCLUDE_DIR}) + +target_include_directories(tx PUBLIC ${CMAKE_SOURCE_DIR}/common) +target_include_directories(tx PUBLIC ${CMAKE_SOURCE_DIR}/common/rfb) + target_link_libraries(tx ${X11_LIBRARIES}) diff --git a/unix/vncconfig/CMakeLists.txt b/unix/vncconfig/CMakeLists.txt index 8734ff63..0589f161 100644 --- a/unix/vncconfig/CMakeLists.txt +++ b/unix/vncconfig/CMakeLists.txt @@ -1,14 +1,14 @@ -include_directories(SYSTEM ${X11_INCLUDE_DIR}) - -include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(${CMAKE_SOURCE_DIR}/unix/tx) - add_executable(vncconfig buildtime.c vncExt.c vncconfig.cxx QueryConnectDialog.cxx) +target_include_directories(vncconfig SYSTEM PUBLIC ${X11_INCLUDE_DIR}) + +target_include_directories(vncconfig PUBLIC ${CMAKE_SOURCE_DIR}/common) +target_include_directories(vncconfig PUBLIC ${CMAKE_SOURCE_DIR}/unix/tx) + target_link_libraries(vncconfig tx rfb network rdr ${X11_LIBRARIES}) install(TARGETS vncconfig DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) diff --git a/unix/vncpasswd/CMakeLists.txt b/unix/vncpasswd/CMakeLists.txt index 9f716fac..9b672041 100644 --- a/unix/vncpasswd/CMakeLists.txt +++ b/unix/vncpasswd/CMakeLists.txt @@ -1,8 +1,7 @@ -include_directories(${CMAKE_SOURCE_DIR}/common) - add_executable(vncpasswd vncpasswd.cxx) +target_include_directories(vncpasswd PUBLIC ${CMAKE_SOURCE_DIR}/common) target_link_libraries(vncpasswd tx rfb os) install(TARGETS vncpasswd DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) diff --git a/unix/x0vncserver/CMakeLists.txt b/unix/x0vncserver/CMakeLists.txt index 488a78fd..31da5118 100644 --- a/unix/x0vncserver/CMakeLists.txt +++ b/unix/x0vncserver/CMakeLists.txt @@ -1,9 +1,3 @@ -include_directories(SYSTEM ${X11_INCLUDE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/unix/common) -include_directories(${CMAKE_SOURCE_DIR}/unix/tx) -include_directories(${CMAKE_SOURCE_DIR}/unix) -include_directories(${CMAKE_SOURCE_DIR}/common) - add_executable(x0vncserver buildtime.c Geometry.cxx @@ -20,6 +14,11 @@ add_executable(x0vncserver ../vncconfig/QueryConnectDialog.cxx ) +target_include_directories(x0vncserver SYSTEM PUBLIC ${X11_INCLUDE_DIR}) +target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/unix/common) +target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/unix/tx) +target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/unix) +target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/common) target_link_libraries(x0vncserver tx rfb network rdr unixcommon) if(X11_FOUND AND X11_XTest_LIB) diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt index 01b3a89c..c8df6a25 100644 --- a/vncviewer/CMakeLists.txt +++ b/vncviewer/CMakeLists.txt @@ -1,8 +1,3 @@ -include_directories(SYSTEM ${FLTK_INCLUDE_DIR}) -include_directories(SYSTEM ${GETTEXT_INCLUDE_DIR}) - -include_directories(${CMAKE_SOURCE_DIR}/common) - add_executable(vncviewer fltk/Fl_Monitor_Arrangement.cxx fltk/Fl_Navigation.cxx @@ -31,7 +26,7 @@ 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}) + target_include_directories(vncviewer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) configure_file(vncviewer.rc.in vncviewer.rc) target_sources(vncviewer PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/vncviewer.rc) endif() @@ -52,6 +47,9 @@ else() target_sources(vncviewer PRIVATE Surface_X11.cxx) endif() +target_include_directories(vncviewer SYSTEM PUBLIC ${FLTK_INCLUDE_DIR}) +target_include_directories(vncviewer SYSTEM PUBLIC ${GETTEXT_INCLUDE_DIR}) +target_include_directories(vncviewer PUBLIC ${CMAKE_SOURCE_DIR}/common) target_link_libraries(vncviewer rfb network rdr os ${FLTK_LIBRARIES} ${GETTEXT_LIBRARIES}) if(WIN32) diff --git a/win/vncconfig/CMakeLists.txt b/win/vncconfig/CMakeLists.txt index 6b620e53..157ee4c5 100644 --- a/win/vncconfig/CMakeLists.txt +++ b/win/vncconfig/CMakeLists.txt @@ -1,11 +1,10 @@ -include_directories(${CMAKE_BINARY_DIR}/win) - add_executable(vncconfig WIN32 Legacy.cxx PasswordDialog.cxx vncconfig.cxx vncconfig.rc) +target_include_directories(vncconfig PUBLIC ${CMAKE_BINARY_DIR}/win) target_link_libraries(vncconfig rfb_win32 rfb network rdr ws2_32.lib) install(TARGETS vncconfig diff --git a/win/winvnc/CMakeLists.txt b/win/winvnc/CMakeLists.txt index 034211c5..e7e1a4de 100644 --- a/win/winvnc/CMakeLists.txt +++ b/win/winvnc/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(${CMAKE_BINARY_DIR}/win ${CMAKE_CURRENT_SOURCE_DIR}) - add_executable(winvnc4 WIN32 buildTime.cxx ControlPanel.cxx @@ -11,6 +9,8 @@ add_executable(winvnc4 WIN32 winvnc.cxx winvnc.rc) +target_include_directories(winvnc4 PUBLIC ${CMAKE_BINARY_DIR}/win) +target_include_directories(winvnc4 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(winvnc4 rfb rfb_win32 network rdr ws2_32.lib) install(TARGETS winvnc4 diff --git a/win/wm_hooks/CMakeLists.txt b/win/wm_hooks/CMakeLists.txt index c8888ab7..441d9bf9 100644 --- a/win/wm_hooks/CMakeLists.txt +++ b/win/wm_hooks/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(${CMAKE_BINARY_DIR}/win ${CMAKE_CURRENT_SOURCE_DIR}) - add_library(wm_hooks SHARED ../wm_hooks/wm_hooks.cxx ../wm_hooks/wm_hooks.rc) @@ -7,6 +5,9 @@ add_library(wm_hooks SHARED # We want the DLL to be named wm_hooks.dll rather than libwm_hooks.dll set_target_properties(wm_hooks PROPERTIES PREFIX "") +target_include_directories(wm_hooks PUBLIC ${CMAKE_BINARY_DIR}/win) +target_include_directories(wm_hooks PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + install(TARGETS wm_hooks RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ) -- 2.39.5