diff options
-rw-r--r-- | Help/manual/cmake-variables.7.rst | 1 | ||||
-rw-r--r-- | Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst | 13 | ||||
-rw-r--r-- | Modules/Platform/UnixPaths.cmake | 9 | ||||
-rw-r--r-- | Modules/Platform/WindowsPaths.cmake | 18 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/RunCMakeTest.cmake | 15 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/do_test.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/no_install_prefix-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/no_install_prefix-stderr.txt | 18 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/no_install_prefix.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/with_install_prefix-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/with_install_prefix-stderr.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/no_install_prefix/with_install_prefix.cmake | 2 |
14 files changed, 78 insertions, 9 deletions
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index dccaf64..2fc02a1 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -90,6 +90,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 0000000..91231b0 --- /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 ccb2663..7a424c4 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 fc921d7..c231495 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 97bf14d..99a0fb3 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 0000000..12cd3c7 --- /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 0000000..2923449 --- /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 0000000..340c7dc --- /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 0000000..d00491f --- /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 0000000..66c6241 --- /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 0000000..c7d28da --- /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 0000000..573541a --- /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 0000000..10f3293 --- /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 0000000..c7d28da --- /dev/null +++ b/Tests/RunCMake/no_install_prefix/with_install_prefix.cmake @@ -0,0 +1,2 @@ + +include(do_test.cmake) |