From fe057ab3cd2469af5440307f1bf2a4f69d686db3 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 29 Oct 2013 10:40:09 +0100 Subject: [PATCH] Allow disabling adding the install prefix to the prefix search path. In certain scenarios, it is preferable to keep a 'dirty' install prefix than to clear it, and to expect that content will not be found there. Add a CMAKE_FIND_NO_INSTALL_PREFIX variable that can be set to disable searching the install prefix. --- Help/manual/cmake-variables.7.rst | 1 + Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst | 13 +++++++++++++ Modules/Platform/UnixPaths.cmake | 9 ++++++--- Modules/Platform/WindowsPaths.cmake | 18 ++++++++++++------ Tests/RunCMake/CMakeLists.txt | 1 + .../RunCMake/no_install_prefix/CMakeLists.txt | 3 +++ .../no_install_prefix/RunCMakeTest.cmake | 15 +++++++++++++++ Tests/RunCMake/no_install_prefix/do_test.cmake | 2 ++ .../no_install_prefix-result.txt | 1 + .../no_install_prefix-stderr.txt | 18 ++++++++++++++++++ .../no_install_prefix/no_install_prefix.cmake | 2 ++ .../with_install_prefix-result.txt | 1 + .../with_install_prefix-stderr.txt | 1 + .../with_install_prefix.cmake | 2 ++ 14 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst create mode 100644 Tests/RunCMake/no_install_prefix/CMakeLists.txt create mode 100644 Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/no_install_prefix/do_test.cmake create mode 100644 Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt create mode 100644 Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt create mode 100644 Tests/RunCMake/no_install_prefix/no_install_prefix.cmake create mode 100644 Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt create mode 100644 Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt create mode 100644 Tests/RunCMake/no_install_prefix/with_install_prefix.cmake diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 22a1c4d98..157c38d02 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -88,6 +88,7 @@ Variables that Change Behavior /variable/CMAKE_FIND_LIBRARY_PREFIXES /variable/CMAKE_FIND_LIBRARY_SUFFIXES /variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE + /variable/CMAKE_FIND_NO_INSTALL_PREFIX /variable/CMAKE_IGNORE_PATH /variable/CMAKE_INCLUDE_PATH /variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME diff --git a/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst new file mode 100644 index 000000000..91231b079 --- /dev/null +++ b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst @@ -0,0 +1,13 @@ +CMAKE_FIND_NO_INSTALL_PREFIX +---------------------------- + +Ignore the :variable:`CMAKE_INSTALL_PREFIX` when searching for assets. + +CMake adds the :variable:`CMAKE_INSTALL_PREFIX` to the +:variable:`CMAKE_SYSTEM_PREFIX_PATH` by default. This variable may be set +on the command line to control that behavior. + +Set :variable:`CMAKE_FIND_NO_INSTALL_PREFIX` to TRUE to tell find_package not +to search in the :variable:`CMAKE_INSTALL_PREFIX` by default. Note that the +prefix may still be searched for other reasons, such as being the same prefix +as the CMake installation, or for being a built-in system prefix. diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake index ccb266330..7a424c442 100644 --- a/Modules/Platform/UnixPaths.cmake +++ b/Modules/Platform/UnixPaths.cmake @@ -37,10 +37,13 @@ list(APPEND CMAKE_SYSTEM_PREFIX_PATH # CMake install location "${_CMAKE_INSTALL_DIR}" - - # Project install destination. - "${CMAKE_INSTALL_PREFIX}" ) +if (NOT CMAKE_FIND_NO_INSTALL_PREFIX) + list(APPEND CMAKE_SYSTEM_PREFIX_PATH + # Project install destination. + "${CMAKE_INSTALL_PREFIX}" + ) +endif() # List common include file locations not under the common prefixes. list(APPEND CMAKE_SYSTEM_INCLUDE_PATH diff --git a/Modules/Platform/WindowsPaths.cmake b/Modules/Platform/WindowsPaths.cmake index fc921d793..c231495f0 100644 --- a/Modules/Platform/WindowsPaths.cmake +++ b/Modules/Platform/WindowsPaths.cmake @@ -73,11 +73,13 @@ get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH) get_filename_component(_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH) list(APPEND CMAKE_SYSTEM_PREFIX_PATH "${_CMAKE_INSTALL_DIR}") -# Add other locations. -list(APPEND CMAKE_SYSTEM_PREFIX_PATH - # Project install destination. - "${CMAKE_INSTALL_PREFIX}" - ) +if (NOT CMAKE_FIND_NO_INSTALL_PREFIX) + # Add other locations. + list(APPEND CMAKE_SYSTEM_PREFIX_PATH + # Project install destination. + "${CMAKE_INSTALL_PREFIX}" + ) +endif() if(CMAKE_CROSSCOMPILING AND NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") # MinGW (useful when cross compiling from linux with CMAKE_FIND_ROOT_PATH set) @@ -88,8 +90,12 @@ list(APPEND CMAKE_SYSTEM_INCLUDE_PATH ) # mingw can also link against dlls which can also be in /bin, so list this too +if (NOT CMAKE_FIND_NO_INSTALL_PREFIX) + list(APPEND CMAKE_SYSTEM_LIBRARY_PATH + "${CMAKE_INSTALL_PREFIX}/bin" + ) +endif() list(APPEND CMAKE_SYSTEM_LIBRARY_PATH - "${CMAKE_INSTALL_PREFIX}/bin" "${_CMAKE_INSTALL_DIR}/bin" /bin ) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 97bf14dbc..99a0fb3b2 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -109,6 +109,7 @@ add_RunCMake_test(CMP0004) add_RunCMake_test(TargetPolicies) add_RunCMake_test(alias_targets) add_RunCMake_test(interface_library) +add_RunCMake_test(no_install_prefix) find_package(Qt4 QUIET) find_package(Qt5Core QUIET) diff --git a/Tests/RunCMake/no_install_prefix/CMakeLists.txt b/Tests/RunCMake/no_install_prefix/CMakeLists.txt new file mode 100644 index 000000000..12cd3c775 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.4) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake b/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake new file mode 100644 index 000000000..292344999 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake @@ -0,0 +1,15 @@ +include(RunCMake) + +set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/prefix") + +file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/prefix") +file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/prefix/NoPrefix") +file(WRITE "${RunCMake_BINARY_DIR}/prefix/NoPrefix/NoPrefixConfig.cmake" "") +set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_BINARY_DIR}/prefix") +run_cmake(with_install_prefix) + +file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/prefix") +file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/prefix/NoPrefix") +file(WRITE "${RunCMake_BINARY_DIR}/prefix/NoPrefix/NoPrefixConfig.cmake" "") +list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_FIND_NO_INSTALL_PREFIX=1") +run_cmake(no_install_prefix) diff --git a/Tests/RunCMake/no_install_prefix/do_test.cmake b/Tests/RunCMake/no_install_prefix/do_test.cmake new file mode 100644 index 000000000..340c7dcc9 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/do_test.cmake @@ -0,0 +1,2 @@ + +find_package(NoPrefix REQUIRED) diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt b/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt b/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt new file mode 100644 index 000000000..66c624123 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt @@ -0,0 +1,18 @@ +CMake Error at do_test.cmake:2 \(find_package\): + By not providing "FindNoPrefix.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NoPrefix", + but CMake did not find one. + + Could not find a package configuration file provided by "NoPrefix" with any + of the following names: + + NoPrefixConfig.cmake + noprefix-config.cmake + + Add the installation prefix of "NoPrefix" to CMAKE_PREFIX_PATH or set + "NoPrefix_DIR" to a directory containing one of the above files. If + "NoPrefix" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + no_install_prefix.cmake:2 \(include\) + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake b/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake new file mode 100644 index 000000000..c7d28daa8 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/no_install_prefix.cmake @@ -0,0 +1,2 @@ + +include(do_test.cmake) diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt b/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt b/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt new file mode 100644 index 000000000..10f32932e --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt @@ -0,0 +1 @@ +^$ diff --git a/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake b/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake new file mode 100644 index 000000000..c7d28daa8 --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake @@ -0,0 +1,2 @@ + +include(do_test.cmake)