File: FindRootPathAndPrefixPathWithCommonSubdir.cmake

package info (click to toggle)
cmake 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 158,704 kB
  • sloc: ansic: 406,077; cpp: 309,512; sh: 4,233; python: 3,696; yacc: 3,109; lex: 1,279; f90: 538; asm: 471; lisp: 375; java: 310; cs: 270; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 110; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22; sed: 2
file content (50 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
set(regular_root "${CMAKE_CURRENT_SOURCE_DIR}/FindRootPathAndPrefixPathAreEqual")
set(regular_prefix "${regular_root}/lib/cmake")

# 'emptydir' must be a real dir on the file system, otherwise CMake
# won't canonicalize the path when getting resolving the real path.
set(dotted_root "${regular_root}/emptydir/..")
set(dotted_prefix "${dotted_root}/lib/cmake")

set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "ONLY")

# Case with no '..' in the paths
set(CMAKE_FIND_ROOT_PATH "${regular_root}")
set(CMAKE_PREFIX_PATH "${regular_prefix}")
message(STATUS "Looking for Foo without '..' in the paths")
find_package(Foo
             REQUIRED
             CONFIG
             NO_CMAKE_ENVIRONMENT_PATH
             NO_SYSTEM_ENVIRONMENT_PATH
             # Important because CMAKE_SYSTEM_PREFIX_PATH might contain "/" as a prefix
             # And when "/" is rerooted onto the root above, the package is found even if
             # CMAKE_PREFIX_PATH is empty. We want to ensure that we hit
             # the CMAKE_FIND_ROOT_PATH == CMAKE_PREFIX_PATH code path.
             NO_CMAKE_SYSTEM_PATH
             )
if(Foo_FOUND)
    message(STATUS "Foo found for case without '..' in the paths")
endif()

# Unset the cache variable to find the package again.
unset(Foo_DIR CACHE)

# Case with '..' in the paths
set(CMAKE_FIND_ROOT_PATH "${dotted_root}")
set(CMAKE_PREFIX_PATH "${dotted_prefix}")
message(STATUS "Looking for Foo with '..' in the paths")
find_package(Foo
             REQUIRED
             CONFIG
             NO_CMAKE_ENVIRONMENT_PATH
             NO_SYSTEM_ENVIRONMENT_PATH
             # Important because CMAKE_SYSTEM_PREFIX_PATH might contain "/" as a prefix
             # And when "/" is rerooted onto the root above, the package is found even if
             # CMAKE_PREFIX_PATH is empty. We want to ensure that we hit
             # the CMAKE_FIND_ROOT_PATH == CMAKE_PREFIX_PATH code path.
             NO_CMAKE_SYSTEM_PATH
             )
if(Foo_FOUND)
    message(STATUS "Foo found for case with '..' in the paths")
endif()