summaryrefslogtreecommitdiffstats
path: root/packaging/cmake/Modules/FindGo.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/cmake/Modules/FindGo.cmake')
-rw-r--r--packaging/cmake/Modules/FindGo.cmake35
1 files changed, 32 insertions, 3 deletions
diff --git a/packaging/cmake/Modules/FindGo.cmake b/packaging/cmake/Modules/FindGo.cmake
index 454a0051e..69e23fda6 100644
--- a/packaging/cmake/Modules/FindGo.cmake
+++ b/packaging/cmake/Modules/FindGo.cmake
@@ -15,8 +15,22 @@ if(GO_FOUND)
return()
endif()
-# Two passes are needed here so that we prefer a copy in `/usr/local/go/bin` over a system copy.
-find_program(GO_EXECUTABLE go PATHS /usr/local/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
+# The complexity below is needed to account for the complex rules we use for finding the Go install.
+#
+# If GOROOT is set, we honor that. Otherwise, we check known third-party install paths for the platform in question
+# and fall back to looking in PATH. For the specific case of MSYS2, we prefer a Windows install over an MSYS2 install.
+if(DEFINED $ENV{GOROOT})
+ find_program(GO_EXECUTABLE go PATHS "$ENV{GOROOT}/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
+ set(GO_ROOT $ENV{GOROOT})
+elseif(OS_WINDOWS)
+ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ find_program(GO_EXECUTABLE go PATHS C:/go/bin "C:/Program Files/go/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
+ else()
+ find_program(GO_EXECUTABLE go PATHS /c/go/bin "/c/Program Files/go/bin" /mingw64/lib/go/bin /ucrt64/lib/go/bin /clang64/lib/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
+ endif()
+else()
+ find_program(GO_EXECUTABLE go PATHS /usr/local/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
+endif()
find_program(GO_EXECUTABLE go DOC "Go toolchain")
if (GO_EXECUTABLE)
@@ -28,12 +42,27 @@ if (GO_EXECUTABLE)
if (RESULT EQUAL 0)
string(REGEX MATCH "go([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
+ else()
+ unset(GO_VERSION_STRING)
+ endif()
+
+ if(NOT DEFINED GO_ROOT)
+ execute_process(
+ COMMAND ${GO_EXECUTABLE} env GOROOT
+ OUTPUT_VARIABLE GO_ROOT
+ RESULT_VARIABLE RESULT
+ )
+ if(RESULT EQUAL 0)
+ string(REGEX REPLACE "\n$" "" GO_ROOT "${GO_ROOT}")
+ else()
+ unset(GO_ROOT)
+ endif()
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Go
- REQUIRED_VARS GO_EXECUTABLE
+ REQUIRED_VARS GO_EXECUTABLE GO_ROOT
VERSION_VAR GO_VERSION_STRING
)