Skip to content

Commit 615fcc4

Browse files
committed
[cmake] prevent in source builds
1 parent 1b31852 commit 615fcc4

12 files changed

+56
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/CMakeCache.txt
2+
**/CMakeFiles

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ endif()
6262

6363
# Include our extra modules
6464
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
65+
include(PreventInSourceBuilds)
6566

6667
if((CMAKE_SYSTEM_NAME MATCHES "WindowsStore") AND (CMAKE_SYSTEM_VERSION MATCHES "10.0"))
6768
set(UWP 1)

client/Mac/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ if(NOT CMAKE_BUILD_TYPE)
99
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE)
1010
endif()
1111

12+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
13+
include(PreventInSourceBuilds)
14+
1215
set(MODULE_NAME "MacFreeRDP-library")
1316
set(MODULE_OUTPUT_NAME "MacFreeRDP")
1417
set(MODULE_PREFIX "FREERDP_CLIENT_MAC_LIBRARY")

client/Mac/cli/CMakeLists.txt

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
project(MacFreeRDP)
33

4+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/)
5+
include(PreventInSourceBuilds)
6+
47
set(MODULE_NAME "MacFreeRDP")
58
set(MODULE_OUTPUT_NAME "MacFreeRDP")
69
set(MODULE_PREFIX "FREERDP_CLIENT_MAC_CLIENT")
@@ -42,19 +45,19 @@ set(${MODULE_PREFIX}_HEADERS
4245

4346
set(${MODULE_PREFIX}_RESOURCES ${MACOSX_BUNDLE_ICON_FILE})
4447

45-
# Include XIB file in Xcode resources.
48+
# Include XIB file in Xcode resources.
4649
if("${CMAKE_GENERATOR}" MATCHES "Xcode")
4750
message(STATUS "Adding Xcode XIB resources for ${MODULE_NAME}")
4851
set(${MODULE_PREFIX}_RESOURCES ${${MODULE_PREFIX}_RESOURCES} ${${MODULE_PREFIX}_XIBS})
4952
endif()
5053

5154
add_executable(${MODULE_NAME}
52-
${APP_TYPE}
55+
${APP_TYPE}
5356
${${MODULE_PREFIX}_HEADERS}
5457
${${MODULE_PREFIX}_SOURCES}
5558
${${MODULE_PREFIX}_RESOURCES})
5659

57-
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_OUTPUT_NAME}")
60+
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_OUTPUT_NAME}")
5861
add_dependencies(${MODULE_NAME} prepare-framework-headers)
5962

6063
# This is necessary for the xib file part below
@@ -101,11 +104,11 @@ add_custom_command(TARGET ${MODULE_NAME} POST_BUILD
101104
# Add post-build NIB file generation in unix makefiles. XCode handles this implicitly.
102105
if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
103106
message(STATUS "Adding post-build NIB file generation event for ${MODULE_NAME}")
104-
107+
105108
# Make sure we can find the 'ibtool' program. If we can NOT find it we skip generation of this project
106109
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
107110
if (${IBTOOL} STREQUAL "IBTOOL-NOTFOUND")
108-
message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with
111+
message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with
109112
the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
110113
endif()
111114

@@ -115,9 +118,9 @@ if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
115118
# Compile the .xib files using the 'ibtool' program with the destination being the app package
116119
foreach(xib ${${MODULE_PREFIX}_XIBS})
117120
get_filename_component(XIB_WE ${xib} NAME_WE)
118-
119-
add_custom_command (TARGET ${MODULE_NAME} POST_BUILD
120-
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
121+
122+
add_custom_command (TARGET ${MODULE_NAME} POST_BUILD
123+
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
121124
--compile ${CMAKE_CURRENT_BINARY_DIR}/${safe_configuration}/${MODULE_OUTPUT_NAME}.app/Contents/Resources/${XIB_WE}.nib ${CMAKE_CURRENT_SOURCE_DIR}/${xib}
122125
COMMENT "Compiling ${xib}")
123126
endforeach()

client/SDL/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ set(CMAKE_CXX_EXTENSIONS ON)
2626
option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON)
2727
option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON)
2828
option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON)
29+
2930
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
31+
include(PreventInSourceBuilds)
3032

3133
include(ConfigureFreeRDP)
3234

client/Sample/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ set(CMAKE_C_EXTENSIONS ON)
2525
option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON)
2626
option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON)
2727
option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON)
28+
2829
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
30+
include(PreventInSourceBuilds)
2931

3032
include(MSVCRuntime)
3133

client/X11/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ set(CMAKE_C_EXTENSIONS ON)
2626
option(CMAKE_COLOR_MAKEFILE "colorful CMake makefile" ON)
2727
option(CMAKE_VERBOSE_MAKEFILE "verbose CMake makefile" ON)
2828
option(CMAKE_POSITION_INDEPENDENT_CODE "build with position independent code (-fPIC or -fPIE)" ON)
29+
2930
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
31+
include(PreventInSourceBuilds)
3032

3133
if(NOT CMAKE_BUILD_TYPE)
3234
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE)

client/iOS/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ if(NOT CMAKE_BUILD_TYPE)
2020
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "project default" FORCE)
2121
endif()
2222

23+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_CURRENT_SOURCE_DIR}/../../cmake/)
24+
include(PreventInSourceBuilds)
25+
2326
set(MODULE_NAME "iFreeRDP")
2427
set(MODULE_PREFIX "IFREERDP_CLIENT")
2528
set(APP_TYPE MACOSX_BUNDLE)

cmake/PreventInSourceBuilds.cmake

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# PreventInSourceBuilds
2+
# ---------------------
3+
#
4+
# Prevent in-source builds
5+
#
6+
# It is generally acknowledged that it is preferable to run CMake out of source,
7+
# in a dedicated build directory. To prevent users from accidentally running
8+
# CMake in the source directory, just include this module.
9+
10+
# make sure the user doesn't play dirty with symlinks
11+
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
12+
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
13+
14+
# disallow in-source builds
15+
if("${srcdir}" STREQUAL "${bindir}")
16+
message(FATAL_ERROR "\
17+
18+
CMake must not to be run in the source directory. \
19+
Rather create a dedicated build directory and run CMake there. \
20+
CMake now already created some files, to clean up after this aborted in-source compilation:
21+
rm -r CMakeCache.txt CMakeFiles
22+
or
23+
git clean -xdf
24+
")
25+
endif()
26+

rdtk/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ endif()
6565

6666
# Include our extra modules
6767
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/)
68+
include(PreventInSourceBuilds)
6869

6970
# Include cmake modules
7071
include(CheckIncludeFiles)

uwac/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ option(UWAC_HAVE_PIXMAN_REGION "Use PIXMAN or FreeRDP for region calculations" "
5858

5959
# Include our extra modules
6060
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/)
61+
include(PreventInSourceBuilds)
6162

6263
# Check for cmake compatibility (enable/disable features)
6364
include(FindFeature)

winpr/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ include(CheckSymbolExists)
115115
include(CheckStructHasMember)
116116
include(TestBigEndian)
117117

118+
include(PreventInSourceBuilds)
119+
118120
# Check for cmake compatibility (enable/disable features)
119121
include(CheckCmakeCompat)
120122
include(FindFeature)
@@ -355,4 +357,3 @@ install(EXPORT WinPRTargets DESTINATION ${WINPR_CMAKE_INSTALL_DIR})
355357
include(pkg-config-install-prefix)
356358
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc @ONLY)
357359
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/winpr${WINPR_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
358-

0 commit comments

Comments
 (0)