Skip to content

Feature/build on linux #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ project(firebase_unity NONE)
enable_language(C)
enable_language(CXX)

if(NOT MSVC AND NOT APPLE)
# Linux-specific option.
if (FIREBASE_LINUX_USE_CXX11_ABI)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
else()
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
endif()
endif()

include(FindPkgConfig)
include(android_dependencies)
include(build_universal)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ The following CMake options are avaliable:
* **FIREBASE_UNI_LIBRARY**: Build all native modules as one dynamic lib
* **FIREBASE_CPP_SDK_DIR**: Local path to firebase cpp
* **FIREBASE_UNITY_SDK_VERSION**: Set version string of firebase unity package
* **UNITY_ENGINE_DLL_DIR**: Local path to UnityEngine.dll directory
(path should end with **/managed**)
* **UNITY_ROOT_DIR**: Local path to Unity's installation directory
(path should end with version number)
* **MONO_DIR**: Local path to mono's xbuild executable directory
* **OPENSSL_ROOT_DIR**: Open ssl root directory
* **PROTOBUF_SRC_ROOT_FOLDER**: Protobuf root directory

> Note:<br/>
> &nbsp;&nbsp;&nbsp;**UNITY_ENGINE_DLL_DIR** is a required setting for building
> unity, CMake will not be able to auto find unity.
> &nbsp;&nbsp;&nbsp;**UNITY_ROOT_DIR** is a recommended setting for building
> unity, else CMake will make an effort to auto find unity.

> Note:<br/>
> &nbsp;&nbsp;&nbsp;On windows, **MONO_DIR** is a required setting.
Expand Down
2 changes: 1 addition & 1 deletion app/task_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mono_add_library(firebase_taskextension_cs
${firebase_platform_task_lib}
firebase_platform_cs
XBUILD_EXE
${MONO_XBUILD_EXE}
${XBUILD_EXE}
)

unity_pack_cs(firebase_taskextension_cs)
2 changes: 1 addition & 1 deletion build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fi

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

CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_NDK=$ANDROID_NDK"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_TOOLCHAIN_FILE=${list[0]}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DANDROID_ABI=armeabi-v7a"
Expand Down
10 changes: 5 additions & 5 deletions build_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ function check_exit_code {
CMAKE_OPTIONS=

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

CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_UNITY_BUILD_TESTS=ON"

# TODO: Fix mono build to not need unity deps
build_options=(
"unity:-DFIREBASE_INCLUDE_UNITY=ON"
# "mono:-DFIREBASE_INCLUDE_MONO=ON"
"unity_seperate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
# "mono_seperate:-DFIREBASE_INCLUDE_MONO=ON -DFIREBASE_UNI_LIBRARY=OFF"
"unity_separate:-DFIREBASE_INCLUDE_UNITY=ON -DFIREBASE_UNI_LIBRARY=OFF"
# "mono_separate:-DFIREBASE_INCLUDE_MONO=ON -DFIREBASE_UNI_LIBRARY=OFF"
)

for option in "${build_options[@]}" ; do
Expand Down Expand Up @@ -70,7 +70,7 @@ for option in "${build_options[@]}" ; do
check_exit_code $?

# Build the SDK
make -j 8
make
check_exit_code $?

# Package build output into zip
Expand Down
2 changes: 1 addition & 1 deletion build_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if [ -d "../firebase-cpp-sdk" ]; then
CMAKE_OPTIONS="-DFIREBASE_CPP_SDK_DIR=$REAL_PATH "
fi

CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ENGINE_DLL_DIR=${UNITY_ENGINE_DLL_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS}-DUNITY_ROOT_DIR=${UNITY_ROOT_DIR}"
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DFIREBASE_UNITY_BUILD_TESTS=ON"

printf "#################################################################\n"
Expand Down
4 changes: 2 additions & 2 deletions build_windows_x32.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SET CPP_DIR=

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

set UNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR:\=/%
set UNITY_ROOT_DIR=%UNITY_ROOT_DIR:\=/%
set PROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER:\=/%

IF EXIST ..\firebase-cpp-sdk (
Expand Down Expand Up @@ -76,7 +76,7 @@ EXIT /B %status%

SET CMAKE_ARGS=-DPROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER%
SET CMAKE_ARGS=%CMAKE_ARGS% %CPP_DIR% -DMONO_DIR=%MONO_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ROOT_DIR=%UNITY_ROOT_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DOPENSSL_ROOT_DIR=%OPENSSL_x32%
SET CMAKE_ARGS=%CMAKE_ARGS% -DFIREBASE_UNITY_BUILD_TESTS=ON
SET CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo
Expand Down
4 changes: 2 additions & 2 deletions build_windows_x64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SET CPP_DIR=

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

set UNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR:\=/%
set UNITY_ROOT_DIR=%UNITY_ROOT_DIR:\=/%
set PROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER:\=/%

IF EXIST ..\firebase-cpp-sdk (
Expand Down Expand Up @@ -76,7 +76,7 @@ EXIT /B %status%

SET CMAKE_ARGS=-DPROTOBUF_SRC_ROOT_FOLDER=%PROTOBUF_SRC_ROOT_FOLDER%
SET CMAKE_ARGS=%CMAKE_ARGS% %CPP_DIR% -DMONO_DIR=%MONO_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ENGINE_DLL_DIR=%UNITY_ENGINE_DLL_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DUNITY_ROOT_DIR=%UNITY_ROOT_DIR%
SET CMAKE_ARGS=%CMAKE_ARGS% -DOPENSSL_ROOT_DIR=%OPENSSL_x64%
SET CMAKE_ARGS=%CMAKE_ARGS% -DFIREBASE_UNITY_BUILD_TESTS=ON
SET CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo
Expand Down
52 changes: 34 additions & 18 deletions cmake/FindUnityMono.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,40 @@ if(EXISTS "${MONO_EXE}")
mono_version_tmp "${mono_version_str}")
set(MONO_VERSION ${mono_version_tmp} CACHE STRING "Mono version")
else()
message(FATAL_ERROR "Cannot find mono.")
message(STATUS "Cannot find mono.")
endif()

if (NOT EXISTS "${UNITY_ROOT_DIR}")
# Make our best attempt to find the latest unity installed on the system.
# Note that Unity <=2018 include mono 2.x which causes compilation errors.
# Minimum supported version of mono is 3.5.
if(MSVC)
set(editordir "C:/Program Files/Unity/Hub/Editor")
elseif(APPLE)
set(editordir "/Applications/Unity/Hub/Editor")
elseif(UNIX) # Linux
set(editordir "$ENV{HOME}/Unity/Hub/Editor")
endif()
file(GLOB unity_versions RELATIVE ${editordir} ${editordir}/*)
list(SORT unity_versions ORDER DESCENDING)
list(GET unity_versions 0 latest_unity_version)
set(UNITY_ROOT_DIR ${editordir}/${latest_unity_version})
message(STATUS "Auto detected latest Unity version: ${UNITY_ROOT_DIR}")
endif()

if(FIREBASE_INCLUDE_UNITY)
if(NOT EXISTS "${UNITY_ENGINE_DLL_DIR}")
if(MSVC)
set(UNITY_PATH_HUB_HINT "C:/Program Files/Unity/Hub/Editor/*")
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
elseif(APPLE)
set(UNITY_PATH_HUB_HINT "/Applications/Unity/Hub/Editor/*")
set(UNITY_PATH_SUFFIXES "Unity.app/Contents/Managed")
elseif(UNIX) # Linux
set(UNITY_PATH_HUB_HINT "$ENV{HOME}/Unity/Hub/Editor/*")
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
endif()
else()
set(UNITY_PATH_HUB_HINT ${UNITY_ENGINE_DLL_DIR})
set(UNITY_PATH_SUFFIXES "")
message(STATUS "Using Unity root directory: ${UNITY_ROOT_DIR}")
set(UNITY_PATH_HUB_HINT "${UNITY_ROOT_DIR}")
# Platform specific directories to search for various dlls and tools.
# These directories can also differ between Unity versions (eg: MonoBleedingEdge/bin or Mono/bin)
if(MSVC)
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed")
elseif(APPLE)
set(UNITY_PATH_SUFFIXES "Unity.app/Contents/Managed" "PlaybackEngines/iOSSupport"
"Unity.app/Contents/MonoBleedingEdge/bin" "Unity.app/Contents/Mono/bin")
elseif(UNIX) # Linux
set(UNITY_PATH_SUFFIXES "Editor/Data/Managed" "Editor/Data/PlaybackEngines/iOSSupport"
"Editor/Data/MonoBleedingEdge/bin" "Editor/Data/Mono/bin")
endif()

find_file(UNITY_ENGINE_DLL
Expand All @@ -78,21 +94,21 @@ if(FIREBASE_INCLUDE_UNITY)
find_file(UNITY_EDITOR_IOS_XCODE_DLL
NAMES UnityEditor.iOS.Extensions.Xcode.dll
PATHS ${UNITY_PATH_HUB_HINT}
PATH_SUFFIXES "PlaybackEngines/iOSSupport"
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)

find_program(UNITY_XBUILD_EXE xbuild
PATHS ${UNITY_PATH_HUB_HINT}
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}/../Mono/bin
PATH_SUFFIXES ${UNITY_PATH_SUFFIXES}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)

if(NOT EXISTS ${UNITY_ENGINE_DLL} OR NOT EXISTS ${UNITY_EDITOR_DLL})
message(FATAL_ERROR "Fail to find UnityEngine.dll or UnityEditor.dll. \
Please set valid path with -DUNITY_ENGINE_DLL_DIR or check that Unity \
Please set valid path with -DUNITY_ROOT_DIR or check that Unity \
is installed in system default place ${UNITY_PATH_HUB_HINT}. \
See the readme.md for more information.")
endif()
Expand Down
4 changes: 2 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mono_add_library(unity_compat_cs
REFERENCES
unity_engine_cs
XBUILD_EXE
${MONO_XBUILD_EXE}
${XBUILD_EXE}
)

mono_add_library(unity_tasks_cs
Expand All @@ -74,7 +74,7 @@ mono_add_library(unity_tasks_cs
unity_engine_cs
unity_compat_cs
XBUILD_EXE
${MONO_XBUILD_EXE}
${XBUILD_EXE}
)

unity_pack_cs(unity_compat_cs
Expand Down
4 changes: 2 additions & 2 deletions external/forwards/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mono_add_library(unity_compat_fwd_cs
REFERENCES
unity_engine_cs
XBUILD_EXE
${MONO_XBUILD_EXE}
${XBUILD_EXE}
)

mono_add_library(unity_tasks_fwd_cs
Expand All @@ -45,7 +45,7 @@ mono_add_library(unity_tasks_fwd_cs
unity_engine_cs
unity_compat_cs
XBUILD_EXE
${MONO_XBUILD_EXE}
${XBUILD_EXE}
)

unity_pack_cs(unity_compat_fwd_cs
Expand Down