Skip to content

Commit 8121edf

Browse files
committed
add cmake file for building package
1 parent fba9544 commit 8121edf

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

CMakeLists.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# ***********************************************************************
2+
# Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
#
4+
# Licensed under the ##LICENSENAME##.
5+
# See LICENSE.md file in the project root for full license information.
6+
# ***********************************************************************
7+
8+
cmake_minimum_required (VERSION 3.8)
9+
10+
# Default is a release build.
11+
if (NOT CMAKE_BUILD_TYPE)
12+
# CMAKE_BUILD_TYPE is special, so we have to CACHE FORCE to actually set it,
13+
# or else our 'set' has very wonky scope.
14+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
15+
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
16+
list(APPEND CMAKE_CXX_FLAGS "-DMEMORY_DEBUG")
17+
endif()
18+
message(STATUS "Building for ${CMAKE_BUILD_TYPE}")
19+
20+
# has to be done before project is set, or else CMAKE_INSTALL_PREFIX will already be set to a default value
21+
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Install path prefix")
22+
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX is: " ${CMAKE_INSTALL_PREFIX})
23+
24+
if (NOT DEFINED PACKAGE_VERSION)
25+
set(PACKAGE_VERSION "0.0.10a")
26+
endif()
27+
28+
if (NOT DEFINED PACKAGE_PATH)
29+
set(PACKAGE_PATH "${CMAKE_BINARY_DIR}/FbxExporters_${PACKAGE_VERSION}.unitypackage")
30+
endif()
31+
32+
if (NOT DEFINED FBXSDK_PACKAGE_PATH)
33+
# TODO: store the FbxSdk directly in this project
34+
set(FBXSDK_PACKAGE_PATH "${CMAKE_SOURCE_DIR}/../FbxSharpBuild/FbxSdk_${PACKAGE_VERSION}.unitypackage")
35+
endif()
36+
37+
project (UnityFbxExporter)
38+
39+
# promote warnings to errors
40+
if(MSVC)
41+
set(PROJECT_COMPILE_FLAGS "/WX")
42+
else()
43+
# requires gcc 6 or higher
44+
set(PROJECT_COMPILE_FLAGS "-Werror -Wno-error=null-dereference")
45+
endif()
46+
47+
add_definitions(${PROJECT_COMPILE_FLAGS})
48+
49+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/deps/cmake)
50+
51+
###########################################################################
52+
# Find packages that we need.
53+
54+
find_package(Unity REQUIRED)
55+
56+
set(Python_ADDITIONAL_VERSIONS 2.7)
57+
58+
###########################################################################
59+
# Import FbxSharp package
60+
61+
set(FBXSDK_PACKAGE_TARGET import_fbxsdk)
62+
add_custom_target(
63+
${FBXSDK_PACKAGE_TARGET}
64+
COMMAND rmdir /s "${CMAKE_SOURCE_DIR}/Assets/FbxSdk"
65+
COMMAND "${UNITY_EDITOR_PATH}" -projectPath "${CMAKE_SOURCE_DIR}" -importPackage ${FBXSDK_PACKAGE_PATH} -quit
66+
)
67+
68+
###########################################################################
69+
# TODO: Add target to replace the version number in README.txt
70+
71+
###########################################################################
72+
# Zip integrations folder
73+
set(MAYA_INTEGRATION_TARGET zip_maya_integration)
74+
set(MAYA_INTEGRATION_ZIP_NAME "unityoneclick_for_maya.zip")
75+
add_custom_command(OUTPUT ${MAYA_INTEGRATION_ZIP_NAME}
76+
COMMAND ${CMAKE_COMMAND} -E tar "cfv" ${CMAKE_SOURCE_DIR}/Assets/FbxExporters/${MAYA_INTEGRATION_ZIP_NAME} --format=zip
77+
"${CMAKE_SOURCE_DIR}/Assets/Integrations"
78+
)
79+
add_custom_target(${MAYA_INTEGRATION_TARGET} DEPENDS ${MAYA_INTEGRATION_ZIP_NAME})
80+
81+
###########################################################################
82+
# Add target for creating a package
83+
# TODO: synthesize the right project depending on configuration.
84+
# Make install does the right thing in all cases but it's overkill in release.
85+
add_custom_command(
86+
OUTPUT ${PACKAGE_PATH}
87+
COMMAND "${UNITY_EDITOR_PATH}" -batchmode -projectPath ${CMAKE_SOURCE_DIR} -exportPackage Assets/FbxExporters Assets/FbxSdk ${PACKAGE_PATH} -quit
88+
COMMENT "Creating Unity Package ${PACKAGE_PATH}"
89+
DEPENDS ${MAYA_INTEGRATION_TARGET}
90+
)
91+
add_custom_target(unitypackage ALL DEPENDS ${PACKAGE_PATH} ${FBXSDK_PACKAGE_TARGET})
92+
93+
enable_testing()
94+
add_test(NAME run-all COMMAND "${UNITY_EDITOR_PATH}" -batchmode -projectPath ${CMAKE_SOURCE_DIR} runEditorTests -quit)

deps/cmake/FindUnity.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ***********************************************************************
2+
# Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
#
4+
# Licensed under the ##LICENSENAME##.
5+
# See LICENSE.md file in the project root for full license information.
6+
# ***********************************************************************
7+
8+
# Find Unity and set things up to be able to compile Unity.
9+
10+
# If UNITY is set to the root of the Unity install, we use it, otherwise we set
11+
# it to the default install location.
12+
13+
if (NOT DEFINED UNITY)
14+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
15+
set(UNITY "/Applications/Unity")
16+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
17+
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
18+
set(UNITY "c:/Program Files/Unity2017.1.0f3")
19+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
20+
set(UNITY "/opt/Unity")
21+
endif()
22+
endif()
23+
24+
# Be generous about how to interpret UNITY:
25+
# it can be the directory that includes the Unity executable,
26+
# or the root of the Unity installation. On mac it can be the app bundle.
27+
list(APPEND UNITY_EXECUTABLE_PATHS "${UNITY}")
28+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
29+
list(APPEND UNITY_EXECUTABLE_PATHS "${UNITY}/Contents/MacOS")
30+
list(APPEND UNITY_EXECUTABLE_PATHS "${UNITY}/Unity.app/Contents/MacOS")
31+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
32+
list(APPEND UNITY_EXECUTABLE_PATHS "${UNITY}/Editor")
33+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
34+
list(APPEND UNITY_EXECUTABLE_PATHS "${UNITY}/Editor")
35+
endif()
36+
37+
find_program(UNITY_EDITOR_PATH Unity PATHS ${UNITY_EXECUTABLE_PATHS})
38+
39+
40+
# Check whether we found everything we needed.
41+
include(FindPackageHandleStandardArgs)
42+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Unity DEFAULT_MSG UNITY_EDITOR_PATH)

0 commit comments

Comments
 (0)