Skip to content

Commit b170cd8

Browse files
authored
Unreal向けに静的ビルドをできるようにしました。 (Synesthesias#153)
* cmake : コンパイル MT,MD,MTd,MDd の場合分け * fbxsdkを4通り、debug/mt, debug/md, release/mt, release/md で場合分け * FBXSDKの名称をOSで場合分け * ローカルでのユニットテストが落ちるのを修正 * github actions調整 * github actions修正 * Update readme * github actions修正 * 同上 * 同上 * 同上 * linux build fix * ubuntu 18 から 20.04 に移行 * linux fix * 同上 * ライセンスをMITに変更 * 静的ビルドのリンクエラー修正中 * 同上 * github actions windows対応 * mac, linux向けの静的ビルド仮置き * 同上 * 同上 * 同上 * fix linux build * fix linux * update libcitgygml * fix for windows unreal * 同上 * 同上 * 同上 * 同上 * fix mac libplateau name * update readme * turn off xerces-c network build * fix how to build * fix xerces-c trancoder issue of mac * MTをMDに変更 * ユニットテストを本番サーバーに依存しないようにした * ビルド方法ごとの違いに対応し、Unity向けでもUnreal向けでもユニットテストが通るようにした * cmakeで書き方が変なところを修正 * テスト微修正 * #define LIBPLATEAU_BUILD_DYNAMIC がCMakeから追加されないバグを修正 * CMake修正 * UnityのDebugビルドのときはMDに * 微修正 * Meshのコンストラクタを高速化 * merge shapeを事前に頂点数を求めることで高速化 * demのLODを取得できていなかったバグを修正 * citygmlのgitignore変更をrevertt
1 parent 09dd43d commit b170cd8

File tree

21 files changed

+349
-130
lines changed

21 files changed

+349
-130
lines changed

.github/actions/build/action.yml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,58 @@ runs:
4545
shell: ${{ inputs.shell_type }}
4646
# Ubuntu 18 だとデフォルトでは g++-7 になりますが、std::filesystem を使う都合上 g++-9 を指定します。
4747

48-
- name: Configure CMake
48+
- name: Configure CMake for Unity
4949
run: >
5050
cmake
5151
-S ${{github.workspace}}
52-
-B ${{github.workspace}}/out/build/x64-Release
52+
-B ${{github.workspace}}/out/build/x64-Release-Unity
5353
-G "Ninja"
5454
-D CMAKE_BUILD_TYPE:STRING="${{env.BUILDTYPE}}"
5555
-D CMAKE_CXX_FLAGS="-w"
56+
-D BUILD_LIB_TYPE=dynamic
57+
-D RUNTIME_LIB_TYPE=MT
5658
${{ env.ADDITIONAL_CMAKE_OPTIONS }}
5759
shell: ${{ inputs.shell_type }}
5860
# 10万行超えの警告が出るので一時的な処置として警告を抑制しています。
5961

6062

61-
- name: Build by CMake
62-
run: cmake --build ${{github.workspace}}/out/build/x64-Release --config ${{env.BUILD_TYPE}}
63+
- name: Build by CMake for Unity
64+
run: cmake --build ${{github.workspace}}/out/build/x64-Release-Unity --config ${{env.BUILD_TYPE}}
65+
shell: ${{ inputs.shell_type }}
66+
67+
- name: Configure CMake for Unreal for non-Windows
68+
if: runner.os != 'Windows'
69+
run: >
70+
cmake
71+
-S ${{github.workspace}}
72+
-B ${{github.workspace}}/out/build/x64-Release-Unreal
73+
-G "Ninja"
74+
-D CMAKE_BUILD_TYPE:STRING="${{env.BUILDTYPE}}"
75+
-D CMAKE_CXX_FLAGS="-w"
76+
-D BUILD_LIB_TYPE=static
77+
-D RUNTIME_LIB_TYPE=MD
78+
${{ env.ADDITIONAL_CMAKE_OPTIONS }}
79+
shell: ${{ inputs.shell_type }}
80+
81+
# Unreal Engine側と Visual Studio のバージョンを合わせる必要があります。
82+
- name: Configure CMake for Unreal for Windows
83+
if: runner.os == 'Windows'
84+
run: >
85+
cmake
86+
-S ${{github.workspace}}
87+
-B ${{github.workspace}}/out/build/x64-Release-Unreal
88+
-G "Visual Studio 16 2019"
89+
-D CMAKE_INSTALL_PREFIX="C:/ninja"
90+
-D CMAKE_BUILD_TYPE:STRING="${{env.BUILDTYPE}}"
91+
-D CMAKE_CXX_FLAGS="-w"
92+
-D BUILD_LIB_TYPE=static
93+
-D RUNTIME_LIB_TYPE=MD
94+
${{ env.ADDITIONAL_CMAKE_OPTIONS }}
95+
shell: ${{ inputs.shell_type }}
96+
97+
- name: Build by CMake for Unreal
98+
run: |
99+
cmake --build ${{github.workspace}}/out/build/x64-Release-Unreal --config ${{env.BUILD_TYPE}}
63100
shell: ${{ inputs.shell_type }}
64101

65102

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [windows-latest, macos-latest, ubuntu-18.04]
20+
os: [windows-2019, macos-latest, ubuntu-20.04]
2121

2222
steps:
2323

@@ -40,7 +40,7 @@ jobs:
4040

4141
- name: Run Test
4242
run: |
43-
cd ${{github.workspace}}/out/build/x64-Release/bin
43+
cd ${{github.workspace}}/out/build/x64-Release-Unity/bin
4444
./plateau_test
4545
4646
- name: Run Test of C# Wrapper

.github/workflows/upload-dlls.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
os: [windows-latest, macos-latest, ubuntu-18.04]
25+
os: [windows-2019, macos-latest, ubuntu-20.04]
2626

2727
steps:
2828

@@ -47,34 +47,34 @@ jobs:
4747
if: runner.os == 'Windows'
4848
run: |
4949
mkdir D:\a\output -Force
50-
Copy-Item -Filter "*.dll" -Path ${{github.workspace}}\out\build\x64-Release\bin\* -Destination D:\a\output
50+
Copy-Item -Filter "*.dll" -Path ${{github.workspace}}\out\build\x64-Release-Unity\bin\* -Destination D:\a\output
5151
Copy-Item -Path ${{github.workspace}}\wrappers\csharp\LibPLATEAU.NET\CSharpPLATEAU\bin\Release\netstandard2.0\CSharpPLATEAU.dll -Destination D:\a\output
5252
5353
- name: Copy lib for Windows
5454
if: runner.os == 'Windows'
5555
run: |
56-
Copy-Item -Path ${{ github.workspace }}\out\build\x64-Release\3rdparty\libcitygml\lib\citygml.lib -Destination D:\a\output
57-
Copy-Item -Path ${{ github.workspace }}\out\build\x64-Release\src\plateau.lib -Destination D:\a\output
56+
Copy-Item -Path ${{ github.workspace }}\out\build\x64-Release-Unreal\src\${{env.BUILD_TYPE}}\plateau_combined.lib -Destination D:\a\output
5857
5958
- name: Upload DLL for Windows
6059
if: runner.os == 'Windows'
6160
uses: actions/upload-artifact@v2
6261
with:
63-
name: libplateau-windows-dll
62+
name: libplateau-windows
6463
path: D:\a\output
6564

6665
- name: Copy Libraries for Ubuntu and MacOS
6766
if: runner.os != 'Windows'
6867
run: |
6968
mkdir $HOME/output/
70-
find ${{github.workspace}}/out/build/x64-Release -name *.so -or -name *.dylib -or -name libcitygml.a | xargs -I {} cp -v {} $HOME/output
69+
find ${{github.workspace}}/out/build/x64-Release-Unity -name *.so -or -name *.dylib | xargs -I {} cp -v {} $HOME/output
70+
find ${{github.workspace}}/out/build/x64-Release-Unreal -name libplateau*.a | xargs -I {} cp -v {} $HOME/output
7171
echo "HOME=$(echo $HOME)" >> $GITHUB_ENV
7272
7373
- name: Upload DLL(so, dylib) for Ubuntu and MacOS
7474
if: runner.os != 'Windows'
7575
uses: actions/upload-artifact@v2
7676
with:
77-
name: libplateau-${{matrix.os}}-dll
77+
name: libplateau-${{matrix.os}}
7878
path: ${{env.HOME}}/output/
7979

8080
# 2つ目のジョブ。
@@ -206,10 +206,10 @@ jobs:
206206
mkdir -p ~/a/plateau-plugins/dynamic-libs/ManagedDLL
207207
mkdir -p ~/a/plateau-plugins/dynamic-libs/Android
208208
mkdir -p ~/a/plateau-plugins/dynamic-libs/iOS/plateau.framework
209-
cp ~/a/libplateau-windows-dll/plateau.dll ~/a/plateau-plugins/dynamic-libs/Windows/x86_64
210-
cp ~/a/libplateau-windows-dll/CSharpPLATEAU.dll ~/a/plateau-plugins/dynamic-libs/ManagedDLL
211-
cp ~/a/libplateau-ubuntu-18.04-dll/*.so ~/a/plateau-plugins/dynamic-libs/Linux/x86_64
212-
cp ~/a/libplateau-macos-latest-dll/*.dylib ~/a/plateau-plugins/dynamic-libs/MacOS/x86_64
209+
cp ~/a/libplateau-windows/plateau.dll ~/a/plateau-plugins/dynamic-libs/Windows/x86_64
210+
cp ~/a/libplateau-windows/CSharpPLATEAU.dll ~/a/plateau-plugins/dynamic-libs/ManagedDLL
211+
cp ~/a/libplateau-ubuntu-20.04/*.so ~/a/plateau-plugins/dynamic-libs/Linux/x86_64
212+
cp ~/a/libplateau-macos-latest/*.dylib ~/a/plateau-plugins/dynamic-libs/MacOS/x86_64
213213
cp ~/a/libplateau-android-dll/libplateau.so ~/a/plateau-plugins/dynamic-libs/Android
214214
cp ~/a/libplateau-ios-dll/* ~/a/plateau-plugins/dynamic-libs/iOS/plateau.framework
215215
@@ -218,9 +218,9 @@ jobs:
218218
mkdir -p ~/a/plateau-plugins/static-libs/windows
219219
mkdir -p ~/a/plateau-plugins/static-libs/linux
220220
mkdir -p ~/a/plateau-plugins/static-libs/macos
221-
cp ~/a/libplateau-windows-dll/*.lib ~/a/plateau-plugins/static-libs/windows
222-
cp ~/a/libplateau-ubuntu-18.04-dll/*.a ~/a/plateau-plugins/static-libs/linux
223-
cp ~/a/libplateau-macos-latest-dll/*.a ~/a/plateau-plugins/static-libs/macos
221+
cp ~/a/libplateau-windows/*.lib ~/a/plateau-plugins/static-libs/windows
222+
cp ~/a/libplateau-ubuntu-20.04/*.a ~/a/plateau-plugins/static-libs/linux
223+
cp ~/a/libplateau-macos-latest/*.a ~/a/plateau-plugins/static-libs/macos
224224
225225
- name: upload artifact
226226
uses: actions/upload-artifact@v3

3rdparty/libcitygml

CMakeLists.txt

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
# README.md を参照するか、 .github/actions/build/action.yml の Configure CMake の箇所を参照してコマンド例とします。
99

1010
# 【ビルドの方針】
11+
# [Unity向けビルドの場合]
1112
# 最終的に libplateau.dll (または .so , .dylib ) が1つだけ出力されるようにします(example, libを除く)。
1213
# なぜなら soファイルが複数できてしまうと、Unityに取り込んだときに .so同士の依存関係が解決されず DllNotFoundExceptionになるためです。
1314
# ビルド時の依存関係を矢印で表すと次のようになります。
1415
# plateau.dll (c_wrapperを含む) --> (3rdparty/libcitygml, 3rdparty/xerces_c)
16+
#
17+
# [Unreal Engine向けビルドの場合]
18+
# 静的ライブラリをビルドします。
1519

1620
# 【トラブルシューティング】
1721
# Linux の Unity で DllNotFoundException になった場合
@@ -21,22 +25,49 @@
2125
# ldd ./libplateau.so | grep "not found”
2226

2327

24-
# github actions で cmakeのオプション -S -B を使いたいのでこれを最小バージョンとします。
25-
cmake_minimum_required(VERSION 3.13)
28+
cmake_minimum_required(VERSION 3.8)
29+
cmake_policy(SET CMP0076 NEW)
30+
31+
# 引数チェック
32+
# cmakeの引数で、次の変数が指定される必要があります。
33+
# ・ -D BUILD_LIB_TYPE=static or dynamic ビルドするのは静的ライブラリか動的ライブラリか
34+
# ・ -D RUNTIME_LIB_TYPE=MT or MD (Windowsのみ) MT か MD か
35+
# デフォルト値は Unity向けに dynamic, MT です。ただし Debugビルドの時は Unity でも MD にしてください。
36+
SET(BUILD_LIB_TYPE "dynamic" CACHE STRING "static or dynamic")
37+
SET(RUNTIME_LIB_TYPE "MT" CACHE STRING "MT or MD")
38+
if(NOT ( BUILD_LIB_TYPE STREQUAL "static" OR BUILD_LIB_TYPE STREQUAL "dynamic"))
39+
message(FATAL_ERROR "Variable not set. use -D BUILD_LIB_TYPE=static or dynamic")
40+
endif()
41+
if(NOT (RUNTIME_LIB_TYPE STREQUAL "MT" OR RUNTIME_LIB_TYPE STREQUAL "MD"))
42+
message(FATAL_ERROR "Variable not set. use -D RUNTIME_LIB_TYPE=MT or MD")
43+
endif()
2644

2745
# MSVC_RUNTIME_LIBRARYプロパティを有効化
2846
# 参考:https://cmake.org/cmake/help/latest/policy/CMP0091.html
2947
if(POLICY CMP0091)
3048
cmake_policy(SET CMP0091 NEW)
3149
endif()
3250

33-
# MDd or MTでコンパイル
34-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:DebugDLL>")
51+
# (Windows向け) MT or MD or MTd or MDd のどれでコンパイルするか決めます。
52+
# CMAKE_MSVC_RUNTIME_LIBRARY の値は最終的に次の4択のどれかになります:
53+
# MultiThreaded, MultiThreadedDebug, MultiThreadedDll, MultiThreadedDebugDll
54+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
55+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
56+
string(APPEND CMAKE_MSVC_RUNTIME_LIBRARY "Debug" )
57+
endif()
58+
if(RUNTIME_LIB_TYPE STREQUAL "MD")
59+
string(APPEND CMAKE_MSVC_RUNTIME_LIBRARY "DLL")
60+
endif()
61+
message("CMAKE_MSVC_RUNTIME_LIBRARY = ${CMAKE_MSVC_RUNTIME_LIBRARY}")
62+
63+
3564

3665
enable_language(CXX)
3766
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3867
set(CMAKE_CXX_STANDARD 17)
3968
set(CMAKE_CXX_EXTENSIONS OFF)
69+
message(compiler_id = ${CMAKE_CXX_COMPILER_ID}, compiler_version = ${CMAKE_CXX_COMPILER_VERSION})
70+
4071

4172

4273
# Xerces-C ライブラリの問題を修正するための措置です。
@@ -54,15 +85,18 @@ project("libplateau")
5485

5586
set(LIBPLATEAU_BINARY_DIR ${libplateau_BINARY_DIR}/bin)
5687

88+
89+
5790
# Linuxで shared library を作るときにはコンパイルオプション -fPIC が必要なので付加します。
5891
# ただし、Windowsの MSVC でコンパイルするときは -fPIC が不要で、付けると警告が出るので付加しません。
5992
include(CheckCXXCompilerFlag)
6093
check_cxx_compiler_flag(-fPIC COMPILER_SUPPORTS_PIC)
61-
if(COMPILER_SUPPORTS_PIC)
94+
if(COMPILER_SUPPORTS_PIC AND (BUILD_LIB_TYPE STREQUAL "dynamic"))
6295
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
6396
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
6497
endif()
6598

99+
66100
# ソースファイルの文字コードはデフォルトでは、 Windows日本語版のMSVC だと Shift_JIS、それ以外だと UTF-8 です。
67101
# 今回は文字コードを統一したいので UTF-8 にします。
68102
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
@@ -76,6 +110,12 @@ if( NOT(IOS OR ANDROID) )
76110
## Xerces-C をビルドします。
77111
### libcitygmlのFindXercesを通すために全てキャッシュ化
78112
set(BUILD_SHARED_LIBS false CACHE BOOL "" FORCE)
113+
### Xerces-cのうちネットワーク機能はビルドしません
114+
set(network false CACHE BOOL "" FORCE)
115+
### macOSの場合に Xerces-C が利用する transcodedr を指定します。
116+
if(APPLE)
117+
set(transcoder macosunicodeconverter CACHE BOOL "" FORCE)
118+
endif()
79119
add_subdirectory("3rdparty/xerces-c")
80120
set(XERCESC_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/xerces-c/src" "${libplateau_BINARY_DIR}/3rdparty/xerces-c/src" CACHE STRING "" FORCE)
81121
set(XERCESC_LIBRARY xerces-c CACHE STRING "" FORCE)
@@ -88,7 +128,10 @@ set(LIBCITYGML_USE_GDAL OFF CACHE BOOL "" FORCE)
88128
set(XERCESC_WAS_STATIC ON CACHE BOOL "" FORCE)
89129

90130
set(LIBCITYGML_DYNAMIC OFF CACHE BOOL "" FORCE)
131+
132+
91133
add_subdirectory("3rdparty/libcitygml")
134+
92135
set(LIBCITYGML_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/libcitygml/sources/include")
93136

94137
## glTF-SDK
@@ -98,13 +141,16 @@ set(GLTFSDK_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/glTF-SDK/glTF-SDK/GLTF
98141
if( NOT(IOS OR ANDROID) )
99142
# FBX SDK 以下のディレクトリで debug と release のどちらを利用するか決めます。
100143
# debug なら debug/*-md.lib を使い、release なら release/*-mt.lib を使います。
101-
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
102-
set(FBXSDK_LAST_DIR_NAME "debug")
144+
if(RUNTIME_LIB_TYPE STREQUAL "MD")
103145
set(FBXSDK_MT_OR_MD "md")
104146
else()
105-
set(FBXSDK_LAST_DIR_NAME "release")
106147
set(FBXSDK_MT_OR_MD "mt")
107148
endif()
149+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
150+
set(FBXSDK_LAST_DIR_NAME "debug")
151+
else()
152+
set(FBXSDK_LAST_DIR_NAME "release")
153+
endif()
108154

109155
## zlib(FBX SDKの依存関係)
110156
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/zlib")
@@ -156,10 +202,16 @@ if( NOT(IOS OR ANDROID) )
156202
endif()
157203

158204
set(FBXSDK_LIB_PATH_SUFFIXES "${FBXSDK_LIB_PATH_SUFFIXES}/${FBXSDK_LAST_DIR_NAME}")
205+
set(FBXSDK_LIB_NAME "libfbxsdk")
206+
if(WIN32)
207+
string(APPEND FBXSDK_LIB_NAME "-${FBXSDK_MT_OR_MD}")
208+
else()
209+
string(APPEND FBXSDK_LIB_NAME ".a")
210+
endif()
159211

160212
find_library(FBXSDK_LIBRARIES
161213
NAMES
162-
libfbxsdk-md libfbxsdk-mt libfbxsdk.a
214+
${FBXSDK_LIB_NAME}
163215
PATHS
164216
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/fbx_sdk/2020.3.1/lib
165217
PATH_SUFFIXES
@@ -170,16 +222,21 @@ if( NOT(IOS OR ANDROID) )
170222
message("${FBXSDK_LIB_PATH_SUFFIXES} , ${FBXSDK_LIBRARIES}")
171223
endif()
172224

225+
## openssl
226+
add_subdirectory("3rdparty/openssl-cmake")
227+
173228
# cpp-httplib
229+
set(HTTPLIB_COMPILE TRUE CACHE BOOL "" FORCE)
174230
add_subdirectory("3rdparty/cpp-httplib")
175231
set(CPPHTTPLIB_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cpp-httplib")
176232

177-
## openssl
178-
add_subdirectory("3rdparty/openssl-cmake")
233+
####################################
234+
# libplateau 本体の Cmake ファイルです。
179235

180-
# libplateau をビルドします。
181236
add_subdirectory("src")
182237

238+
####################################
239+
183240
if( NOT(IOS OR ANDROID) )
184241
## Examples
185242
add_subdirectory("examples/log_skipped_elements")

0 commit comments

Comments
 (0)