-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
156 lines (132 loc) · 4.52 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
# CMakeLists.txt -- Build system for the Layer Lab
#
# Copyright (c) 2015 Wenzel Jakob <[email protected]>
#
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
cmake_minimum_required(VERSION 2.8.12)
project(layerlab)
option(USE_AVX "Enable AVX optimizations" TRUE)
set(LAYERLAB_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling layer lab")
include(CheckCXXCompilerFlag)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
# Build TBB
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_MACOSX_RPATH ON)
endif()
option(TBB_BUILD_SHARED "" OFF)
option(TBB_BUILD_STATIC "" ON)
option(TBB_BUILD_TESTS "" OFF)
option(TBB_BUILD_TBBMALLOC "" OFF)
option(TBB_BUILD_TBBMALLOC_PROXY "" OFF)
add_subdirectory(ext/tbb)
add_subdirectory(ext/pybind11)
set(CMAKE_MACOSX_RPATH ON)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (HAS_CPP14_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (HAS_CPP11_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "Unsupported compiler -- at least C++11 support is needed!")
endif()
# Enable link time optimization and set the default symbol
# visibility to hidden (very important to obtain small binaries)
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
# Default symbol visibility
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
# Check for Link Time Optimization support
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
if (HAS_LTO_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
endif()
endif()
endif()
# Search for FFTW3
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(FFTW)
if (PKG_FFTW_FOUND)
add_definitions("-DHAVE_FFTW")
include_directories(${FFTW_INCLUDES})
endif()
# Compile with AVX
if (USE_AVX)
if (MSVC)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
endif()
endif()
# Compile with compiler warnings turned on
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
# Set platform-specific flags
if (WIN32)
add_definitions(-D__WINDOWS__ -D_UNICODE)
elseif(UNIX)
if(APPLE)
add_definitions(-D__OSX__)
else()
add_definitions(-D__LINUX__)
endif()
endif()
include_directories(
${PYTHON_INCLUDE_DIR}
ext/eigen
ext/filesystem
ext/pybind11/include
ext/tbb/include
ext/tinyformat
include
)
pybind11_add_module(layerlab SHARED
# Layer lab files
include/layer/common.h
include/layer/color.h
include/layer/frame.h
include/layer/spline.h
include/layer/quad.h
include/layer/simd.h
include/layer/vector.h
include/layer/math.h src/math.cpp
include/layer/hg.h src/hg.cpp
include/layer/fourier.h src/fourier.cpp
include/layer/microfacet.h src/microfacet.cpp
include/layer/layer.h src/layer.cpp
include/layer/fresnel.h src/fresnel.cpp
include/layer/mmap.h src/mmap.cpp
include/layer/log.h src/log.cpp
include/layer/storage.h src/storage.cpp
include/layer/simd.h src/simd.cpp
# Python API
src/python.cpp src/py_math.cpp src/py_fourier.cpp
src/py_spline.cpp src/py_layer.cpp src/py_quad.cpp src/py_fresnel.cpp
src/py_filesystem.cpp
)
add_custom_target(mkdoc COMMAND
python3 ${CMAKE_CURRENT_SOURCE_DIR}/ext/pybind11/tools/mkdoc.py
-I${PYTHON_INCLUDE_DIR} -Iext/eigen -Iext/pybind11/include -Iext/filesystem
-Iext/tinyformat -Iinclude
${CMAKE_CURRENT_SOURCE_DIR}/include/layer/*.h > ${CMAKE_CURRENT_SOURCE_DIR}/src/py_doc.h)
set_target_properties(layerlab PROPERTIES PREFIX "")
link_directories(${CMAKE_CURRENT_BUILD_DIR}/tbb)
target_link_libraries(layerlab PRIVATE tbb_static)
if (PKG_FFTW_FOUND)
target_link_libraries(layerlab PRIVATE ${FFTW_THREADS_LIB})
endif()