2dcf653db43fba2108020f9a18898fdd2e6a1a42
[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 set(MAKE_THREADS 1 CACHE STRING "Number of threads to run make with")
24
25 if(NOT BUILD_MODE)
26         set(BUILD_MODE "Release")
27         message(STATUS "Build type not specified: defaulting to a release build.")
28 endif()
29 message("BuildMode = ${BUILD_MODE}")
30
31 if(BUILD_MODE STREQUAL "Debug")
32         set(LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/Debug)
33 else(BUILD_MODE STREQUAL "Debug")
34         set(LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/Release)
35 endif()
36
37 option(DOWNLOAD_DIR "Path for downloaded files" ${CMAKE_CURRENT_SOURCE_DIR}/downloads)
38 file(TO_CMAKE_PATH ${DOWNLOAD_DIR} DOWNLOAD_DIR)
39 set(PATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/patches)
40 set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/build)
41
42 message("LIBDIR = ${LIBDIR}")
43 message("DOWNLOAD_DIR = ${DOWNLOAD_DIR}")
44 message("PATCH_DIR = ${PATCH_DIR}")
45 message("BUILD_DIR = ${BUILD_DIR}")
46
47 if(WIN32)
48         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
49                 set(PATCH_CMD ${DOWNLOAD_DIR}/mingw/mingw64/msys/1.0/bin/patch.exe)
50         else()
51                 set(PATCH_CMD ${DOWNLOAD_DIR}/mingw/mingw32/msys/1.0/bin/patch.exe)
52         endif()
53         set(LIBEXT ".lib")
54         set(LIBPREFIX "")
55
56         # For OIIO and OSL
57         set(COMMON_DEFINES /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS)
58
59         # TODO FIXME highly MSVC specific
60         if(WITH_OPTIMIZED_DEBUG)
61                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "/MTd /O2 /Ob2 /DNDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
62         else()
63                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1 /D_DEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
64         endif()
65         set(BLENDER_CMAKE_C_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
66         set(BLENDER_CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
67         set(BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D NDEBUG /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
68
69         if(WITH_OPTIMIZED_DEBUG)
70                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "/MTd /O2 /Ob2 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
71         else()
72                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /D PLATFORM_WINDOWS /MTd /Zi /Ob0 /Od /RTC1 /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
73         endif()
74         set(BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG  /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
75         set(BLENDER_CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
76         set(BLENDER_CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D NDEBUG /D PLATFORM_WINDOWS /DPSAPI_VERSION=1 /DOIIO_STATIC_BUILD /DTINYFORMAT_ALLOW_WCHAR_STRINGS")
77
78         set(PLATFORM_FLAGS)
79         set(PLATFORM_CXX_FLAGS)
80         set(PLATFORM_CMAKE_FLAGS)
81
82         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
83                 set(MINGW_PATH ${DOWNLOAD_DIR}/mingw/mingw64)
84                 set(MINGW_SHELL ming64sh.cmd)
85                 set(PERL_SHELL ${DOWNLOAD_DIR}/perl/portableshell.bat)
86                 set(MINGW_HOST x86_64-w64-mingw32)
87         else()
88                 set(MINGW_PATH ${DOWNLOAD_DIR}/mingw/mingw32)
89                 set(MINGW_SHELL ming32sh.cmd)
90                 set(PERL_SHELL ${DOWNLOAD_DIR}/perl32/portableshell.bat)
91                 set(MINGW_HOST i686-w64-mingw32)
92         endif()
93
94         set(CONFIGURE_ENV
95                 cd ${MINGW_PATH} &&
96                 call ${MINGW_SHELL} &&
97                 call ${PERL_SHELL} &&
98                 set path &&
99                 set CFLAGS=-g &&
100                 set LDFLAGS=-Wl,--as-needed -static-libgcc
101         )
102
103         set(CONFIGURE_ENV_NO_PERL
104                 cd ${MINGW_PATH} &&
105                 call ${MINGW_SHELL} &&
106                 set path &&
107                 set CFLAGS=-g &&
108                 set LDFLAGS=-Wl,--as-needed -static-libgcc
109         )
110
111         set(CONFIGURE_COMMAND sh ./configure)
112         set(CONFIGURE_COMMAND_NO_TARGET ${CONFIGURE_COMMAND})
113 else()
114         set(PATCH_CMD patch)
115         set(LIBEXT ".a")
116         set(LIBPREFIX "lib")
117
118         if(APPLE)
119                 # Let's get the current Xcode dir, to support xcode-select
120                 execute_process(
121                         COMMAND xcode-select --print-path
122                         OUTPUT_VARIABLE XCODE_DEV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE
123                 )
124                 set(OSX_ARCHITECTURES x86_64)
125                 set(OSX_DEPLOYMENT_TARGET 10.9)
126                 set(OSX_SDK_VERSION 10.12)
127                 set(OSX_SYSROOT ${XCODE_DEV_PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk)
128
129                 set(PLATFORM_CFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET}")
130                 set(PLATFORM_CXXFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET} -std=c++11 -stdlib=libc++")
131                 set(PLATFORM_LDFLAGS "-isysroot ${OSX_SYSROOT} -mmacosx-version-min=${OSX_DEPLOYMENT_TARGET}")
132                 set(PLATFORM_BUILD_TARGET --build=x86_64-apple-darwin13.0.0) # OS X 10.9
133                 set(PLATFORM_CMAKE_FLAGS
134                         -DCMAKE_OSX_ARCHITECTURES:STRING=${OSX_ARCHITECTURES}
135                         -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${OSX_DEPLOYMENT_TARGET}
136                         -DCMAKE_OSX_SYSROOT:PATH=${OSX_SYSROOT}
137                 )
138         else()
139                 set(PLATFORM_CFLAGS "-fPIC")
140                 set(PLATFORM_CXXFLAGS "-std=c++11 -fPIC")
141                 set(PLATFORM_LDFLAGS)
142                 set(PLATFORM_BUILD_TARGET)
143                 set(PLATFORM_CMAKE_FLAGS)
144         endif()
145
146         if(WITH_OPTIMIZED_DEBUG)
147                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "-O2 -DNDEBUG")
148         else()
149                 set(BLENDER_CMAKE_C_FLAGS_DEBUG "-g")
150         endif()
151         set(BLENDER_CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
152         set(BLENDER_CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
153         set(BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
154
155         if(WITH_OPTIMIZED_DEBUG)
156                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "-O2 -DNDEBUG ${PLATFORM_CXXFLAGS}")
157         else()
158                 set(BLENDER_CMAKE_CXX_FLAGS_DEBUG "-g ${PLATFORM_CXXFLAGS}")
159         endif()
160
161         set(BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG ${PLATFORM_CXXFLAGS}")
162         set(BLENDER_CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${PLATFORM_CXXFLAGS}")
163         set(BLENDER_CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${PLATFORM_CXXFLAGS}")
164
165         set(CONFIGURE_ENV
166                 export MACOSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET} &&
167                 export CFLAGS=${PLATFORM_CFLAGS} &&
168                 export CXXFLAGS=${PLATFORM_CXXFLAGS} &&
169                 export LDFLAGS=${PLATFORM_LDFLAGS}
170         )
171         set(CONFIGURE_ENV_NO_PERL ${CONFIGURE_ENV})
172         set(CONFIGURE_COMMAND ./configure ${PLATFORM_BUILD_TARGET})
173         set(CONFIGURE_COMMAND_NO_TARGET ./configure)
174 endif()
175
176 set(DEFAULT_CMAKE_FLAGS
177         -DCMAKE_BUILD_TYPE=${BUILD_MODE}
178         -DCMAKE_C_FLAGS_DEBUG=${BLENDER_CMAKE_C_FLAGS_DEBUG}
179         -DCMAKE_C_FLAGS_MINSIZEREL=${BLENDER_CMAKE_C_FLAGS_MINSIZEREL}
180         -DCMAKE_C_FLAGS_RELEASE=${BLENDER_CMAKE_C_FLAGS_RELEASE}
181         -DCMAKE_C_FLAGS_RELWITHDEBINFO=${BLENDER_CMAKE_C_FLAGS_RELWITHDEBINFO}
182         -DCMAKE_CXX_FLAGS_DEBUG=${BLENDER_CMAKE_CXX_FLAGS_DEBUG}
183         -DCMAKE_CXX_FLAGS_MINSIZEREL=${BLENDER_CMAKE_CXX_FLAGS_MINSIZEREL}
184         -DCMAKE_CXX_FLAGS_RELEASE=${BLENDER_CMAKE_CXX_FLAGS_RELEASE}
185         -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
186         ${PLATFORM_CMAKE_FLAGS}
187 )
188
189 if(WIN32)
190         #we need both flavors to build the thumbnail dlls
191         if(MSVC12)
192                 set(GENERATOR_32 "Visual Studio 12 2013")
193                 set(GENERATOR_64 "Visual Studio 12 2013 Win64")
194         elseif(MSVC14)
195                 set(GENERATOR_32 "Visual Studio 14 2015")
196                 set(GENERATOR_64 "Visual Studio 14 2015 Win64")
197         endif()
198 endif()
199
200
201 if(WIN32)
202         set(ZLIB_LIBRARY zlibstatic${LIBEXT})
203 else()
204         set(ZLIB_LIBRARY libz${LIBEXT})
205 endif()
206
207 if(MSVC)
208         set_property(GLOBAL PROPERTY USE_FOLDERS ON)
209 endif()
210
211 set(CMAKE_INSTALL_MESSAGE LAZY)