Skip to content

Commit d13c7d6

Browse files
authored
Check env-var UNITY_ROOT_DIR as well during build (#455)
Currently the build script would automatically find the latest version of Unity unless it is passed with `-unity_root=` parameter. This change make sure that the build script also check environment variable UNITY_ROOT_DIR before searching for the latest version of Unity.
1 parent ee4ee67 commit d13c7d6

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

cmake/FindUnity.cmake

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@ if (NOT EXISTS "${UNITY_ROOT_DIR}")
2020
# Make our best attempt to find the latest unity installed on the system.
2121
# Note that Unity <=2018 include mono 2.x which causes compilation errors.
2222
# Minimum supported version of mono is 3.5.
23-
if(CMAKE_HOST_WIN32)
24-
set(editordir "C:/Program Files/Unity/Hub/Editor")
25-
elseif(CMAKE_HOST_APPLE)
26-
set(editordir "/Applications/Unity/Hub/Editor")
27-
elseif(CMAKE_HOST_UNIX) # Linux
28-
set(editordir "$ENV{HOME}/Unity/Hub/Editor")
23+
if (EXISTS "$ENV{UNITY_ROOT_DIR}")
24+
set(UNITY_ROOT_DIR "$ENV{UNITY_ROOT_DIR}")
25+
message(STATUS "Detected Unity version from env-var 'UNITY_ROOT_DIR': ${UNITY_ROOT_DIR}")
26+
else()
27+
if(CMAKE_HOST_WIN32)
28+
set(editordir "C:/Program Files/Unity/Hub/Editor")
29+
elseif(CMAKE_HOST_APPLE)
30+
set(editordir "/Applications/Unity/Hub/Editor")
31+
elseif(CMAKE_HOST_UNIX) # Linux
32+
set(editordir "$ENV{HOME}/Unity/Hub/Editor")
33+
endif()
34+
file(GLOB unity_versions RELATIVE ${editordir} ${editordir}/*)
35+
list(SORT unity_versions ORDER DESCENDING)
36+
list(GET unity_versions 0 latest_unity_version)
37+
set(UNITY_ROOT_DIR ${editordir}/${latest_unity_version})
38+
message(STATUS "Auto detected latest Unity version: ${UNITY_ROOT_DIR}")
2939
endif()
30-
file(GLOB unity_versions RELATIVE ${editordir} ${editordir}/*)
31-
list(SORT unity_versions ORDER DESCENDING)
32-
list(GET unity_versions 0 latest_unity_version)
33-
set(UNITY_ROOT_DIR ${editordir}/${latest_unity_version})
34-
message(STATUS "Auto detected latest Unity version: ${UNITY_ROOT_DIR}")
3540
endif()
3641

3742
if(FIREBASE_INCLUDE_UNITY)
@@ -95,7 +100,7 @@ if(FIREBASE_INCLUDE_UNITY)
95100

96101
message(STATUS "UNITY_MONO_EXE is ${UNITY_MONO_EXE}")
97102
message(STATUS "UNITY_CSHARP_BUILD_EXE is ${UNITY_CSHARP_BUILD_EXE}")
98-
103+
99104
if(NOT EXISTS UNITY_MONO_EXE OR
100105
NOT EXISTS UNITY_CSHARP_BUILD_EXE)
101106
set(FIND_TOOL_OPTIONS

0 commit comments

Comments
 (0)