Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / RunCMake / find_package / RunCMakeTest.cmake
1 include(RunCMake)
2
3 run_cmake(CMP0074-WARN)
4 run_cmake(CMP0074-OLD)
5 run_cmake(ComponentRequiredAndOptional)
6 run_cmake(FromPATHEnv)
7 run_cmake_with_options(FromPATHEnvDebugPkg --debug-find-pkg=Resolved)
8 run_cmake(FromPrefixPath)
9 run_cmake(GlobalImportTarget)
10 run_cmake(MissingNormal)
11 run_cmake(MissingNormalForceRequired)
12 run_cmake(MissingNormalRequired)
13 run_cmake(MissingNormalVersion)
14 run_cmake(MissingNormalWarnNoModuleOld)
15 run_cmake(MissingNormalWarnNoModuleNew)
16 run_cmake(MissingModule)
17 run_cmake(MissingModuleRequired)
18 run_cmake(MissingConfig)
19 run_cmake(MissingConfigDebug)
20 run_cmake_with_options(MissingConfigDebugPkg --debug-find-pkg=NotHere)
21 run_cmake(MissingConfigOneName)
22 run_cmake(MissingConfigRequired)
23 run_cmake(MissingConfigVersion)
24 run_cmake(MixedModeOptions)
25 run_cmake_with_options(ModuleModeDebugPkg --debug-find-pkg=Foo,Zot)
26 run_cmake(PackageRoot)
27 run_cmake(PackageRootNestedConfig)
28 run_cmake(PackageRootNestedModule)
29 run_cmake(PolicyPush)
30 run_cmake(PolicyPop)
31 run_cmake(RequiredOptionValuesClash)
32 run_cmake(FindRootPathAndPrefixPathAreEqual)
33 run_cmake(SetFoundFALSE)
34 run_cmake(WrongVersion)
35 run_cmake(WrongVersionConfig)
36 run_cmake(CMP0084-OLD)
37 run_cmake(CMP0084-WARN)
38 run_cmake(CMP0084-NEW)
39 run_cmake(WrongVersionRange)
40 run_cmake(EmptyVersionRange)
41 run_cmake(VersionRangeWithEXACT)
42 run_cmake(VersionRange)
43 run_cmake(VersionRange2)
44 run_cmake(VersionRange3)
45 run_cmake(VersionRange4)
46 run_cmake(VersionRangeConfig)
47 run_cmake(VersionRangeConfig2)
48 run_cmake(VersionRangeConfig02)
49 run_cmake(VersionRangeConfigStd)
50 run_cmake(VersionRangeConfigStd2)
51 run_cmake_with_options(IgnoreInstallPrefix  "-DCMAKE_INSTALL_PREFIX=${RunCMake_SOURCE_DIR}/PackageRoot/foo/cmake_root")
52 run_cmake(IgnorePath)
53 run_cmake(IgnorePrefixPath)
54 run_cmake(REGISTRY_VIEW-no-view)
55 run_cmake(REGISTRY_VIEW-wrong-view)
56 run_cmake(REGISTRY_VIEW-propagated)
57
58 file(
59     GLOB SearchPaths_TEST_CASE_LIST
60     LIST_DIRECTORIES TRUE
61     "${RunCMake_SOURCE_DIR}/SearchPaths/*"
62   )
63 foreach(TestCasePrefix IN LISTS SearchPaths_TEST_CASE_LIST)
64   if(IS_DIRECTORY "${TestCasePrefix}")
65     cmake_path(GET TestCasePrefix FILENAME TestSuffix)
66     run_cmake_with_options(
67       SearchPaths_${TestSuffix}
68         "-DSearchPaths_ROOT=${TestCasePrefix}"
69         "--debug-find-pkg=SearchPaths"
70       )
71   endif()
72 endforeach()
73
74 if(UNIX
75     AND NOT MSYS # FIXME: This works on CYGWIN but not on MSYS
76     )
77   run_cmake(SetFoundResolved)
78 endif()
79
80 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
81   # Tests using the Windows registry
82   find_program(REG NAMES "reg.exe" NO_CACHE)
83   if (REG)
84     ## check host architecture
85     cmake_host_system_information(RESULT result QUERY WINDOWS_REGISTRY "HKCU" SUBKEYS VIEW 64 ERROR_VARIABLE status)
86     if (status STREQUAL "")
87       set(ARCH "64bit")
88     else()
89       set(ARCH "32bit")
90     endif()
91
92     # crete some entries in the registry
93     cmake_path(CONVERT "${RunCMake_SOURCE_DIR}/registry_host${ARCH}.reg" TO_NATIVE_PATH_LIST registry_data)
94     execute_process(COMMAND "${REG}" import "${registry_data}" OUTPUT_QUIET ERROR_QUIET)
95
96     run_cmake_with_options(Registry-query -DARCH=${ARCH})
97
98     # clean-up registry
99     execute_process(COMMAND "${REG}" delete "HKCU\\SOFTWARE\\Classes\\CLSID\\CMake-Tests\\find_package" /f OUTPUT_QUIET ERROR_QUIET)
100     if (ARCH STREQUAL "64bit")
101       execute_process(COMMAND "${REG}" delete "HKCU\\SOFTWARE\\Classes\\WOW6432Node\\CLSID\\CMake-Tests\\find_package" /f OUTPUT_QUIET ERROR_QUIET)
102     endif()
103   endif()
104 endif()