From cb30eb91b8a0265c620e155b4b2acf916cab20a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Wed, 14 May 2014 15:08:22 +0200 Subject: Do not fail if vars like CMAKE_INSTALL_LIBDIR are defined as normal vars REVIEW: 118127 --- kde-modules/KDEInstallDirs.cmake | 15 +++++++++------ tests/CMakeLists.txt | 1 + tests/KDEInstallDirsTest/CMakeLists.txt | 7 +++++++ .../KDEInstallDirsTest/not_cache_variable/CMakeLists.txt | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/KDEInstallDirsTest/CMakeLists.txt create mode 100644 tests/KDEInstallDirsTest/not_cache_variable/CMakeLists.txt diff --git a/kde-modules/KDEInstallDirs.cmake b/kde-modules/KDEInstallDirs.cmake index 6102d9e5..061e542b 100644 --- a/kde-modules/KDEInstallDirs.cmake +++ b/kde-modules/KDEInstallDirs.cmake @@ -247,12 +247,15 @@ macro(_define_relative varname parent subdir docstring) CACHE PATH "${docstring} (${_docpath})") set(CMAKE_INSTALL_${varname} "${_realpath}") else() - # make sure the docs are still set if it was passed on the command line - set_property(CACHE CMAKE_INSTALL_${varname} - PROPERTY HELPSTRING "${docstring} (${_docpath})") - # make sure the type is correct if it was passed on the command line - set_property(CACHE CMAKE_INSTALL_${varname} - PROPERTY TYPE PATH) + get_property(_iscached CACHE CMAKE_INSTALL_${varname} PROPERTY VALUE SET) + if (_iscached) + # make sure the docs are still set if it was passed on the command line + set_property(CACHE CMAKE_INSTALL_${varname} + PROPERTY HELPSTRING "${docstring} (${_docpath})") + # make sure the type is correct if it was passed on the command line + set_property(CACHE CMAKE_INSTALL_${varname} + PROPERTY TYPE PATH) + endif() endif() if(_oldstylename) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cc11aec2..ad341c00 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(ECMGenerateHeadersTest) add_subdirectory(ECMSetupVersionTest) +add_subdirectory(KDEInstallDirsTest) macro(ADD_TEST_MACRO NAME COMMAND) string(REPLACE "." "/" dir "${NAME}") diff --git a/tests/KDEInstallDirsTest/CMakeLists.txt b/tests/KDEInstallDirsTest/CMakeLists.txt new file mode 100644 index 00000000..ad3febe5 --- /dev/null +++ b/tests/KDEInstallDirsTest/CMakeLists.txt @@ -0,0 +1,7 @@ +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/not_cache_variable) + +add_test( + NAME KDEInstallDirs_not_cache_variable + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/not_cache_variable + COMMAND "${CMAKE_COMMAND}" "${CMAKE_CURRENT_SOURCE_DIR}/not_cache_variable" + ) diff --git a/tests/KDEInstallDirsTest/not_cache_variable/CMakeLists.txt b/tests/KDEInstallDirsTest/not_cache_variable/CMakeLists.txt new file mode 100644 index 00000000..b78c10d7 --- /dev/null +++ b/tests/KDEInstallDirsTest/not_cache_variable/CMakeLists.txt @@ -0,0 +1,7 @@ +# Test KDEInstallDirs does not crash if a variable like CMAKE_INSTALL_LIBDIR is +# defined but is not a cache variable. +cmake_minimum_required(VERSION 2.8) +set(kde_modules_dir ${CMAKE_SOURCE_DIR}/../../../kde-modules) + +set(CMAKE_INSTALL_LIBDIR "foo") +include(${kde_modules_dir}/KDEInstallDirs.cmake) -- cgit v1.2.1