Skip to content

Commit 80c6e58

Browse files
authored
Merge pull request #11 from firebase/origin/feature/monoupdate
Update find mono scripts
2 parents 0a62c94 + 3ea993a commit 80c6e58

8 files changed

+367
-163
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
__pycache__/
55
*.py[cod]
66
*$py.class
7+
*.pyc
78

89
### Gradle ###
910
.gradle
@@ -20,3 +21,6 @@ gcs_key_file.json
2021
*_build/
2122
*_unity/
2223
*_unity_seperate/
24+
25+
# Windows ignore
26+
vcpkg

build_bash.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_UNITY_BUILD_TESTS=ON"
4141
build_options=(
4242
"unity:-DFIREBASE_INCLUDE_UNITY=ON"
4343
# "mono:-DFIREBASE_INCLUDE_MONO=ON"
44-
"unity_separate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
44+
# "unity_separate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
4545
# "mono_separate:-DFIREBASE_INCLUDE_MONO=ON -DFIREBASE_UNI_LIBRARY=OFF"
4646
)
4747

build_windows_x32.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ IF EXIST ..\firebase-cpp-sdk (
3535
IF EXIST "C:\Program Files (x86)\Mono\bin" (
3636
SET MONO_DIR="C:/Program Files (x86)/Mono/bin"
3737
) ELSE (
38-
ECHO ERROR: Cant find mono
38+
ECHO ERROR: Cant find mono in programs files x86
3939
EXIT /B -1
4040
)
4141

build_windows_x64.bat

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ IF EXIST ..\firebase-cpp-sdk (
3232
SET CPP_DIR=-DFIREBASE_CPP_SDK_DIR^=../../firebase-cpp-sdk
3333
)
3434

35-
IF EXIST "C:\Program Files (x86)\Mono\bin" (
36-
SET MONO_DIR="C:/Program Files (x86)/Mono/bin"
35+
IF EXIST "C:\Program Files\Mono\bin" (
36+
SET MONO_DIR="C:/Program Files/Mono/bin"
3737
) ELSE (
38-
ECHO ERROR: Cant find mono
38+
ECHO ERROR: Cant find mono in program files
3939
EXIT /B -1
4040
)
4141

cmake/FindMono.cmake

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2021 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Locates the Mono launcher and build tool.
16+
#
17+
# Optional variable arguments for this module:
18+
# MONO_DIR: Variable to specify a search path for Mono.
19+
# MONO_DISABLE_VISUAL_STUDIO_FALLBACK: Do not use Visual Studio's msbuild
20+
# as a fallback on Windows when using the Visual Studio project generator.
21+
#
22+
# Cache variables set by this module:
23+
# MONO_EXE: Location of the Mono interpreter executable.
24+
# MONO_VERSION: Version of the detected Mono installation.
25+
# MONO_CSHARP_BUILD_EXE: Location of the tool (e.g msbuild or xbuild) that
26+
# can build .csproj projects.
27+
28+
# If MONO_DIR is specified, only search that path.
29+
set(FIND_MONO_OPTIONS "")
30+
if(EXISTS "${MONO_DIR}")
31+
set(FIND_MONO_OPTIONS
32+
PATHS
33+
"${MONO_DIR}"
34+
"${MONO_DIR}/lib/mono"
35+
PATH_SUFFIXES
36+
bin
37+
NO_DEFAULT_PATH
38+
)
39+
endif()
40+
41+
# Search for Mono tools.
42+
find_program(MONO_EXE mono
43+
${FIND_MONO_OPTIONS}
44+
)
45+
find_program(MONO_CSHARP_BUILD_EXE
46+
NAMES
47+
msbuild
48+
xbuild
49+
${FIND_MONO_OPTIONS}
50+
)
51+
52+
if(CMAKE_HOST_WIN32 AND
53+
NOT MONO_DISABLE_VISUAL_STUDIO_FALLBACK AND
54+
EXISTS "${CMAKE_VS_MSBUILD_COMMAND}")
55+
if(NOT MONO_CSHARP_BUILD_EXE)
56+
# If Mono's build tool isn't found, fallback to Visual Studio.
57+
message(STATUS "Mono installation not found, trying to fallback "
58+
"to Visual Studio's msbuild ${CMAKE_VS_MSBUILD_COMMAND}."
59+
)
60+
set(MONO_CSHARP_BUILD_EXE "${CMAKE_VS_MSBUILD_COMMAND}"
61+
CACHE STRING "" FORCE
62+
)
63+
endif()
64+
if(NOT MONO_EXE)
65+
# Just use cmake to launch the C# executable which should run on Windows if
66+
# the .NET framework is installed.
67+
# NOTE: This does not use cmd as CTest passes a path with / path separators
68+
# to CreateProcess() causing cmd to fail to start.
69+
set(MONO_EXE "${CMAKE_COMMAND};-E;env" CACHE STRING "" FORCE)
70+
endif()
71+
endif()
72+
73+
# If the mono executable is found, and retrieve the version.
74+
if(MONO_EXE)
75+
if(EXISTS "${MONO_EXE}")
76+
execute_process(
77+
COMMAND ${MONO_EXE} -V
78+
OUTPUT_VARIABLE MONO_VERSION_STRING
79+
RESULT_VARIABLE RESULT
80+
)
81+
if(NOT ${RESULT} EQUAL "0")
82+
message(FATAL_ERROR "${MONO_EXE} -V returned ${RESULT}.")
83+
endif()
84+
string(REGEX MATCH "([0-9]*)([.])([0-9]*)([.]*)([0-9]*)"
85+
MONO_VERSION_MATCH "${MONO_VERSION_STRING}")
86+
set(MONO_VERSION "${MONO_VERSION_MATCH}" CACHE STRING "Mono version.")
87+
else()
88+
set(MONO_VERSION "0.0.0" CACHE STRING "Mono version.")
89+
endif()
90+
endif()
91+
92+
if(NOT MONO_EXE OR NOT MONO_CSHARP_BUILD_EXE)
93+
message(FATAL_ERROR "Cannot find mono and msbuild/xbuild executables.")
94+
endif()
95+
96+
include(FindPackageHandleStandardArgs)
97+
find_package_handle_standard_args(
98+
Mono
99+
DEFAULT_MSG
100+
MONO_EXE
101+
MONO_CSHARP_BUILD_EXE
102+
MONO_VERSION
103+
)
104+
mark_as_advanced(
105+
MONO_EXE
106+
MONO_CSHARP_BUILD_EXE
107+
MONO_VERSION
108+
)

0 commit comments

Comments
 (0)