CMake: De-duplicate checks around unordered maps and shared pointer
[blender.git] / CMakeLists.txt
index 26e0a3f13799a823a522387e2fea691e31e00341..e91f4b503a23b51d88eac6c001c41c4d4239e23f 100644 (file)
@@ -362,7 +362,6 @@ if(WIN32)
 endif()
 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
 option(WITH_RAYOPTIMIZATION    "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
-option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
 if(UNIX AND NOT APPLE)
        option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
        option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
@@ -400,6 +399,9 @@ mark_as_advanced(WITH_CYCLES_LOGGING)
 mark_as_advanced(WITH_CYCLES_DEBUG)
 mark_as_advanced(WITH_CYCLES_WERROR)
 
+option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
+mark_as_advanced(WITH_CUDA_DYNLOAD)
+
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
 if(APPLE)
@@ -470,7 +472,7 @@ if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
        set(WITH_SYSTEM_GLEW OFF)
 endif()
 
-if(MSVC)
+if(WIN32)
        getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
        set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
 endif()
@@ -493,7 +495,7 @@ option_defaults_clear()
 # By default we want to install to the directory we are compiling our executables
 # unless specified otherwise, which we currently do not allow
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-       if(MSVC)
+       if(WIN32)
                set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
        elseif(APPLE)
                set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
@@ -729,6 +731,9 @@ if(HAVE_STDBOOL_H)
        add_definitions(-DHAVE_STDBOOL_H)
 endif()
 
+TEST_SHARED_PTR_SUPPORT()
+TEST_UNORDERED_MAP_SUPPORT()
+
 if(WITH_AUDASPACE)
        if(WITH_SYSTEM_AUDASPACE)
                set(AUDASPACE_DEFINITIONS
@@ -1292,13 +1297,22 @@ elseif(WIN32)
                set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
                if(NOT DEFINED LIBDIR)
+
                        # Setup 64bit and 64bit windows systems
                        if(CMAKE_CL_64)
                                message(STATUS "64 bit compiler detected.")
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64_vc12)
+                               set(LIBDIR_BASE "win64")
                        else()
                                message(STATUS "32 bit compiler detected.")
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows_vc12)
+                               set(LIBDIR_BASE "windows")
+                       endif()
+
+                       if(MSVC_VERSION EQUAL 1900)
+                               message(STATUS "Visual Studio 2015 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
+                       else()
+                               message(STATUS "Visual Studio 2013 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
                        endif()
                else()
                        message(STATUS using LIBDIR  ${LIBDIR})
@@ -1330,9 +1344,7 @@ elseif(WIN32)
                        set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
                endif()
 
-               if(MSVC)
-                       set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
-               endif()
+               set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
                find_package(jpeg REQUIRED)
 
                set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
@@ -1480,8 +1492,8 @@ elseif(WIN32)
                                        set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
                                else()
                                        set(BOOST_LIBPATH ${BOOST}/lib)
-                                       set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
-                                       set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
+                                       set(BOOST_POSTFIX "vc140-mt-s-1_60.lib")
+                                       set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-1_60.lib")
                                endif()
                                set(BOOST_LIBRARIES
                                        optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
@@ -1577,8 +1589,13 @@ elseif(WIN32)
                if(WITH_SDL)
                        set(SDL ${LIBDIR}/sdl)
                        set(SDL_INCLUDE_DIR ${SDL}/include)
-                       set(SDL_LIBRARY SDL2)
                        set(SDL_LIBPATH ${SDL}/lib)
+                       # MinGW TODO: Update MinGW to SDL2
+                       if(NOT CMAKE_COMPILER_IS_GNUCC)
+                               set(SDL_LIBRARY SDL2)
+                       else()
+                               set(SDL_LIBRARY SDL)
+                       endif()
                endif()
 
                # Audio IO
@@ -1608,12 +1625,7 @@ elseif(WIN32)
                
                if(WITH_MINGW64)
                        message(STATUS "Compiling for 64 bit with MinGW-w64.")
-                       execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
-                       if(GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64_gcc49)
-                       else()
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
-                       endif()
+                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
                else()
                        message(STATUS "Compiling for 32 bit with MinGW-w32.")
                        set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
@@ -2463,7 +2475,7 @@ if(WITH_OPENMP)
                        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
                else()
                        # Typically avoid adding flags as defines but we can't
-                       # ass OpenMP flags to the linker for static builds, meaning
+                       # pass OpenMP flags to the linker for static builds, meaning
                        # we can't add any OpenMP related flags to CFLAGS variables
                        # since they're passed to the linker as well.
                        add_definitions("${OpenMP_C_FLAGS}")
@@ -2574,6 +2586,59 @@ if(WITH_PYTHON_MODULE)
        add_definitions(-DPy_ENABLE_SHARED)
 endif()
 
+#-----------------------------------------------------------------------------
+# Configure GLog/GFlags
+
+if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
+       set(GLOG_DEFINES
+               -DGOOGLE_GLOG_DLL_DECL=
+       )
+
+       set(GFLAGS_DEFINES
+               -DGFLAGS_DLL_DEFINE_FLAG=
+               -DGFLAGS_DLL_DECLARE_FLAG=
+               -DGFLAGS_DLL_DECL=
+       )
+endif()
+
+#-----------------------------------------------------------------------------
+# Configure Ceres
+
+if(WITH_LIBMV)
+       set(CERES_DEFINES)
+
+       if(SHARED_PTR_FOUND)
+               if(SHARED_PTR_TR1_MEMORY_HEADER)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_MEMORY_HEADER)
+               endif()
+               if(SHARED_PTR_TR1_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_SHARED_PTR)
+               endif()
+       else()
+               message(FATAL_ERROR "Ceres: Unable to find shared_ptr.")
+       endif()
+
+       if(HAVE_STD_UNORDERED_MAP_HEADER)
+               if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
+               else()
+                       if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                               list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                       else()
+                               list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
+                               message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
+                       endif()
+               endif()
+       else()
+               if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_UNORDERED_MAP)
+               else()
+                       list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
+                       message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
+               endif()
+       endif()
+endif()
+
 #-----------------------------------------------------------------------------
 # Extra compile flags
 
@@ -2730,6 +2795,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
                "/w34062"  # switch statement contains 'default' but no 'case' labels
                # disable:
                "/wd4018"  # signed/unsigned mismatch
+               "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
                "/wd4065"  # switch statement contains 'default' but no 'case' labels
                "/wd4127"  # conditional expression is constant
                "/wd4181"  # qualifier applied to reference type; ignored
@@ -2844,7 +2910,9 @@ if(WITH_BLENDER OR WITH_PLAYER)
 elseif(WITH_CYCLES_STANDALONE)
        add_subdirectory(intern/cycles)
        add_subdirectory(extern/clew)
-       add_subdirectory(extern/cuew)
+       if(WITH_CUDA_DYNLOAD)
+               add_subdirectory(extern/cuew)
+       endif()
        if(NOT WITH_SYSTEM_GLEW)
                add_subdirectory(extern/glew)
        endif()
@@ -2983,9 +3051,6 @@ if(FIRST_RUN)
                info_cfg_option(WITH_GL_ANGLE)
        endif()
 
-       info_cfg_text("Other:")
-       info_cfg_option(WITH_OPENNL)
-
        # debug
        message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")