-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
136 lines (112 loc) · 4.85 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
# Copyright Disney Enterprises, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License
# and the following modification to it: Section 6 Trademarks.
# deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the
# trade names, trademarks, service marks, or product names of the
# Licensor and its affiliates, except as required for reproducing
# the content of the NOTICE file.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
cmake_minimum_required(VERSION 3.15.0)
project(ptexutils LANGUAGES CXX)
set(${PROJECT_NAME}_MAJOR_VERSION 0)
set(${PROJECT_NAME}_MINOR_VERSION 1)
set(${PROJECT_NAME}_PATCH_LEVEL 0)
set(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)
set(OpenGL_GL_PREFERENCE GLVND)
include(GNUInstallDirs)
## Setup platform specific helper defines build variants
if (WIN32)
add_compile_definitions(-DPTEXUTILS_WIN32 -D_USE_MATH_DEFINES)
endif()
# Adjust OpenMP in Clang on Apple platforms
IF(APPLE)
IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(OpenMP_C "${CMAKE_C_COMPILER}" CACHE STRING "" FORCE)
SET(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
SET(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
SET(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
SET(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
SET(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
ENDIF()
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(OpenMP_CXX "${CMAKE_CXX_COMPILER}" CACHE STRING "" FORCE)
SET(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
SET(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
SET(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
SET(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
SET(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
ENDIF()
# Default (Command-line tools & Xcode toolchain) compiler won't provide proper OpenMP functionality on macOS.
# Compiler obtained from `brew install llvm` will suffice.
# Create a symbolic link for ease of use.
SET(CMAKE_CXX_COMPILER clang-omp++ CACHE STRING "C++ compiler" FORCE)
ENDIF()
## Choose build options
# Disney specific method of choosing variant
if ("$ENV{FLAVOR}" STREQUAL "optimize")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "type of build" FORCE)
endif()
if ("$ENV{FLAVOR}" STREQUAL "debug")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE)
endif()
# Set to release if nothing else defined
if(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
if (DEFINED ENV{CXXFLAGS_STD})
string(REPLACE "c++" "" cxx_std $ENV{CXXFLAGS_STD})
set(CMAKE_CXX_STANDARD ${cxx_std})
endif()
## Set install location
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
execute_process(COMMAND sh -c "echo `uname`-`uname -r | cut -d'-' -f1`-`uname -m`"
OUTPUT_VARIABLE VARIANT_DIRECTORY
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}")
endif()
if (DEFINED ENV{RP_glew})
set(GLEW_ROOT $ENV{RP_glew} CACHE PATH "glew location" FORCE)
endif()
if (DEFINED ENV{RP_freeglut})
set(GLUT_ROOT $ENV{RP_freeglut} CACHE PATH "glut location" FORCE)
endif()
if (DEFINED ENV{RP_mesa})
set(OPENGL_INCLUDE_DIR "$ENV{RP_mesa}/include" CACHE PATH "OpenGL headers" FORCE)
set(OPENGL_EGL_INCLUDE_DIR "$ENV{RP_mesa}/include" CACHE PATH "OpenGL EGL headers" FORCE)
set(OPENGL_GL_INCLUDE_DIR "$ENV{RP_mesa}/include" CACHE PATH "OpenGL GL headers" FORCE)
set(OPENGL_GLX_INCLUDE_DIR "$ENV{RP_mesa}/include" CACHE PATH "OpenGL GLX headers" FORCE)
endif()
if (DEFINED ENV{RP_zlib})
set(ZLIB_ROOT $ENV{RP_zlib} CACHE PATH "zlib location" FORCE)
endif()
## Set the cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
## Search for useful libraries
find_package(Ptex REQUIRED)
find_package(OpenMP REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OIIO REQUIRED)
## Trasitive dependency, needed when linking with static libPTex
find_package(ZLIB REQUIRED)
## Use static ptex library
option(PTEX_USE_STATIC_LIBS "Link against Ptex static libraries" ON)
if (PTEX_USE_STATIC_LIBS)
set(PTEX_LIBRARIES Ptex::Ptex_static)
else()
set(PTEX_LIBRARIES Ptex::Ptex_dynamic)
endif()
## Traverse subdirectories
add_subdirectory(src)