authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-22 17:46:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-22 20:30:08-07:00
log0ae60f7236e4da0c234f59f3671f742695d54905
tree8e54ab9b65fc445bbb5f55d564c592afdec2b572
parentf82a82f889bb145fe83eb9cd366f920f10f6dcec

CMake: detect use of CMAKE_PREFIX_PATH env var

CMake recognizes the CMAKE_PREFIX_PATH environment variable for some things, and also the CMAKE_PREFIX_PATH cache variable for other things. However, it does not relate these two things, i.e. if the environment variable is set, CMake does not populate the cache variable in a corresponding manner. Some package systems, such as Homebrew, set the environment variable but not the cache variable. Furthermore, the environment variable follows the system path separator, such as ':' on POSIX and ';' on Windows, but the cache variable follows CMake's array behavior, i.e. always ';' for a separator. Closes #13242

2 files changed, 17 insertions(+), 1 deletions(-)

CMakeLists.txt+16
...@@ -16,6 +16,22 @@ if(NOT CMAKE_INSTALL_PREFIX)...@@ -16,6 +16,22 @@ if(NOT CMAKE_INSTALL_PREFIX)
16 "Directory to install zig to" FORCE)16 "Directory to install zig to" FORCE)
17endif()17endif()
1818
19# CMake recognizes the CMAKE_PREFIX_PATH environment variable for some things,
20# and also the CMAKE_PREFIX_PATH cache variable for other things. However, it
21# does not relate these two things, i.e. if the environment variable is set,
22# CMake does not populate the cache variable in a corresponding manner. Some
23# package systems, such as Homebrew, set the environment variable but not the
24# cache variable. Furthermore, the environment variable follows the system path
25# separator, such as ':' on POSIX and ';' on Windows, but the cache variable
26# follows CMake's array behavior, i.e. always ';' for a separator.
27list(APPEND ZIG_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
28if(WIN32)
29 list(APPEND ZIG_CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
30else()
31 string(REGEX REPLACE ":" ";" ZIG_CMAKE_PREFIX_PATH_STRING "$ENV{CMAKE_PREFIX_PATH}")
32 list(APPEND ZIG_CMAKE_PREFIX_PATH "${ZIG_CMAKE_PREFIX_PATH_STRING}")
33endif()
34
19set(CMAKE_USER_MAKE_RULES_OVERRIDE35set(CMAKE_USER_MAKE_RULES_OVERRIDE
20 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)36 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
21set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX37set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
src/stage1/config.h.in+1-1
...@@ -17,7 +17,7 @@...@@ -17,7 +17,7 @@
17// Used by build.zig for communicating build information to self hosted build.17// Used by build.zig for communicating build information to self hosted build.
18#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"18#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
19#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"19#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"
20#define ZIG_CMAKE_PREFIX_PATH "@CMAKE_PREFIX_PATH@"20#define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@"
21#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"21#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
22#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"22#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
23#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"23#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"