20e9750bed6b4c56ea8815f33230afb0399b4d5f
[blender.git] / build_files / build_environment / cmake / options.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ***** END GPL LICENSE BLOCK *****
18
19 if(WIN32)
20         option(ENABLE_MINGW64 "Enable building of ffmpeg/iconv/libsndfile/lapack/fftw3 by installing mingw64" ON)
21 endif()
22 option(WITH_WEBP "Enable building of oiio with webp support" OFF)
23 option(WITH_EMBREE "Enable building of Embree" OFF)
24 set(MAKE_THREADS 1 CACHE STRING "Number of threads to run make with")
25
26 if(NOT BUILD_MODE)
27         set(BUILD_MODE "Release")
28         message(STATUS "Build type not specified: defaulting to a release build.")
29 endif()
30 message("BuildMode = ${BUILD_MODE}")
31
32 if(BUILD_MODE STREQUAL "Debug")
33         set(LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/Debug)
34 else(BUILD_MODE STREQUAL "Debug")
35         set(LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/Release)
36 endif()
37
38 option(DOWNLOAD_DIR "Path for downloaded files" ${CMAKE_CURRENT_SOURCE_DIR}/downloads)
39 file(TO_CMAKE_PATH ${DOWNLOAD_DIR} DOWNLOAD_DIR)
40 set(PATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/patches)
41 set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/build)
42
43 message("LIBDIR = ${LIBDIR}")
44 message("DOWNLOAD_DIR = ${DOWNLOAD_DIR}")
45 message("PATCH_DIR = ${PATCH_DIR}")
46 message("BUILD_DIR = ${BUILD_DIR}")
47
48 if(WIN32)
49         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
50                 set(PATCH_CMD ${DOWNLOAD_DIR}/mingw/mingw64/msys/1.0/bin/patch.exe)
51         else()
52                 set(PATCH_CMD ${DOWNLOAD_DIR}/mingw/mingw32/msys/1.0/bin/patch.exe)
53         endif()
54         set(LIBEXT ".lib")
55         set(LIBPREFIX "")
56
57         # For OIIO and OSL
58         set(COMMON_DEFINES /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS)
59
60         if(MSVC_VERSION GREATER 1909)
61                 set(COMMON_MSVC_FLAGS "/Wv:18") #some deps with warnings as error aren't quite ready for dealing with the new 2017 warnings.
62         endif()
63         set(COMMON_MSVC_FLAGS "${COMMON_MSVC_FLAGS} /bigobj")
64         if(WITH_OPTIMIZED_DEBUG)
65                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "/MTd ${COMMON_MSVC_FLAGS} /O2 /Ob2 /DNDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
66         else()
67                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "/MTd ${COMMON_MSVC_FLAGS} /Zi /Ob0 /Od /RTC1 /D_DEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
68         endif()
69         set(BLENDER_CMAKE_C_FLAGS_MINSIZEREL "/MT ${COMMON_MSVC_FLAGS} /O1 /Ob1 /D NDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
70         set(BLENDER_CMAKE_C_FLAGS_RELEASE "/MT ${COMMON_MSVC_FLAGS} /O2 /Ob2 /DNDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
71         set(BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO "/MT ${COMMON_MSVC_FLAGS} /Zi /O2 /Ob1 /D NDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
72
73         if(WITH_OPTIMIZED_DEBUG)
74                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "/MTd ${COMMON_MSVC_FLAGS} /O2 /Ob2 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
75         else()
76                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /D PLATFORM_WINDOWS /MTd  ${COMMON_MSVC_FLAGS} /Zi /Ob0 /Od /RTC1 /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
77         endif()
78         set(BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL "/MT /${COMMON_MSVC_FLAGS} /O1 /Ob1 /D NDEBUG  /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
79         set(BLENDER_CMAKE_CXX_FLAGS_RELEASE "/MT ${COMMON_MSVC_FLAGS} /O2 /Ob2 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
80         set(BLENDER_CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT ${COMMON_MSVC_FLAGS} /Zi /O2 /Ob1 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
81
82         set(PLATFORM_FLAGS)
83         set(PLATFORM_CXX_FLAGS)
84         set(PLATFORM_CMAKE_FLAGS)
85
86         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
87                 set(MINGW_PATH ${DOWNLOAD_DIR}/mingw/mingw64)
88                 set(MINGW_SHELL ming64sh.cmd)
89                 set(PERL_SHELL ${DOWNLOAD_DIR}/perl/portableshell.bat)
90                 set(MINGW_HOST x86_64-w64-mingw32)
91         else()
92                 set(MINGW_PATH ${DOWNLOAD_DIR}/mingw/mingw32)
93                 set(MINGW_SHELL ming32sh.cmd)
94                 set(PERL_SHELL ${DOWNLOAD_DIR}/perl32/portableshell.bat)
95                 set(MINGW_HOST i686-w64-mingw32)
96         endif()
97
98         set(CONFIGURE_ENV
99                 cd ${MINGW_PATH} &&
100                 call ${MINGW_SHELL} &&
101                 call ${PERL_SHELL} &&
102                 set path &&
103                 set CFLAGS=-g &&
104                 set LDFLAGS=-Wl,--as-needed -static-libgcc
105         )
106
107         set(CONFIGURE_ENV_NO_PERL
108                 cd ${MINGW_PATH} &&
109                 call ${MINGW_SHELL} &&
110                 set path &&
111                 set CFLAGS=-g &&
112                 set LDFLAGS=-Wl,--as-needed -static-libgcc
113         )
114
115         set(CONFIGURE_COMMAND sh ./configure)
116         set(CONFIGURE_COMMAND_NO_TARGET ${CONFIGURE_COMMAND})
117 else()
118         set(PATCH_CMD patch)
119         set(LIBEXT ".a")
120         set(LIBPREFIX "lib")
121
122         if(APPLE)
123                 # Let's get the current Xcode dir, to support xcode-select
124                 execute_process(
125                         COMMAND xcode-select --print-path
126                         OUTPUT_VARIABLE XCODE_DEV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE
127                 )
128                 set(OSX_ARCHITECTURES x86_64)
129                 set(OSX_DEPLOYMENT_TARGET 10.9)
130                 set(OSX_SDK_VERSION 10.13)
131                 set(OSX_SYSROOT ${XCODE_DEV_PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk)
132
133                 set(PLATFORM_CFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET}")
134                 set(PLATFORM_CXXFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET} -std=c++11 -stdlib=libc++")
135                 set(PLATFORM_LDFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET}")
136                 set(PLATFORM_BUILD_TARGET --build=x86_64-apple-darwin13.0.0) # OS X 10.9
137                 set(PLATFORM_CMAKE_FLAGS
138                         -DCMAKE_OSX_ARCHITECTURES:STRING=${OSX_ARCHITECTURES}
139                         -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${OSX_DEPLOYMENT_TARGET}
140                         -DCMAKE_OSX_SYSROOT:PATH=${OSX_SYSROOT}
141                 )
142         else()
143                 set(PLATFORM_CFLAGS "-fPIC")
144                 set(PLATFORM_CXXFLAGS "-std=c++11 -fPIC")
145                 set(PLATFORM_LDFLAGS)
146                 set(PLATFORM_BUILD_TARGET)
147                 set(PLATFORM_CMAKE_FLAGS -DCMAKE_INSTALL_LIBDIR=lib)
148         endif()
149
150         if(WITH_OPTIMIZED_DEBUG)
151                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "-O2 -DNDEBUG ${PLATFORM_CFLAGS}")
152         else()
153                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "-g ${PLATFORM_CFLAGS}")
154         endif()
155         set(BLENDER_CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${PLATFORM_CFLAGS}")
156         set(BLENDER_CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG ${PLATFORM_CFLAGS}")
157         set(BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${PLATFORM_CFLAGS}")
158
159         if(WITH_OPTIMIZED_DEBUG)
160                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "-O2 -DNDEBUG ${PLATFORM_CXXFLAGS}")
161         else()
162                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "-g ${PLATFORM_CXXFLAGS}")
163         endif()
164
165         set(BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG ${PLATFORM_CXXFLAGS}")
166         set(BLENDER_CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${PLATFORM_CXXFLAGS}")
167         set(BLENDER_CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${PLATFORM_CXXFLAGS}")
168
169         set(CONFIGURE_ENV
170                 export MACOSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET} &&
171                 export CFLAGS=${PLATFORM_CFLAGS} &&
172                 export CXXFLAGS=${PLATFORM_CXXFLAGS} &&
173                 export LDFLAGS=${PLATFORM_LDFLAGS}
174         )
175         set(CONFIGURE_ENV_NO_PERL ${CONFIGURE_ENV})
176         set(CONFIGURE_COMMAND ./configure ${PLATFORM_BUILD_TARGET})
177         set(CONFIGURE_COMMAND_NO_TARGET ./configure)
178 endif()
179
180 set(DEFAULT_CMAKE_FLAGS
181         -DCMAKE_BUILD_TYPE=${BUILD_MODE}
182         -DCMAKE_C_FLAGS_DEBUG=${BLENDER_CMAKE_C_FLAGS_DEBUG}
183         -DCMAKE_C_FLAGS_MINSIZEREL=${BLENDER_CMAKE_C_FLAGS_MINSIZEREL}
184         -DCMAKE_C_FLAGS_RELEASE=${BLENDER_CMAKE_C_FLAGS_RELEASE}
185         -DCMAKE_C_FLAGS_RELWITHDEBINFO=${BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO}
186         -DCMAKE_CXX_FLAGS_DEBUG=${BLENDER_CMAKE_CXX_FLAGS_DEBUG}
187         -DCMAKE_CXX_FLAGS_MINSIZEREL=${BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL}
188         -DCMAKE_CXX_FLAGS_RELEASE=${BLENDER_CMAKE_CXX_FLAGS_RELEASE}
189         -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
190         ${PLATFORM_CMAKE_FLAGS}
191 )
192
193 if(WIN32)
194         #we need both flavors to build the thumbnail dlls
195         if(MSVC12)
196                 set(GENERATOR_32 "Visual Studio 12 2013")
197                 set(GENERATOR_64 "Visual Studio 12 2013 Win64")
198         elseif(MSVC14)
199                 set(GENERATOR_32 "Visual Studio 14 2015")
200                 set(GENERATOR_64 "Visual Studio 14 2015 Win64")
201         endif()
202 endif()
203
204
205 if(WIN32)
206         if(BUILD_MODE STREQUAL Debug)
207                 set(ZLIB_LIBRARY zlibstaticd${LIBEXT})
208         else()
209                 set(ZLIB_LIBRARY zlibstatic${LIBEXT})
210         endif()
211 else()
212         set(ZLIB_LIBRARY libz${LIBEXT})
213 endif()
214
215 if(MSVC)
216         set_property(GLOBAL PROPERTY USE_FOLDERS ON)
217 endif()
218
219 set(CMAKE_INSTALL_MESSAGE LAZY)