-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
211 lines (185 loc) · 7.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
cmake_minimum_required(VERSION 3.18)
set(PROJECT_NAME FbxParser)
set(COMPILER_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(COMPILER_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
OPTION(FBX_VENDER_DIR "Optional Fbx SDK path." "")
OPTION(USE_IMAGE_SHARED "Use image as shared lib." OFF)
message("${FBX_VENDER_DIR}")
set(OSX_VERSION "10.9")
if (WIN32)
project(${PROJECT_NAME} C CXX ASM)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
endif()
if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "${OSX_VERSION}" CACHE STRING "Minimum OS X deployment version")
project(${PROJECT_NAME} C CXX OBJC ASM)
set(CMAKE_C_FLAGS "-fobjc-arc")
set(CMAKE_CXX_FLAGS "-std=c++14 -stdlib=libc++ -fobjc-arc")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")
set(CMAKE_MACOSX_RPATH ON)
set(BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(CMAKE_BUILD_TYPE MATCHES DEBUG OR CMAKE_BUILD_TYPE MATCHES RELWITHDEBINFO)
elseif(CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES MINSIZEREL)
else()
set(CMAKE_BUILD_TYPE "MINSIZEREL")
endif()
file (
GLOB_RECURSE fbx_src
LIST_DIRECTORIES false
"${PROJECT_SOURCE_DIR}/Source/*.cpp"
"${PROJECT_SOURCE_DIR}/Source/*.h"
)
foreach(_source IN ITEMS ${fbx_src})
if (IS_ABSOLUTE "${_source}")
file(RELATIVE_PATH _source_rel "${PROJECT_SOURCE_DIR}" "${_source}")
else()
set(_source_rel "${_source}")
endif()
get_filename_component(_source_path "${_source_rel}" PATH)
if (WIN32)
string(REPLACE "/" "\\" _source_path_replaced "${_source_path}")
else()
set(_source_path_replaced "${_source_path}")
endif()
source_group("${_source_path_replaced}" FILES "${_source}")
endforeach()
set(LIBRARY_NAME "fbx")
add_library(${LIBRARY_NAME} SHARED ${fbx_src})
add_subdirectory(ThirdParty)
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
endif()
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/ThirdParty/ForsythTriOO")
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/ThirdParty/ext-mikktspace")
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/ThirdParty/glm")
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/ThirdParty/spdlog/include")
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/ThirdParty/filesystem/include")
target_include_directories(${LIBRARY_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/Source")
target_link_libraries(${LIBRARY_NAME} "ForsythTriOO")
target_link_libraries(${LIBRARY_NAME} "ext-mikktspace")
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
if(USE_IMAGE_SHARED)
target_include_directories(${LIBRARY_NAME} PRIVATE "${IMAGE_DECODER_INSTALL_DIR}/include")
target_link_libraries(${LIBRARY_NAME} "${IMAGE_DECODER_INSTALL_DIR}/lib/image.lib")
else()
target_compile_definitions(${LIBRARY_NAME} PRIVATE IMAGE_STATIC)
file(
GLOB_RECURSE image_libs
LIST_DIRECTORIES false
"${IMAGE_DECODER_INSTALL_DIR}/lib/*.lib"
)
target_include_directories(${LIBRARY_NAME} PRIVATE "${IMAGE_DECODER_INSTALL_DIR}/include")
target_link_libraries(${LIBRARY_NAME} "${image_libs}")
endif()
else()
if(USE_IMAGE_SHARED)
target_include_directories(${LIBRARY_NAME} PRIVATE "${IMAGE_DECODER_INSTALL_DIR}/include")
target_link_libraries(${LIBRARY_NAME} "${IMAGE_DECODER_INSTALL_DIR}/bin/libimage.dylib")
else()
target_compile_definitions(${LIBRARY_NAME} PRIVATE IMAGE_STATIC)
file(
GLOB_RECURSE image_libs
LIST_DIRECTORIES false
"${IMAGE_DECODER_INSTALL_DIR}/lib/*.a"
)
target_include_directories(${LIBRARY_NAME} PRIVATE "${IMAGE_DECODER_INSTALL_DIR}/include")
target_link_libraries(${LIBRARY_NAME} "${image_libs}")
endif()
target_compile_options(${LIBRARY_NAME} PUBLIC -fvisibility=hidden)
target_compile_options(${LIBRARY_NAME} PUBLIC -fvisibility-inlines-hidden)
endif()
# Search for FBX sdk package
if("${FBX_VENDER_DIR}" STREQUAL "")
unset(FBX_VENDER_DIR)
else()
if (WIN32)
string(REPLACE "/" "\\" FBX_VENDER_DIR_REPLCAED "${FBX_VENDER_DIR}")
else()
set(FBX_VENDER_DIR_REPLCAED "${FBX_VENDER_DIR}")
endif()
set(FBX_DIR "${FBX_VENDER_DIR}/*/")
message(${FBX_DIR})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
find_package(Fbx 2020.2.1)
if(NOT FBX_FOUND)
message("Fbx SDK not found!")
else()
target_include_directories(${LIBRARY_NAME} PUBLIC ${FBX_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME} debug ${FBX_LIBRARIES_DEBUG} optimized ${FBX_LIBRARIES})
endif()
target_compile_definitions(${LIBRARY_NAME} PRIVATE FBX_DLL)
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME}
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}")
set(LIBRARY_PUBLIC_HDRS
${PROJECT_SOURCE_DIR}/Source/FbxParser.h
)
install(FILES ${LIBRARY_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
if(WIN32)
install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}> DESTINATION bin OPTIONAL)
endif()
# ============ Test ==============
file (
GLOB_RECURSE main_src
LIST_DIRECTORIES false
"${PROJECT_SOURCE_DIR}/Test/*.cpp"
"${PROJECT_SOURCE_DIR}/Test/*.h"
)
foreach(_source IN ITEMS ${main_src})
if (IS_ABSOLUTE "${_source}")
file(RELATIVE_PATH _source_rel "${PROJECT_SOURCE_DIR}" "${_source}")
else()
set(_source_rel "${_source}")
endif()
get_filename_component(_source_path "${_source_rel}" PATH)
if (WIN32)
string(REPLACE "/" "\\" _source_path_replaced "${_source_path}")
else()
set(_source_path_replaced "${_source_path}")
endif()
source_group("${_source_path_replaced}" FILES "${_source}")
endforeach()
add_executable(${PROJECT_NAME} ${main_src})
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/ThirdParty/rapidjson/include")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/ThirdParty/cxxopts/include")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/ThirdParty/filesystem/include")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/ThirdParty/glm")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/Test")
target_include_directories(${PROJECT_NAME} PUBLIC "${PROJECT_SOURCE_DIR}/Source")
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
endif()
target_link_libraries(${PROJECT_NAME} ${LIBRARY_NAME})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "$<TARGET_FILE_DIR:${LIBRARY_NAME}>" "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)
if(WIN32)
if(USE_IMAGE_SHARED)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${IMAGE_DECODER_INSTALL_DIR}/bin" "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)
endif()
else()
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,./")
set_target_properties(${PROJECT_NAME} PROPERTIES CMAKE_BUILD_RPATH "$ORIGIN")
set_target_properties(${PROJECT_NAME} PROPERTIES CMAKE_INSTALL_RPATH "$ORIGIN")
if(USE_IMAGE_SHARED)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${IMAGE_DECODER_INSTALL_DIR}/bin" "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)
endif()
endif()