From cd90e28dab3200e48e62a19a9a2187c5d511e01e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 28 Dec 2023 09:39:08 +0100 Subject: [PATCH] Prevent incorrect cmake usage It's a reoccurring issue that users try to build individual components by pointing cmake at a specific subdirectory, e.g. 'cmake vncviewer'. CMake, unfortunately, has insufficient protection against this so we'll need to add a manual check. This commit only adds it to the most likely places for misuse so we don't have to pollute every CMakeLists.txt. --- tests/CMakeLists.txt | 4 ++++ unix/CMakeLists.txt | 4 ++++ vncviewer/CMakeLists.txt | 4 ++++ win/CMakeLists.txt | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4399dad0..3d0d4390 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,7 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR "cmake must be invoked with the top level directory") +endif() + # Benchmarking tools add_subdirectory(perf) diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index 5456e00b..a4726006 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -1,3 +1,7 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR "cmake must be invoked with the top level directory") +endif() + add_subdirectory(tx) add_subdirectory(common) add_subdirectory(vncconfig) diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt index 3191176b..1f9c6d39 100644 --- a/vncviewer/CMakeLists.txt +++ b/vncviewer/CMakeLists.txt @@ -1,3 +1,7 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR "cmake must be invoked with the top level directory") +endif() + add_executable(vncviewer fltk/Fl_Monitor_Arrangement.cxx fltk/Fl_Navigation.cxx diff --git a/win/CMakeLists.txt b/win/CMakeLists.txt index 951f16ad..6f0886d9 100644 --- a/win/CMakeLists.txt +++ b/win/CMakeLists.txt @@ -1,3 +1,7 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR "cmake must be invoked with the top level directory") +endif() + include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/win) configure_file(resdefs.h.in ${CMAKE_CURRENT_BINARY_DIR}/resdefs.h) -- 2.39.5