- Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathFindMono.cmake
108 lines (101 loc) · 3.25 KB
/
FindMono.cmake
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright 2021 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Locates the Mono launcher and build tool.
#
# Optional variable arguments for this module:
# MONO_DIR: Variable to specify a search path for Mono.
# MONO_DISABLE_VISUAL_STUDIO_FALLBACK: Do not use Visual Studio's msbuild
# as a fallback on Windows when using the Visual Studio project generator.
#
# Cache variables set by this module:
# MONO_EXE: Location of the Mono interpreter executable.
# MONO_VERSION: Version of the detected Mono installation.
# MONO_CSHARP_BUILD_EXE: Location of the tool (e.g msbuild or xbuild) that
# can build .csproj projects.
# If MONO_DIR is specified, only search that path.
set(FIND_MONO_OPTIONS "")
if(EXISTS"${MONO_DIR}")
set(FIND_MONO_OPTIONS
PATHS
"${MONO_DIR}"
"${MONO_DIR}/lib/mono"
PATH_SUFFIXES
bin
NO_DEFAULT_PATH
)
endif()
# Search for Mono tools.
find_program(MONO_EXE mono
${FIND_MONO_OPTIONS}
)
find_program(MONO_CSHARP_BUILD_EXE
NAMES
msbuild
xbuild
${FIND_MONO_OPTIONS}
)
if(CMAKE_HOST_WIN32AND
NOT MONO_DISABLE_VISUAL_STUDIO_FALLBACK AND
EXISTS"${CMAKE_VS_MSBUILD_COMMAND}")
if(NOT MONO_CSHARP_BUILD_EXE)
# If Mono's build tool isn't found, fallback to Visual Studio.
message(STATUS"Mono installation not found, trying to fallback "
"to Visual Studio's msbuild ${CMAKE_VS_MSBUILD_COMMAND}."
)
set(MONO_CSHARP_BUILD_EXE "${CMAKE_VS_MSBUILD_COMMAND}"
CACHESTRING"" FORCE
)
endif()
if(NOT MONO_EXE)
# Just use cmake to launch the C# executable which should run on Windows if
# the .NET framework is installed.
# NOTE: This does not use cmd as CTest passes a path with / path separators
# to CreateProcess() causing cmd to fail to start.
set(MONO_EXE "${CMAKE_COMMAND};-E;env"CACHESTRING"" FORCE)
endif()
endif()
# If the mono executable is found, and retrieve the version.
if(MONO_EXE)
if(EXISTS"${MONO_EXE}")
execute_process(
COMMAND${MONO_EXE} -V
OUTPUT_VARIABLE MONO_VERSION_STRING
RESULT_VARIABLE RESULT
)
if(NOT${RESULT}EQUAL"0")
message(FATAL_ERROR "${MONO_EXE} -V returned ${RESULT}.")
endif()
string(REGEX MATCH "([0-9]*)([.])([0-9]*)([.]*)([0-9]*)"
MONO_VERSION_MATCH "${MONO_VERSION_STRING}")
set(MONO_VERSION "${MONO_VERSION_MATCH}"CACHESTRING"Mono version.")
else()
set(MONO_VERSION "0.0.0"CACHESTRING"Mono version.")
endif()
endif()
if(NOT MONO_EXE ORNOT MONO_CSHARP_BUILD_EXE)
message(FATAL_ERROR "Cannot find mono and msbuild/xbuild executables.")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Mono
DEFAULT_MSG
MONO_EXE
MONO_CSHARP_BUILD_EXE
MONO_VERSION
)
mark_as_advanced(
MONO_EXE
MONO_CSHARP_BUILD_EXE
MONO_VERSION
)