Commit 2cb719f3 authored by jcfr's avatar jcfr

BUG: Consider inner build dir when checking for max root directory length.

This commit introduces the convenience CMake module "PreventDirWithTooManyChars"
and update code to account for length of the inner build subdirectory.

It means if the maximum length of the top-level build directory is 40,
assuming the inner build directory is "Slicer-build", the check in
the inner build will expect a path of length 53.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@23361 3bd1e089-480b-0410-8dfb-8563597acbee
parent 114526a2
#
# This function will prevent building the project from a source or build directory having
# too many characters.
#
# The maximum path length should be specified setting the variable ${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH.
# For example:
#
# set(${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH 40)
#
# To skip the directory length check, the project can be configured with:
#
# -D<PROJECT_NAME>_SKIP_ROOT_DIR_MAX_LENGTH_CHECK:BOOL=TRUE
#
function(AssureLengthForSourceOrBuildDir max_length)
function(_check_path_length path description)
string(LENGTH "${path}" n)
if(n GREATER ${max_length})
string(SUBSTRING "${path}" 0 ${max_length} _expected_path)
message(
FATAL_ERROR
"The current ${description} directory has too many characters:\n"
" current path:\n"
" ${path} [${n} chars]\n"
" expected path:\n"
" ${_expected_path} [${max_length} chars]\n"
""
"Please use a shorter directory for ${PROJECT_NAME} ${description} directory.\n"
""
"To ignore this error, reconfigure with the following option:\n"
" -D${PROJECT_NAME}_SKIP_ROOT_DIR_MAX_LENGTH_CHECK:BOOL=TRUE\n"
)
endif()
endfunction()
_check_path_length("${CMAKE_CURRENT_SOURCE_DIR}" "source")
_check_path_length("${CMAKE_CURRENT_BINARY_DIR}" "binary")
endfunction()
if(NOT DEFINED ${PROJECT_NAME}_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
set(${PROJECT_NAME}_SKIP_ROOT_DIR_MAX_LENGTH_CHECK FALSE)
endif()
if(NOT ${PROJECT_NAME}_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
if("${${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH}" STREQUAL "")
message(FATAL_ERROR "Variable ${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH should be set to an integer value > 0.")
endif()
AssureLengthForSourceOrBuildDir(${${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH})
endif()
......@@ -41,6 +41,13 @@ set(Slicer_EXTENSIONS_CMAKE_DIR ${Slicer_SOURCE_DIR}/Extensions/CMake)
#-----------------------------------------------------------------------------
include(SlicerCheckSourceTree)
#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#-----------------------------------------------------------------------------
option(Slicer_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
mark_as_advanced(Slicer_SUPERBUILD)
set(Slicer_BINARY_INNER_SUBDIR Slicer-build)
#-----------------------------------------------------------------------------
include(CTestUseLaunchers OPTIONAL)
if(${CTEST_USE_LAUNCHERS})
......@@ -51,27 +58,12 @@ endif()
# Sanity checks
#------------------------------------------------------------------------------
if(WIN32)
option(Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK "Skip root directory length check" OFF)
mark_as_advanced(Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
if(NOT Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
set(root_directory_max_length 40)
string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n)
if(n GREATER ${root_directory_max_length})
message(
FATAL_ERROR
"Source tree directory of ${PROJECT_NAME} is too deep (${n} > ${root_directory_max_length})."
"Please use a shorter root directory for the ${PROJECT_NAME} source tree."
)
endif()
string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n)
if(n GREATER ${root_directory_max_length})
message(
FATAL_ERROR
"Binary tree directory of ${PROJECT_NAME} is too deep (${n} > ${root_directory_max_length})."
"Please use a shorter root directory for the ${PROJECT_NAME} binary tree."
)
endif()
set(${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH 40)
if(NOT ${PROJECT_NAME}_SUPERBUILD)
string(LENGTH ${Slicer_BINARY_INNER_SUBDIR} _inner_subdir_length)
math(EXPR ${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH "${${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH} + ${_inner_subdir_length}")
endif()
include(PreventDirWithTooManyChars)
endif()
include(PreventInSourceBuilds)
include(PreventInBuildInstalls)
......@@ -155,14 +147,6 @@ if(NOT DEFINED Slicer_REQUIRED_QT_VERSION)
endif()
mark_as_superbuild(Slicer_REQUIRED_QT_VERSION)
#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#-----------------------------------------------------------------------------
option(Slicer_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
mark_as_advanced(Slicer_SUPERBUILD)
set(Slicer_BINARY_INNER_SUBDIR Slicer-build)
#-----------------------------------------------------------------------------
# Build shared lib by default
#------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment