From d6a8e08acc529999c50c019bbb25260c9d91e7a1 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 21 Oct 2018 15:02:40 +0000 Subject: [PATCH] cmake: fix variable expand in CMake conditions --- CMakeLists.txt | 4 ++++ cmake/OpenCVCompilerOptimizations.cmake | 6 +++--- cmake/OpenCVDetectCUDA.cmake | 4 ++-- cmake/OpenCVDetectVTK.cmake | 8 ++++---- cmake/OpenCVFindIPP.cmake | 4 ++-- cmake/OpenCVFindMKL.cmake | 2 +- cmake/OpenCVModule.cmake | 4 ++-- cmake/OpenCVPackaging.cmake | 2 +- cmake/templates/OpenCVConfig-CUDA.cmake.in | 2 +- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de27a744d8..3204fabb86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,10 @@ if(POLICY CMP0051) cmake_policy(SET CMP0051 NEW) endif() +if(POLICY CMP0054) # CMake 3.1: Only interpret if() arguments as variables or keywords when unquoted. + cmake_policy(SET CMP0054 NEW) +endif() + if(POLICY CMP0056) cmake_policy(SET CMP0056 NEW) endif() diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 377eb98a65..6710ba7e76 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -50,13 +50,13 @@ endforeach() # process legacy flags macro(ocv_optimization_process_obsolete_option legacy_flag OPT legacy_warn) - if(DEFINED ${legacy_flag}) - if(${legacy_warn}) + if(DEFINED "${legacy_flag}") + if("${legacy_warn}") message(STATUS "WARNING: Option ${legacy_flag}='${${legacy_flag}}' is deprecated and should not be used anymore") message(STATUS " Behaviour of this option is not backward compatible") message(STATUS " Refer to 'CPU_BASELINE'/'CPU_DISPATCH' CMake options documentation") endif() - if(${legacy_flag}) + if("${legacy_flag}") if(NOT ";${CPU_BASELINE_REQUIRE};" MATCHES ";${OPT};") set(CPU_BASELINE_REQUIRE "${CPU_BASELINE_REQUIRE};${OPT}" CACHE STRING "${HELP_CPU_BASELINE_REQUIRE}" FORCE) endif() diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index ee4e7cea64..eb7e79a800 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -114,9 +114,9 @@ if(CUDA_FOUND) endif() set(__cuda_arch_ptx "") else() - if(${CUDA_VERSION} VERSION_LESS "9.0") + if(CUDA_VERSION VERSION_LESS "9.0") set(__cuda_arch_bin "2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1") - elseif(${CUDA_VERSION} VERSION_LESS "10.0") + elseif(CUDA_VERSION VERSION_LESS "10.0") set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1 7.0") else() set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5") diff --git a/cmake/OpenCVDetectVTK.cmake b/cmake/OpenCVDetectVTK.cmake index f16077755a..14956886e3 100644 --- a/cmake/OpenCVDetectVTK.cmake +++ b/cmake/OpenCVDetectVTK.cmake @@ -20,27 +20,27 @@ if(NOT VTK_FOUND) endif() # Don't support earlier VTKs -if(${VTK_VERSION} VERSION_LESS "5.8.0") +if(VTK_VERSION VERSION_LESS "5.8.0") message(STATUS "VTK support is disabled. VTK ver. 5.8.0 is minimum required, but found VTK ver. ${VTK_VERSION}") return() endif() # Different Qt versions can't be linked together -if(HAVE_QT5 AND ${VTK_VERSION} VERSION_LESS "6.0.0") +if(HAVE_QT5 AND VTK_VERSION VERSION_LESS "6.0.0") if(VTK_USE_QT) message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") endif() endif() # Different Qt versions can't be linked together. VTK 6.0.0 doesn't provide a way to get Qt version it was linked with -if(HAVE_QT5 AND ${VTK_VERSION} VERSION_EQUAL "6.0.0" AND NOT DEFINED FORCE_VTK) +if(HAVE_QT5 AND VTK_VERSION VERSION_EQUAL "6.0.0" AND NOT DEFINED FORCE_VTK) message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt5, and VTK ver.${VTK_VERSION} with Qt4") message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DFORCE_VTK=TRUE' flag in CMake") return() endif() # Different Qt versions can't be linked together -if(HAVE_QT AND ${VTK_VERSION} VERSION_GREATER "6.0.0" AND NOT ${VTK_QT_VERSION} STREQUAL "") +if(HAVE_QT AND VTK_VERSION VERSION_GREATER "6.0.0" AND NOT ${VTK_QT_VERSION} STREQUAL "") if(HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "4") message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") return() diff --git a/cmake/OpenCVFindIPP.cmake b/cmake/OpenCVFindIPP.cmake index 52c8d50638..13d73d1ca1 100644 --- a/cmake/OpenCVFindIPP.cmake +++ b/cmake/OpenCVFindIPP.cmake @@ -105,7 +105,7 @@ macro(ipp_detect_version) message(STATUS "found Intel IPP${__msg}: ${_MAJOR}.${_MINOR}.${_BUILD} [${IPP_VERSION_STR}]") message(STATUS "at: ${IPP_ROOT_DIR}") - if(${IPP_VERSION_STR} VERSION_LESS "7.0") + if(IPP_VERSION_STR VERSION_LESS "7.0") _ipp_not_supported("Intel IPP ${IPP_VERSION_STR} is not supported") endif() @@ -166,7 +166,7 @@ macro(ipp_detect_version) endmacro() set(IPP_PREFIX "ipp") - if(${IPP_VERSION_STR} VERSION_LESS "8.0") + if(IPP_VERSION_STR VERSION_LESS "8.0") if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV) set(IPP_SUFFIX "") # dynamic not threaded libs suffix Intel IPP 7.x else () diff --git a/cmake/OpenCVFindMKL.cmake b/cmake/OpenCVFindMKL.cmake index d920672fbe..5eee3f5daa 100644 --- a/cmake/OpenCVFindMKL.cmake +++ b/cmake/OpenCVFindMKL.cmake @@ -94,7 +94,7 @@ else() set(MKL_ARCH_SUFFIX "c") endif() -if(${MKL_VERSION_STR} VERSION_GREATER "11.3.0" OR ${MKL_VERSION_STR} VERSION_EQUAL "11.3.0") +if(MKL_VERSION_STR VERSION_GREATER "11.3.0" OR MKL_VERSION_STR VERSION_EQUAL "11.3.0") set(mkl_lib_find_paths ${MKL_ROOT_DIR}/lib ${MKL_ROOT_DIR}/lib/${MKL_ARCH} ${MKL_ROOT_DIR}/../tbb/lib/${MKL_ARCH}) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index c0b189836f..495787ff81 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -615,7 +615,7 @@ function(__ocv_resolve_dependencies) list(APPEND LINK_DEPS opencv_world) endif() endif() - if(${m} STREQUAL opencv_world) + if("${m}" STREQUAL opencv_world) list(APPEND OPENCV_MODULE_opencv_world_DEPS_EXT ${OPENCV_MODULE_${m2}_DEPS_EXT}) endif() endif() @@ -842,7 +842,7 @@ macro(ocv_create_module) if(NOT " ${ARGN}" STREQUAL " ") set(OPENCV_MODULE_${the_module}_LINK_DEPS "${OPENCV_MODULE_${the_module}_LINK_DEPS};${ARGN}" CACHE INTERNAL "") endif() - if(${BUILD_opencv_world} AND OPENCV_MODULE_${the_module}_IS_PART_OF_WORLD) + if(BUILD_opencv_world AND OPENCV_MODULE_${the_module}_IS_PART_OF_WORLD) # nothing set(the_module_target opencv_world) else() diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake index 32537982f9..9b98268b71 100644 --- a/cmake/OpenCVPackaging.cmake +++ b/cmake/OpenCVPackaging.cmake @@ -89,7 +89,7 @@ set(CPACK_COMPONENT_TESTS_DEPENDS libs) if(HAVE_CUDA) string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION}) - if(${CUDA_VERSION} VERSION_LESS "6.5") + if(CUDA_VERSION VERSION_LESS "6.5") set(CPACK_DEB_libs_PACKAGE_DEPENDS "cuda-core-libs-${cuda_version_suffix}, cuda-extra-libs-${cuda_version_suffix}") set(CPACK_DEB_dev_PACKAGE_DEPENDS "cuda-headers-${cuda_version_suffix}") else() diff --git a/cmake/templates/OpenCVConfig-CUDA.cmake.in b/cmake/templates/OpenCVConfig-CUDA.cmake.in index 0d261dd84b..b48cfba5b0 100644 --- a/cmake/templates/OpenCVConfig-CUDA.cmake.in +++ b/cmake/templates/OpenCVConfig-CUDA.cmake.in @@ -16,7 +16,7 @@ endif() set(OpenCV_CUDA_LIBS_ABSPATH ${CUDA_LIBRARIES}) -if(${CUDA_VERSION} VERSION_LESS "5.5") +if(CUDA_VERSION VERSION_LESS "5.5") list(APPEND OpenCV_CUDA_LIBS_ABSPATH ${CUDA_npp_LIBRARY}) else() find_cuda_helper_libs(nppc)