Skip to content

Commit

Permalink
chore: convert the plugin building process to cmake (#76)
Browse files Browse the repository at this point in the history
* Move the previous plugin source under "Src" folder
* Add script to find and execute Visual Studio 2019 developer command prompt
* Add documents to build using cmake
* Move g_filenameToPtrMap to Loader and add a new global define PLUGIN_DLL_EXPORT to define dllexport in the code
* Add AddPlugin module to copy libraries directly to the Runtime folder
* Pass BUILD_OSX_BUNDLE as an argument to AddPlugin
* move dllmain.cpp under Win folder
* Move TGALoader.cpp under Win folder
* Copy the libraries to different folders based on the platform
* Update Mac Bundle and dylib
* Update Windows DLL
* Load CommonLib.dylib on startup on Mac

gitignore
* ignore cmake build files
* don't ignore dylib

Yamato:
* remove prepack
  • Loading branch information
sindharta authored Jun 3, 2020
1 parent 760470a commit b06ecd3
Show file tree
Hide file tree
Showing 91 changed files with 415 additions and 48 deletions.
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

*.exe
*.so
*.dylib
*.unitypackage

release/
Expand Down Expand Up @@ -54,3 +53,19 @@ Plugin~/_out/
*.xcuserdatad/
Plugins~/**/DerivedData/**
Plugins~/**/XCBuildData/**

# CMake
Plugins~/Build/CMakeFiles/*
Plugins~/Build/CMakeScripts/*
Plugins~/Build/CMakeCache.txt
Plugins~/Build/**/cmake_install.cmake
Plugins~/Build/Makefile
Plugins~/Build/*.xcodeproj/**
Plugins~/Build/ispc**
Plugins~/Build/*.vcxproj**
Plugins~/Build/*.sln
Plugins~/Build/x64/**
Plugins~/Build/Src/**



12 changes: 0 additions & 12 deletions .yamato/upm-ci-StreamingImageSequence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ prepack_{{ platform.name }}:
image: {{ platform.prepack_image }}
flavor: {{ platform.flavor }}
commands:
{% if platform.name == "mac" -%}
- cd Plugins~/Project && xcodebuild -configuration Release build && cd ../..
{% else -%}
- cd .
{% endif -%}
artifacts:
{{ yamato_name }}_{{ platform.name }}_prepack_artifacts:
paths:
Expand All @@ -43,19 +39,11 @@ pack:
flavor: b1.large
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
{% for platform in platforms %}
- unzip -qq -o streamingImageSequence_{{ platform.name }}_prepack_artifacts*
- rm streamingImageSequence_{{ platform.name }}_prepack_artifacts*
{% endfor %}
- upm-ci package pack
artifacts:
{{ yamato_name }}_pack_artifacts:
paths:
- "upm-ci~/**/*"
dependencies:
{% for platform in platforms %}
- .yamato/upm-ci-{{ yamato_name }}.yml#prepack_{{ platform.name }}
{% endfor %}

{% for editor in test_editors %}
{% for platform in platforms %}
Expand Down
6 changes: 6 additions & 0 deletions Plugins~/Build/VsDevCmd_2019.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" /version [16.0^,17^) /property installationPath`) do (
set VSDIR=%%i
echo %%i
)
call "%VSDIR%\Common7\Tools\VsDevCmd.bat"
cd %~dp0
44 changes: 44 additions & 0 deletions Plugins~/Build/cmake_modules/AddPlugin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Expects BUILD_TESTS variable to be defined

option(ENABLE_DEPLOY "Copy built binaries to plugins directory." ON)


function(add_plugin name)
cmake_parse_arguments(arg "BUILD_OSX_BUNDLE" "PLUGINS_DIR" "SOURCES" ${ARGN})
file(TO_NATIVE_PATH ${arg_PLUGINS_DIR} native_plugins_dir)

if(NOT BUILD_TESTS AND APPLE AND ${arg_BUILD_OSX_BUNDLE})
add_library(${name} MODULE ${arg_SOURCES})
set_target_properties(${name} PROPERTIES BUNDLE ON)
else()
add_library(${name} SHARED ${arg_SOURCES})
set_target_properties(${name} PROPERTIES PREFIX "")
endif()

if(ENABLE_DEPLOY)

if(WIN32)

# Win: Visual Studio Settings
add_custom_command(TARGET ${name} POST_BUILD
COMMAND del ${native_plugins_dir}\$(TargetFileName)
COMMAND copy $(TargetPath) ${native_plugins_dir}

)
else()

if(${arg_BUILD_OSX_BUNDLE})
SET(target_filename \${TARGET_BUILD_DIR}/${name}.bundle)
else()
SET(target_filename $<TARGET_FILE:${name}>)
endif()

# Linux or Mac
add_custom_command(TARGET ${name} POST_BUILD
COMMAND rm -rf ${arg_PLUGINS_DIR}/${target_filename}
COMMAND cp -r ${target_filename} ${native_plugins_dir}
)
endif()

endif()
endfunction()
66 changes: 66 additions & 0 deletions Plugins~/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13)

# Mac deployment target
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
endif()

PROJECT(StreamingImageSequencePlugin)


#cmake variables
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/Build/cmake_modules)

# Custom scripts
include(AddPlugin)

set(src_root ${CMAKE_CURRENT_SOURCE_DIR}/Src)

# ----------------------------------------------------------------------------------------------------------------------

if(APPLE)
set(PLATFORM "OSX")
find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
mark_as_advanced(CORE_GRAPHICS_LIBRARY)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(PLATFORM "Linux")
set(LINUX ON)

elseif(WIN32)
set(PLATFORM "Win64")

add_definitions(-DPLUGIN_DLL_EXPORT)

# To handle DLL loading error related to the requirement of having VCRUNTIME140_1.DLL
# https://developercommunity.visualstudio.com/content/problem/852548/vcruntime140-1dll-is-missing.html
add_definitions(-d2FH4-)
add_link_options(-d2:-FH4-)
endif()

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

# Force Unicode character set
add_definitions(-DUNICODE -D_UNICODE)


# ----------------------------------------------------------------------------------------------------------------------

option(BUILD_TESTS "Tests" OFF)

# ----------------------------------------------------------------------------------------------------------------------


#Specify available modules
add_subdirectory(${src_root}/External/stb)
add_subdirectory(${src_root}/CommonLib)
add_subdirectory(${src_root}/Loader)

if(WIN32)
add_subdirectory(${src_root}/DrawOverWindow)
endif()

# Tests
if(BUILD_TESTS)
add_subdirectory(${src_root}/PluginTest)
endif()

61 changes: 61 additions & 0 deletions Plugins~/Docs/en/BuildPlugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Building Plugins

1. [Windows](#building-on-windows)
1. [Mac OSX](#building-on-mac-osx)


## Building on Windows

### Prerequisites (Win)

1. Install [cmake](https://cmake.org/) version 3.13 or later.
Make sure to choose one of the "Add CMake to the System PATH ..." options as shown below.
![CMakeInstallation](../Images/CMakeInstallation.png)

1. Install Visual Studio 2019.
1. Install git. For example: [SourceTree](https://www.sourcetreeapp.com/)


### Build Steps (Win)


Start "Developer Command Prompt for VS 2019" and execute the following:

```
$ git clone https://github.com/unity3d-jp/StreamingImageSequence.git
$ cd StreamingImageSequence\Plugins~\Build
$ cmake -G "Visual Studio 16 2019" -A x64 ..
$ msbuild StreamingImageSequencePlugin.sln /t:Build /p:Configuration=Release /p:Platform=x64 /m /nologo
```

> For a regular "Command Prompt", there is a script: *VsDevCmd_2019.bat*
> under the *Build* folder, which if executed, will turn the prompt into a
> "Developer Command Prompt for VS 2019".

## Building on Mac OSX

### Prerequisites (Mac)

1. Install [cmake](https://cmake.org/) version 3.5 or later, if not already installed.
1. Install [XCode](https://developer.apple.com/xcode/).
1. Install XCode Command Line tools.
```
xcode-select --install
```
1. Install git. For example: [SourceTree](https://www.sourcetreeapp.com/)
### Build Steps (Mac)
Open a terminal and execute the following
```
$ git clone https://github.com/unity3d-jp/StreamingImageSequence.git
$ cd StreamingImageSequence/Plugins~/Build
$ cmake -GXcode ..
$ xcodebuild -scheme ALL_BUILD -configuration Release build
```
Binary file added Plugins~/Images/CMakeInstallation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Plugins~/Src/CommonLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13)

project(CommonLib)

file(GLOB sources *.cpp *.h)
set(CommonLib_dir "${CMAKE_CURRENT_SOURCE_DIR}")
if(WIN32)
file(GLOB win_sources Win/*.h Win/*.cpp)
list(APPEND sources ${win_sources})
endif()
set(src_root "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(plugins_dir "${src_root}/../../Runtime/Plugins/${PLATFORM}")

# setup as a library
add_plugin(CommonLib SOURCES ${sources} PLUGINS_DIR ${plugins_dir})

#Include, pch
target_precompile_headers(CommonLib PRIVATE "${CommonLib_dir}/stdafx.h")
target_include_directories(CommonLib PRIVATE
${CommonLib_dir}
${src_root}
)

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@

#include "CriticalSectionObject.h"

using namespace std;

COMMONLIB_API map<strType, StReadResult> g_fileNameToPtrMap[StreamingImageSequencePlugin::MAX_CRITICAL_SECTION_TYPE_TEXTURES];
COMMONLIB_API map<strType, int> g_scenePathToSceneStatus;

//----------------------------------------------------------------------------------------------------------------------

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#ifdef _WIN32
# ifdef COMMONLIBWIN_EXPORTS
# if defined(COMMONLIBWIN_EXPORTS) || defined(PLUGIN_DLL_EXPORT)
# define COMMONLIB_API __declspec(dllexport)
# else
# define COMMONLIB_API __declspec(dllimport)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions Plugins~/Src/DrawOverWindow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13)

project(DrawOverWindow)

file(GLOB sources *.cpp *.h)
set(DrawOverWindow_dir "${CMAKE_CURRENT_SOURCE_DIR}")
if(WIN32)
file(GLOB win_sources Win/*.h Win/*.cpp)
list(APPEND sources ${win_sources})
endif()
set(plugins_dir "${src_root}/../../Runtime/Plugins/${PLATFORM}")

# setup as a library
add_plugin(DrawOverWindow SOURCES ${sources} PLUGINS_DIR ${plugins_dir})

#Include, pch
target_precompile_headers(DrawOverWindow PRIVATE "${DrawOverWindow_dir}/stdafx.h")
target_include_directories(DrawOverWindow PRIVATE
${DrawOverWindow_dir}
${src_root}
)

# Library dependencies
target_link_libraries( DrawOverWindow
CommonLib
)

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// that uses this DLL. This way any other project whose source files include this file see
// DRAWOVERWINDOW_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef DRAWOVERWINDOW_EXPORTS
#if defined(DRAWOVERWINDOW_EXPORTS) || defined(PLUGIN_DLL_EXPORT)
#define DRAWOVERWINDOW_API __declspec(dllexport)
#else
#define DRAWOVERWINDOW_API __declspec(dllimport)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions Plugins~/Src/External/stb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13)

project(stb)

file(GLOB sources *.cpp *.h)
set(stb_dir "${CMAKE_CURRENT_SOURCE_DIR}")

# setup as a library
add_library(stb STATIC ${sources} )

#Include, pch
target_include_directories(stb PRIVATE
${stb_dir}
)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions Plugins~/Src/Loader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13)

project(Loader)

file(GLOB sources *.cpp *.h ../)
set(Loader_dir "${CMAKE_CURRENT_SOURCE_DIR}")
if(APPLE)
file(GLOB mac_sources Mac/*.h Mac/*.cpp Mac/*.mm)
list(APPEND sources ${mac_sources})

elseif(WIN32)
file(GLOB win_sources Win/*.h Win/*.cpp)
list(APPEND sources ${win_sources})
endif()
set(src_root "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(plugins_dir "${src_root}/../../Runtime/Plugins/${PLATFORM}")

# setup as a library
add_plugin(Loader SOURCES ${sources} PLUGINS_DIR ${plugins_dir} BUILD_OSX_BUNDLE )

#Include, pch
target_precompile_headers(Loader PRIVATE "${Loader_dir}/stdafx.h")
target_include_directories(Loader PRIVATE
${Loader_dir}
${src_root}
)

# Library dependencies
target_link_libraries( Loader
CommonLib
stb
${CORE_GRAPHICS_LIBRARY}
)
File renamed without changes.
3 changes: 3 additions & 0 deletions Plugins~/Loader/Loader.cpp → Plugins~/Src/Loader/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

using namespace std;

LOADER_API std::map<strType, int> g_scenePathToSceneStatus;
LOADER_API std::map<strType, StReadResult> g_fileNameToPtrMap[StreamingImageSequencePlugin::MAX_CRITICAL_SECTION_TYPE_TEXTURES];


//----------------------------------------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion Plugins~/Loader/Loader.h → Plugins~/Src/Loader/Loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// LOADER_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef _WIN32
# ifdef LOADERWIN_EXPORTS
# if defined(LOADERWIN_EXPORTS) || defined(PLUGIN_DLL_EXPORT)
# define LOADER_API __declspec(dllexport)
# else
# define LOADER_API __declspec(dllimport)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Runtime/Plugins/OSX/CommonLib.dylib
Binary file not shown.
Loading

0 comments on commit b06ecd3

Please sign in to comment.