Cleanup use of CMake version in install destinations

Factor the CMAKE_DATA_DIR, CMAKE_DOC_DIR, and CMAKE_MAN_DIR selection
out of CMakeLists.txt and into a Source/CMakeInstallDestinations.cmake
script.  Load the script from the original location of the code.

Cache the destination values as empty strings so we know if the user
sets them explicitly.  If not, then compute defaults based on the
platform and full CMake version string.  By not caching the versioned
defaults, we can change them in a single build tree as the version
changes.

Remove duplication of the install destination defaults from the
bootstrap script.  Cache empty defaults there too.  Parse from the CMake
code the default values to report in the help output.  Keep the CMake
code in a structured format to make this reliable.
This commit is contained in:
Brad King 2013-09-26 14:13:38 -04:00
parent c72f8513f7
commit c9a5f34bd7
3 changed files with 68 additions and 30 deletions

View File

@ -432,27 +432,8 @@ set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
# install tree.
set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
set(CMAKE_DATA_DIR "share/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}" CACHE STRING
"Install location for data (relative to prefix).")
set(CMAKE_DOC_DIR "doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}" CACHE STRING
"Install location for documentation (relative to prefix).")
set(CMAKE_MAN_DIR "man" CACHE STRING
"Install location for man pages (relative to prefix).")
mark_as_advanced(CMAKE_DATA_DIR CMAKE_DOC_DIR CMAKE_MAN_DIR)
if(CYGWIN AND EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
# Force doc, data and man dirs to conform to cygwin layout.
set(CMAKE_DOC_DIR "share/doc/cmake-${CMake_VERSION}")
set(CMAKE_DATA_DIR "share/cmake-${CMake_VERSION}")
set(CMAKE_MAN_DIR "share/man")
# let the user know we just forced these values
message(STATUS "Setup for Cygwin packaging")
message(STATUS "Override cache CMAKE_DOC_DIR = ${CMAKE_DOC_DIR}")
message(STATUS "Override cache CMAKE_DATA_DIR = ${CMAKE_DATA_DIR}")
message(STATUS "Override cache CMAKE_MAN_DIR = ${CMAKE_MAN_DIR}")
endif()
string(REGEX REPLACE "^/" "" CMAKE_DATA_DIR "${CMAKE_DATA_DIR}")
string(REGEX REPLACE "^/" "" CMAKE_DOC_DIR "${CMAKE_DOC_DIR}")
string(REGEX REPLACE "^/" "" CMAKE_MAN_DIR "${CMAKE_MAN_DIR}")
# Load install destinations.
include(Source/CMakeInstallDestinations.cmake)
if(BUILD_TESTING)
include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)

View File

@ -0,0 +1,36 @@
# Keep formatting here consistent with bootstrap script expectations.
set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION}") # OTHER
if(BEOS)
set(CMAKE_MAN_DIR_DEFAULT "documentation/man") # HAIKU
set(CMAKE_DOC_DIR_DEFAULT "documentation/doc/cmake-${CMake_VERSION}") # HAIKU
elseif(CYGWIN)
set(CMAKE_DOC_DIR_DEFAULT "share/doc/cmake-${CMake_VERSION}") # CYGWIN
set(CMAKE_MAN_DIR_DEFAULT "share/man") # CYGWIN
else()
set(CMAKE_DOC_DIR_DEFAULT "doc/cmake-${CMake_VERSION}") # OTHER
set(CMAKE_MAN_DIR_DEFAULT "man") # OTHER
endif()
set(CMAKE_DATA_DIR_DESC "data")
set(CMAKE_DOC_DIR_DESC "docs")
set(CMAKE_MAN_DIR_DESC "man pages")
foreach(v
CMAKE_DATA_DIR
CMAKE_DOC_DIR
CMAKE_MAN_DIR
)
# Populate the cache with empty values so we know when the user sets them.
set(${v} "" CACHE STRING "")
set_property(CACHE ${v} PROPERTY HELPSTRING
"Location under install prefix for ${${v}_DESC} (default \"${${v}_DEFAULT}\")"
)
set_property(CACHE ${v} PROPERTY ADVANCED 1)
# Use the default when the user did not set this variable.
if(NOT ${v})
set(${v} "${${v}_DEFAULT}")
endif()
# Remove leading slash to treat as relative to install prefix.
string(REGEX REPLACE "^/" "" ${v} "${${v}}")
endforeach()

View File

@ -23,6 +23,15 @@ cmake_version_component()
"
}
# Install destination extraction function.
cmake_install_dest_default()
{
cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n '
/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/;p;q;}
'
}
cmake_toupper()
{
echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
@ -47,9 +56,12 @@ if [ "$cmake_version_rc" != "" ]; then
cmake_version="${cmake_version}-rc${cmake_version_rc}"
fi
cmake_data_dir="share/cmake-${cmake_version_major}.${cmake_version_minor}"
cmake_doc_dir="doc/cmake-${cmake_version_major}.${cmake_version_minor}"
cmake_man_dir="man"
cmake_data_dir_keyword="OTHER"
cmake_doc_dir_keyword="OTHER"
cmake_man_dir_keyword="OTHER"
cmake_data_dir=""
cmake_doc_dir=""
cmake_man_dir=""
cmake_init_file=""
cmake_bootstrap_system_libs=""
cmake_bootstrap_qt_gui=""
@ -58,6 +70,8 @@ cmake_bootstrap_qt_qmake=""
# Determine whether this is a Cygwin environment.
if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
cmake_system_cygwin=true
cmake_doc_dir_keyword="CYGWIN"
cmake_man_dir_keyword="CYGWIN"
else
cmake_system_cygwin=false
fi
@ -79,6 +93,8 @@ fi
# Determine whether this is BeOS
if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
cmake_system_beos=true
cmake_doc_dir_keyword="HAIKU"
cmake_man_dir_keyword="HAIKU"
else
cmake_system_beos=false
fi
@ -86,6 +102,8 @@ fi
# Determine whether this is Haiku
if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
cmake_system_haiku=true
cmake_doc_dir_keyword="HAIKU"
cmake_man_dir_keyword="HAIKU"
else
cmake_system_haiku=false
fi
@ -164,12 +182,15 @@ if ${cmake_system_mingw}; then
fi
elif ${cmake_system_haiku}; then
cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
cmake_man_dir="documentation/man"
cmake_doc_dir="documentation/doc/cmake-${cmake_version}"
else
cmake_default_prefix="/usr/local"
fi
# Lookup default install destinations.
cmake_data_dir_default="`cmake_install_dest_default DATA ${cmake_data_dir_keyword}`"
cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`"
cmake_man_dir_default="`cmake_install_dest_default MAN ${cmake_man_dir_keyword}`"
CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
@ -360,11 +381,11 @@ Directory and file names:
--prefix=PREFIX install files in tree rooted at PREFIX
['"${cmake_default_prefix}"']
--datadir=DIR install data files in PREFIX/DIR
['"${cmake_data_dir}"']
['"${cmake_data_dir_default}"']
--docdir=DIR install documentation files in PREFIX/DIR
['"${cmake_doc_dir}"']
['"${cmake_doc_dir_default}"']
--mandir=DIR install man pages files in PREFIX/DIR/manN
['"${cmake_man_dir}"']
['"${cmake_man_dir_default}"']
'
exit 10
}
@ -1408,7 +1429,7 @@ cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_PATCH ${cmake_versi
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_TWEAK ${cmake_version_tweak}"
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION \"${cmake_version}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_ROOT_DIR \"${cmake_root_dir}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/${cmake_data_dir}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP"
# Regenerate configured headers