options.cmake 8.6 KB

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