From 615fcc4370a318dfe35a63e40b46ccecf226be9b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 7 Nov 2023 15:41:01 +0100 Subject: [PATCH] [cmake] prevent in source builds --- .gitignore | 2 ++ CMakeLists.txt | 1 + client/Mac/CMakeLists.txt | 3 +++ client/Mac/cli/CMakeLists.txt | 19 +++++++++++-------- client/SDL/CMakeLists.txt | 2 ++ client/Sample/CMakeLists.txt | 2 ++ client/X11/CMakeLists.txt | 2 ++ client/iOS/CMakeLists.txt | 3 +++ cmake/PreventInSourceBuilds.cmake | 26 ++++++++++++++++++++++++++ rdtk/CMakeLists.txt | 1 + uwac/CMakeLists.txt | 1 + winpr/CMakeLists.txt | 3 ++- 12 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 cmake/PreventInSourceBuilds.cmake diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..15dc69dde --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/CMakeCache.txt +**/CMakeFiles diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e9ee33c5..bb63a5945 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ endif() # Include our extra modules list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/) +include(PreventInSourceBuilds) if((CMAKE_SYSTEM_NAME MATCHES "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES "10.0")) set(UWP 1) diff --git a/client/Mac/CMakeLists.txt b/client/Mac/CMakeLists.txt index f56af3513..f2b016195 100644 --- a/client/Mac/CMakeLists.txt +++ b/client/Mac/CMakeLists.txt @@ -9,6 +9,9 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE) endif() +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/) +include(PreventInSourceBuilds) + set(MODULE_NAME "MacFreeRDP-library") set(MODULE_OUTPUT_NAME "MacFreeRDP") set(MODULE_PREFIX "FREERDP_CLIENT_MAC_LIBRARY") diff --git a/client/Mac/cli/CMakeLists.txt b/client/Mac/cli/CMakeLists.txt index e2822d027..65213c4ee 100644 --- a/client/Mac/cli/CMakeLists.txt +++ b/client/Mac/cli/CMakeLists.txt @@ -1,6 +1,9 @@ project(MacFreeRDP) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/) +include(PreventInSourceBuilds) + set(MODULE_NAME "MacFreeRDP") set(MODULE_OUTPUT_NAME "MacFreeRDP") set(MODULE_PREFIX "FREERDP_CLIENT_MAC_CLIENT") @@ -42,19 +45,19 @@ set(${MODULE_PREFIX}_HEADERS set(${MODULE_PREFIX}_RESOURCES ${MACOSX_BUNDLE_ICON_FILE}) -# Include XIB file in Xcode resources. +# Include XIB file in Xcode resources. if("${CMAKE_GENERATOR}" MATCHES "Xcode") message(STATUS "Adding Xcode XIB resources for ${MODULE_NAME}") set(${MODULE_PREFIX}_RESOURCES ${${MODULE_PREFIX}_RESOURCES} ${${MODULE_PREFIX}_XIBS}) endif() add_executable(${MODULE_NAME} - ${APP_TYPE} + ${APP_TYPE} ${${MODULE_PREFIX}_HEADERS} ${${MODULE_PREFIX}_SOURCES} ${${MODULE_PREFIX}_RESOURCES}) -set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_OUTPUT_NAME}") +set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_OUTPUT_NAME}") add_dependencies(${MODULE_NAME} prepare-framework-headers) # This is necessary for the xib file part below @@ -101,11 +104,11 @@ add_custom_command(TARGET ${MODULE_NAME} POST_BUILD # Add post-build NIB file generation in unix makefiles. XCode handles this implicitly. if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") message(STATUS "Adding post-build NIB file generation event for ${MODULE_NAME}") - + # Make sure we can find the 'ibtool' program. If we can NOT find it we skip generation of this project find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin") if (${IBTOOL} STREQUAL "IBTOOL-NOTFOUND") - message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with + message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin") endif() @@ -115,9 +118,9 @@ if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") # Compile the .xib files using the 'ibtool' program with the destination being the app package foreach(xib ${${MODULE_PREFIX}_XIBS}) get_filename_component(XIB_WE ${xib} NAME_WE) - - add_custom_command (TARGET ${MODULE_NAME} POST_BUILD - COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text + + add_custom_command (TARGET ${MODULE_NAME} POST_BUILD + COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text --compile ${CMAKE_CURRENT_BINARY_DIR}/${safe_configuration}/${MODULE_OUTPUT_NAME}.app/Contents/Resources/${XIB_WE}.nib ${CMAKE_CURRENT_SOURCE_DIR}/${xib} COMMENT "Compiling ${xib}") endforeach() diff --git a/client/SDL/CMakeLists.txt b/client/SDL/CMakeLists.txt index 4d229d955..0cf889b22 100644 --- a/client/SDL/CMakeLists.txt +++ b/client/SDL/CMakeLists.txt @@ -26,7 +26,9 @@ set(CMAKE_CXX_EXTENSIONS ON) option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON) option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON) option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/) +include(PreventInSourceBuilds) include(ConfigureFreeRDP) diff --git a/client/Sample/CMakeLists.txt b/client/Sample/CMakeLists.txt index abd63c6dd..10d8dc448 100644 --- a/client/Sample/CMakeLists.txt +++ b/client/Sample/CMakeLists.txt @@ -25,7 +25,9 @@ set(CMAKE_C_EXTENSIONS ON) option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON) option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON) option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/) +include(PreventInSourceBuilds) include(MSVCRuntime) diff --git a/client/X11/CMakeLists.txt b/client/X11/CMakeLists.txt index b779ad9f4..e6aff6c6c 100644 --- a/client/X11/CMakeLists.txt +++ b/client/X11/CMakeLists.txt @@ -26,7 +26,9 @@ set(CMAKE_C_EXTENSIONS ON) option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON) option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON) option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/) +include(PreventInSourceBuilds) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE) diff --git a/client/iOS/CMakeLists.txt b/client/iOS/CMakeLists.txt index 1f86c2a08..9185b2619 100644 --- a/client/iOS/CMakeLists.txt +++ b/client/iOS/CMakeLists.txt @@ -20,6 +20,9 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE) endif() +list(APPEND CMAKE_MODULE_PATH ${PROJECT_CURRENT_SOURCE_DIR}/../../cmake/) +include(PreventInSourceBuilds) + set(MODULE_NAME "iFreeRDP") set(MODULE_PREFIX "IFREERDP_CLIENT") set(APP_TYPE MACOSX_BUNDLE) diff --git a/cmake/PreventInSourceBuilds.cmake b/cmake/PreventInSourceBuilds.cmake new file mode 100644 index 000000000..0f495d8ae --- /dev/null +++ b/cmake/PreventInSourceBuilds.cmake @@ -0,0 +1,26 @@ +# PreventInSourceBuilds +# --------------------- +# +# Prevent in-source builds +# +# It is generally acknowledged that it is preferable to run CMake out of source, +# in a dedicated build directory. To prevent users from accidentally running +# CMake in the source directory, just include this module. + +# make sure the user doesn't play dirty with symlinks +get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) +get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) + +# disallow in-source builds +if("${srcdir}" STREQUAL "${bindir}") + message(FATAL_ERROR "\ + +CMake must not to be run in the source directory. \ +Rather create a dedicated build directory and run CMake there. \ +CMake now already created some files, to clean up after this aborted in-source compilation: + rm -r CMakeCache.txt CMakeFiles +or + git clean -xdf +") +endif() + diff --git a/rdtk/CMakeLists.txt b/rdtk/CMakeLists.txt index 5a24c7069..8bf7f9f95 100644 --- a/rdtk/CMakeLists.txt +++ b/rdtk/CMakeLists.txt @@ -65,6 +65,7 @@ endif() # Include our extra modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/) +include(PreventInSourceBuilds) # Include cmake modules include(CheckIncludeFiles) diff --git a/uwac/CMakeLists.txt b/uwac/CMakeLists.txt index 4c98ccaa4..4efd61f33 100644 --- a/uwac/CMakeLists.txt +++ b/uwac/CMakeLists.txt @@ -58,6 +58,7 @@ option(UWAC_HAVE_PIXMAN_REGION "Use PIXMAN or FreeRDP for region calculations" " # Include our extra modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/) +include(PreventInSourceBuilds) # Check for cmake compatibility (enable/disable features) include(FindFeature) diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 5afe899d5..5403125b2 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -115,6 +115,8 @@ include(CheckSymbolExists) include(CheckStructHasMember) include(TestBigEndian) +include(PreventInSourceBuilds) + # Check for cmake compatibility (enable/disable features) include(CheckCmakeCompat) include(FindFeature) @@ -355,4 +357,3 @@ install(EXPORT WinPRTargets DESTINATION ${WINPR_CMAKE_INSTALL_DIR}) include(pkg-config-install-prefix) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -