forked from cpichard/usdtweak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
99 lines (81 loc) · 3.29 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
cmake_minimum_required (VERSION 3.14)
project(usdtweak)
find_package(OpenGL REQUIRED)
find_package(pxr REQUIRED)
if (${PXR_VERSION} VERSION_GREATER_EQUAL 2208)
find_package(MaterialX)
endif()
set(CMAKE_CXX_STANDARD 14)
if (${PXR_VERSION} VERSION_GREATER_EQUAL 2311)
set(CMAKE_CXX_STANDARD 17)
endif()
# for glfw, if the user doesn't specify the glfw install dir, we attempt to
# download the latest version and add it to the project directly
if (DEFINED glfw3_DIR)
find_package(glfw3 3.3 REQUIRED)
else ()
include(FetchContent)
FetchContent_Declare(
glfw
URL https://github.com/glfw/glfw/releases/download/3.3.8/glfw-3.3.8.zip
)
set(GLFW_BUILD_EXAMPLES OFF)
set(GLFW_BUILD_TESTS OFF)
set(GLFW_BUILD_DOCS OFF)
set(GLFW_INSTALL OFF)
FetchContent_MakeAvailable(glfw)
endif (DEFINED glfw3_DIR)
# Get the stamp informations, git hash, time stamp, stuff like that
add_custom_target(stamp
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/src/Stamp.h ${CMAKE_CURRENT_SOURCE_DIR}/src/Stamp.cpp
COMMAND ${CMAKE_COMMAND}
-DSRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
-DDST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/stamp.cmake"
)
# Use folders in the generated xcode/vs projects
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (APPLE)
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
# And this part tells CMake where to find and install the file itself
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/icon.icns)
set_source_files_properties(${myApp_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
add_executable(usdtweak MACOSX_BUNDLE ${myApp_ICON})
set_target_properties(usdtweak PROPERTIES
OUTPUT_NAME "usdtweak"
MACOSX_BUNDLE TRUE)
else()
add_executable(usdtweak)
endif()
add_dependencies(usdtweak stamp)
add_subdirectory(src)
target_compile_definitions(usdtweak PRIVATE NOMINMAX)
target_link_libraries(usdtweak glfw resources ${OPENGL_gl_LIBRARY} ${PXR_LIBRARIES} ${MATERIALX_LIBRARIES} $<$<CXX_COMPILER_ID:MSVC>:Shlwapi.lib>)
target_include_directories(usdtweak PUBLIC ${OPENGL_INCLUDE_DIR} ${PXR_INCLUDE_DIRS})
set(USE_PYTHON3 OFF CACHE BOOL "Compile with the Python3 target")
if (USE_PYTHON3)
message(STATUS "Looking for Python3 target")
find_package(Python3 COMPONENTS Development)
target_link_libraries(usdtweak Python3::Python)
endif()
# Installer on windows
if(WIN32)
include("cmake/windows_installer.cmake")
endif()
# Installer on macOS
if(APPLE)
include("cmake/macos_installer.cmake")
endif()
# Remove warnings coming from usd and enable default multithreaded compilation on windows
target_compile_options(usdtweak PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/MP /wd4244 /wd4305 /wd4996>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated>)
# Fix compilation error with C++17 on macos
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_STANDARD MATCHES "17")
add_compile_definitions(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
endif()
# Organise the sources using the same hierarchy as the filesystem in xcode and vs projects
get_target_property(USDTWEAK_SOURCES usdtweak SOURCES)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src"
PREFIX "src"
FILES ${USDTWEAK_SOURCES})