CMake: Avoid call of find_package(Git) for every compile with buildinfo enabled
[blender.git] / CMakeLists.txt
index 1603f1f98b2b070a53291b2fab4ceb76b0abf582..b24945d7ebdf8086e31358cb5bcaab6145e75491 100644 (file)
@@ -467,7 +467,9 @@ if(WIN32)
        set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
 endif()
 
-# Experimental support of C++11
+# Experimental support of C11 and C++11
+option(WITH_C11 "Build with C11 standard enabled, for development use only!" OFF)
+mark_as_advanced(WITH_C11)
 option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF)
 mark_as_advanced(WITH_CPP11)
 
@@ -501,40 +503,23 @@ endif()
 # Apple
 
 if(APPLE)
-       if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
-               cmake_minimum_required(VERSION 2.8.8)
-               cmake_policy(VERSION 2.8.8)
-       endif()
+       # require newer cmake on osx because of version handling,
+       # older cmake cannot handle 2 digit subversion!
+       cmake_minimum_required(VERSION 3.0.0)
 
        if(NOT CMAKE_OSX_ARCHITECTURES)
                set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
                "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
                FORCE)
        endif()
-       
-       execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
-       if(${MAC_SYS} MATCHES 15)
-               set(OSX_SYSTEM 10.11)
-               # throw an error here, older cmake cannot handle 2 digit subversion!
-               cmake_minimum_required(VERSION 3.0.0)
-       elseif(${MAC_SYS} MATCHES 14)
-               set(OSX_SYSTEM 10.10)
-               # throw an error here, older cmake cannot handle 2 digit subversion!
-               cmake_minimum_required(VERSION 3.0.0)
-       elseif(${MAC_SYS} MATCHES 13)
-               set(OSX_SYSTEM 10.9)
-       elseif(${MAC_SYS} MATCHES 12)
-               set(OSX_SYSTEM 10.8)
-       elseif(${MAC_SYS} MATCHES 11)
-               set(OSX_SYSTEM 10.7)
-       elseif(${MAC_SYS} MATCHES 10)
-               set(OSX_SYSTEM 10.6)
-       elseif(${MAC_SYS} MATCHES 9)
-               set(OSX_SYSTEM 10.5)
-       else()
-               set(OSX_SYSTEM unsupported)
+
+       if(NOT DEFINED OSX_SYSTEM)
+               execute_process(
+                       COMMAND xcodebuild -version -sdk macosx SDKVersion
+                       OUTPUT_VARIABLE OSX_SYSTEM
+                       OUTPUT_STRIP_TRAILING_WHITESPACE)
        endif()
-       
+
        # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
        # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
        execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -719,6 +704,13 @@ else()
        set(COMPILER_SSE2_FLAG)
 endif()
 
+if(WITH_BUILDINFO)
+       find_package(Git)
+       if(NOT GIT_FOUND)
+               set(WITH_BUILDINFO OFF)
+       endif()
+endif()
+
 TEST_SHARED_PTR_SUPPORT()
 TEST_UNORDERED_MAP_SUPPORT()
 
@@ -1242,6 +1234,14 @@ elseif(WIN32)
        add_definitions(-DWIN32)
 
        if(MSVC)
+               # Minimum MSVC Version
+               set(_min_ver "18.0.31101")
+               if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
+                       message(FATAL_ERROR
+                               "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
+                               "found (${CMAKE_CXX_COMPILER_VERSION})")
+               endif()
+               unset(_min_ver)
 
                # needed for some MSVC installations
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
@@ -1288,6 +1288,10 @@ elseif(WIN32)
 
                set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
 
+               # Ignore meaningless for us linker warnings.
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
+               set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
+
                # MSVC only, Mingw doesnt need
                if(CMAKE_CL_64)
                        set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
@@ -1316,7 +1320,10 @@ elseif(WIN32)
                                set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
                        endif()
                else()
-                       message(STATUS using LIBDIR  ${LIBDIR})
+                       message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
+               endif()
+               if(NOT EXISTS "${LIBDIR}/")
+                       message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
                endif()
 
                # Add each of our libraries to our cmake_prefix_path so find_package() could work
@@ -1572,11 +1579,12 @@ elseif(WIN32)
                endif()
 
                if(WITH_OPENVDB)
+                       set(BLOSC_LIBRARIES ${LIBDIR}/blosc/lib/libblosc.lib)
                        set(TBB_LIBRARIES ${LIBDIR}/tbb/lib/tbb.lib)
                        set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
                        set(OPENVDB ${LIBDIR}/openvdb)
                        set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
-                       set(OPENVDB_LIBRARIES openvdb ${TBB_LIBRARIES})
+                       set(OPENVDB_LIBRARIES openvdb ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
                        set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
                endif()
 
@@ -1635,18 +1643,25 @@ elseif(WIN32)
                        " 
                        WITH_MINGW64)
                
-               if(WITH_MINGW64)
-                       message(STATUS "Compiling for 64 bit with MinGW-w64.")
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
-               else()
-                       message(STATUS "Compiling for 32 bit with MinGW-w32.")
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
-                       
-                       if(WITH_RAYOPTIMIZATION)
-                               message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
+               if(NOT DEFINED LIBDIR)
+                       if(WITH_MINGW64)
+                               message(STATUS "Compiling for 64 bit with MinGW-w64.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
+                       else()
+                               message(STATUS "Compiling for 32 bit with MinGW-w32.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
+
+                               if(WITH_RAYOPTIMIZATION)
+                                       message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
+                               endif()
                        endif()
+               else()
+                       message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
                endif()
-               
+               if(NOT EXISTS "${LIBDIR}/")
+                       message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
+               endif()
+
                list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp)
 
                if(WITH_INPUT_IME)
@@ -1921,16 +1936,22 @@ elseif(APPLE)
                set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
        endif()
 
-       if(WITH_LIBS10.5)
-               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
-       else()
-               if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
+       if(NOT DEFINED LIBDIR)
+               if(WITH_LIBS10.5)
+                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
                else()
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
+                       if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
+                       else()
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
+                       endif()
                endif()
+       else()
+               message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
+       endif()
+       if(NOT EXISTS "${LIBDIR}/")
+               message(FATAL_ERROR "Mac OSX requires pre-compiled libs at: '${LIBDIR}'")
        endif()
-
 
        if(WITH_OPENAL)
                find_package(OpenAL)
@@ -2172,7 +2193,7 @@ elseif(APPLE)
                set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
                set(TBB_INCLUDE_DIRS ${LIBDIR}/tbb/include)
                set(TBB_LIBRARIES ${LIBDIR}/tbb/lib/libtbb.a)
-               set(OPENVDB_LIBRARIES openvdb ${TBB_LIBRARIES})
+               set(OPENVDB_LIBRARIES openvdb blosc ${TBB_LIBRARIES})
                set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
                set(OPENVDB_DEFINITIONS)
        endif()
@@ -2281,12 +2302,6 @@ endif()
 #-----------------------------------------------------------------------------
 # Common.
 
-if(APPLE OR WIN32)
-       if(NOT EXISTS "${LIBDIR}/")
-               message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
-       endif()
-endif()
-
 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
        message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
 endif()
@@ -2880,7 +2895,11 @@ endif()
 # Visual Studio has all standards it supports available by default
 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
        # Use C99 + GNU extensions, works with GCC, Clang, ICC
-       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+       if(WITH_C11)
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
+       else()
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+       endif()
 endif()
 
 # Include warnings first, so its possible to disable them with user defined flags