Skip to content

Commit 4ab1ee1

Browse files
authored
Merge pull request #1 from firebase/feature/build-on-linux
Feature/build on linux
2 parents 5a6e152 + ee08080 commit 4ab1ee1

File tree

11 files changed

+67
-38
lines changed

11 files changed

+67
-38
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ project(firebase_unity NONE)
103103
enable_language(C)
104104
enable_language(CXX)
105105

106+
if(NOT MSVC AND NOT APPLE)
107+
# Linux-specific option.
108+
if (FIREBASE_LINUX_USE_CXX11_ABI)
109+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
110+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
111+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
112+
else()
113+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
114+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
115+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
116+
endif()
117+
endif()
118+
106119
include(FindPkgConfig)
107120
include(android_dependencies)
108121
include(build_universal)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ The following CMake options are avaliable:
5353
* **FIREBASE_UNI_LIBRARY**: Build all native modules as one dynamic lib
5454
* **FIREBASE_CPP_SDK_DIR**: Local path to firebase cpp
5555
* **FIREBASE_UNITY_SDK_VERSION**: Set version string of firebase unity package
56-
* **UNITY_ENGINE_DLL_DIR**: Local path to UnityEngine.dll directory
57-
(path should end with **/managed**)
56+
* **UNITY_ROOT_DIR**: Local path to Unity's installation directory
57+
(path should end with version number)
5858
* **MONO_DIR**: Local path to mono's xbuild executable directory
5959
* **OPENSSL_ROOT_DIR**: Open ssl root directory
6060
* **PROTOBUF_SRC_ROOT_FOLDER**: Protobuf root directory
6161

6262
> Note:<br/>
63-
> &nbsp;&nbsp;&nbsp;**UNITY_ENGINE_DLL_DIR** is a required setting for building
64-
> unity, CMake will not be able to auto find unity.
63+
> &nbsp;&nbsp;&nbsp;**UNITY_ROOT_DIR** is a recommended setting for building
64+
> unity, else CMake will make an effort to auto find unity.
6565
6666
> Note:<br/>
6767
> &nbsp;&nbsp;&nbsp;On windows, **MONO_DIR** is a required setting.

app/task_extension/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mono_add_library(firebase_taskextension_cs
2929
${firebase_platform_task_lib}
3030
firebase_platform_cs
3131
XBUILD_EXE
32-
${MONO_XBUILD_EXE}
32+
${XBUILD_EXE}
3333
)
3434

3535
unity_pack_cs(firebase_taskextension_cs)

build_android.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fi
5353

5454
echo "Using android toolchain: ${list[0]}"
5555

56-
CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
56+
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
5757
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_NDK=$ANDROID_NDK"
5858
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_TOOLCHAIN_FILE=${list[0]}"
5959
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_ABI=armeabi-v7a"

build_bash.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ function check_exit_code {
3131
CMAKE_OPTIONS=
3232

3333
if [ -d "../firebase-cpp-sdk" ]; then
34-
CMAKE_OPTIONS="-DFIREBASE_CPP_SDK_DIR=`realpath ../firebase-cpp-sdk` "
34+
CMAKE_OPTIONS="-DFIREBASE_CPP_SDK_DIR=`python -c "import os;print(os.path.realpath('../firebase-cpp-sdk'))"` "
3535
fi
3636

37-
CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
37+
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
3838
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_UNITY_BUILD_TESTS=ON"
3939

4040
# TODO: Fix mono build to not need unity deps
4141
build_options=(
4242
"unity:-DFIREBASE_INCLUDE_UNITY=ON"
4343
# "mono:-DFIREBASE_INCLUDE_MONO=ON"
44-
"unity_seperate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
45-
# "mono_seperate:-DFIREBASE_INCLUDE_MONO=ON -DFIREBASE_UNI_LIBRARY=OFF"
44+
"unity_separate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
45+
# "mono_separate:-DFIREBASE_INCLUDE_MONO=ON -DFIREBASE_UNI_LIBRARY=OFF"
4646
)
4747

4848
for option in "${build_options[@]}" ; do
@@ -70,7 +70,7 @@ for option in "${build_options[@]}" ; do
7070
check_exit_code $?
7171

7272
# Build the SDK
73-
make -j 8
73+
make
7474
check_exit_code $?
7575

7676
# Package build output into zip

build_ios.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if [ -d "../firebase-cpp-sdk" ]; then
3838
CMAKE_OPTIONS="-DFIREBASE_CPP_SDK_DIR=$REAL_PATH "
3939
fi
4040

41-
CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
41+
CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
4242
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_UNITY_BUILD_TESTS=ON"
4343

4444
printf "#################################################################\n"

build_windows_x32.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SET CPP_DIR=
2525

2626
SET PATH=%PROTOBUF_SRC_ROOT_FOLDER%\vsprojects\Release;%PATH%
2727

28-
set UNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR:\=/%
28+
set UNITY_ROOT_DIR=%UNITY_ROOT_DIR:\=/%
2929
set PROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER:\=/%
3030

3131
IF EXIST ..\firebase-cpp-sdk (
@@ -76,7 +76,7 @@ EXIT /B %status%
7676

7777
SET CMAKE_ARGS=-DPROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER%
7878
SET CMAKE_ARGS=%CMAKE_ARGS% %CPP_DIR% -DMONO_DIR=%MONO_DIR%
79-
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR%
79+
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ROOT_DIR=%UNITY_ROOT_DIR%
8080
SET CMAKE_ARGS=%CMAKE_ARGS% -DOPENSSL_ROOT_DIR=%OPENSSL_x32%
8181
SET CMAKE_ARGS=%CMAKE_ARGS% -DFIREBASE_UNITY_BUILD_TESTS=ON
8282
SET CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo

build_windows_x64.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SET CPP_DIR=
2525

2626
SET PATH=%PROTOBUF_SRC_ROOT_FOLDER%\vsprojects\x64\Release;%PATH%
2727

28-
set UNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR:\=/%
28+
set UNITY_ROOT_DIR=%UNITY_ROOT_DIR:\=/%
2929
set PROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER:\=/%
3030

3131
IF EXIST ..\firebase-cpp-sdk (
@@ -76,7 +76,7 @@ EXIT /B %status%
7676

7777
SET CMAKE_ARGS=-DPROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER%
7878
SET CMAKE_ARGS=%CMAKE_ARGS% %CPP_DIR% -DMONO_DIR=%MONO_DIR%
79-
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR%
79+
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ROOT_DIR=%UNITY_ROOT_DIR%
8080
SET CMAKE_ARGS=%CMAKE_ARGS% -DOPENSSL_ROOT_DIR=%OPENSSL_x64%
8181
SET CMAKE_ARGS=%CMAKE_ARGS% -DFIREBASE_UNITY_BUILD_TESTS=ON
8282
SET CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo

cmake/FindUnityMono.cmake

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,40 @@ if(EXISTS "${MONO_EXE}")
3939
mono_version_tmp "${mono_version_str}")
4040
set(MONO_VERSION ${mono_version_tmp} CACHE STRING "Mono version")
4141
else()
42-
message(FATAL_ERROR "Cannot find mono.")
42+
message(STATUS "Cannot find mono.")
43+
endif()
44+
45+
if (NOT EXISTS "${UNITY_ROOT_DIR}")
46+
# Make our best attempt to find the latest unity installed on the system.
47+
# Note that Unity <=2018 include mono 2.x which causes compilation errors.
48+
# Minimum supported version of mono is 3.5.
49+
if(MSVC)
50+
set(editordir "C:/Program Files/Unity/Hub/Editor")
51+
elseif(APPLE)
52+
set(editordir "/Applications/Unity/Hub/Editor")
53+
elseif(UNIX) # Linux
54+
set(editordir "$ENV{HOME}/Unity/Hub/Editor")
55+
endif()
56+
file(GLOB unity_versions RELATIVE ${editordir} ${editordir}/*)
57+
list(SORT unity_versions ORDER DESCENDING)
58+
list(GET unity_versions 0 latest_unity_version)
59+
set(UNITY_ROOT_DIR ${editordir}/${latest_unity_version})
60+
message(STATUS "Auto detected latest Unity version: ${UNITY_ROOT_DIR}")
4361
endif()
4462

4563
if(FIREBASE_INCLUDE_UNITY)
46-
if(NOT EXISTS "${UNITY_ENGINE_DLL_DIR}")
47-
if(MSVC)
48-
set(UNITY_PATH_HUB_HINT "C:/Program Files/Unity/Hub/Editor/*")
49-
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
50-
elseif(APPLE)
51-
set(UNITY_PATH_HUB_HINT "/Applications/Unity/Hub/Editor/*")
52-
set(UNITY_PATH_SUFFIXES "Unity.app/Contents/Managed")
53-
elseif(UNIX) # Linux
54-
set(UNITY_PATH_HUB_HINT "$ENV{HOME}/Unity/Hub/Editor/*")
55-
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
56-
endif()
57-
else()
58-
set(UNITY_PATH_HUB_HINT ${UNITY_ENGINE_DLL_DIR})
59-
set(UNITY_PATH_SUFFIXES "")
64+
message(STATUS "Using Unity root directory: ${UNITY_ROOT_DIR}")
65+
set(UNITY_PATH_HUB_HINT "${UNITY_ROOT_DIR}")
66+
# Platform specific directories to search for various dlls and tools.
67+
# These directories can also differ between Unity versions (eg: MonoBleedingEdge/bin or Mono/bin)
68+
if(MSVC)
69+
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
70+
elseif(APPLE)
71+
set(UNITY_PATH_SUFFIXES "Unity.app/Contents/Managed" "PlaybackEngines/iOSSupport"
72+
"Unity.app/Contents/MonoBleedingEdge/bin" "Unity.app/Contents/Mono/bin")
73+
elseif(UNIX) # Linux
74+
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed" "Editor/Data/PlaybackEngines/iOSSupport"
75+
"Editor/Data/MonoBleedingEdge/bin" "Editor/Data/Mono/bin")
6076
endif()
6177

6278
find_file(UNITY_ENGINE_DLL
@@ -78,21 +94,21 @@ if(FIREBASE_INCLUDE_UNITY)
7894
find_file(UNITY_EDITOR_IOS_XCODE_DLL
7995
NAMES UnityEditor.iOS.Extensions.Xcode.dll
8096
PATHS ${UNITY_PATH_HUB_HINT}
81-
PATH_SUFFIXES "PlaybackEngines/iOSSupport"
97+
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}
8298
NO_DEFAULT_PATH
8399
NO_CMAKE_FIND_ROOT_PATH
84100
)
85101

86102
find_program(UNITY_XBUILD_EXE xbuild
87103
PATHS ${UNITY_PATH_HUB_HINT}
88-
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}/../Mono/bin
104+
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}
89105
NO_DEFAULT_PATH
90106
NO_CMAKE_FIND_ROOT_PATH
91107
)
92108

93109
if(NOT EXISTS ${UNITY_ENGINE_DLL} OR NOT EXISTS ${UNITY_EDITOR_DLL})
94110
message(FATAL_ERROR "Fail to find UnityEngine.dll or UnityEditor.dll. \
95-
Please set valid path with -DUNITY_ENGINE_DLL_DIR or check that Unity \
111+
Please set valid path with -DUNITY_ROOT_DIR or check that Unity \
96112
is installed in system default place ${UNITY_PATH_HUB_HINT}. \
97113
See the readme.md for more information.")
98114
endif()

external/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mono_add_library(unity_compat_cs
5050
REFERENCES
5151
unity_engine_cs
5252
XBUILD_EXE
53-
${MONO_XBUILD_EXE}
53+
${XBUILD_EXE}
5454
)
5555

5656
mono_add_library(unity_tasks_cs
@@ -74,7 +74,7 @@ mono_add_library(unity_tasks_cs
7474
unity_engine_cs
7575
unity_compat_cs
7676
XBUILD_EXE
77-
${MONO_XBUILD_EXE}
77+
${XBUILD_EXE}
7878
)
7979

8080
unity_pack_cs(unity_compat_cs

0 commit comments

Comments
 (0)