Procházet zdrojové kódy

Minor code cleanup on handling of URHO3D_D3D11 and URHO3D_OPENGL.

Yao Wei Tjong 姚伟忠 před 10 roky
rodič
revize
377fd30e9a
2 změnil soubory, kde provedl 9 přidání a 14 odebrání
  1. 8 13
      CMake/Modules/Urho3D-CMake-common.cmake
  2. 1 1
      Docs/GettingStarted.dox

+ 8 - 13
CMake/Modules/Urho3D-CMake-common.cmake

@@ -129,17 +129,16 @@ endif ()
 if (MSVC)
     # On MSVC compiler, default to false (i.e. prefers Direct3D)
     # OpenGL can be manually enabled with -DURHO3D_OPENGL=1, but Windows graphics card drivers are usually better optimized for Direct3D
-    option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)")
-elseif (WIN32)
+    set (DEFAULT_OPENGL FALSE)
+else ()
     # On non-MSVC compiler on Windows platform, default to true to enable use of OpenGL instead of Direct3D
     # Direct3D can be manually enabled with -DURHO3D_OPENGL=0, but it is likely to fail unless the MinGW-w64 distribution is used due to dependency to Direct3D headers and libs
-    option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" TRUE)
-endif ()
-if (WIN32)
-    # On Windows platform Direct3D11 can be optionally chosen
-    # Using Direct3D11 on non-MSVC compiler may require copying and renaming Microsoft official libraries (.lib to .a), else link failures or non-functioning graphics may result
-    option (URHO3D_D3D11 "Use Direct3D11 instead of Direct3D9 (Windows platform only)")
+    set (DEFAULT_OPENGL TRUE)
 endif ()
+cmake_dependent_option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" ${DEFAULT_OPENGL} "WIN32" TRUE)      # Force the variable to TRUE when not WIN32
+# On Windows platform Direct3D11 can be optionally chosen
+# Using Direct3D11 on non-MSVC compiler may require copying and renaming Microsoft official libraries (.lib to .a), else link failures or non-functioning graphics may result
+cmake_dependent_option (URHO3D_D3D11 "Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option" FALSE "WIN32" FALSE)
 if (CMAKE_HOST_WIN32 AND NOT DEFINED URHO3D_MKLINK)
     # Test whether the host system is capable of setting up symbolic link
     execute_process (COMMAND cmd /C mklink test-link CMakeCache.txt RESULT_VARIABLE MKLINK_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
@@ -273,17 +272,13 @@ if (URHO3D_LOGGING)
     add_definitions (-DURHO3D_LOGGING)
 endif ()
 
-# If not on Windows platform, enable Unix mode for kNet library and OpenGL graphic back-end
+# If not on Windows platform, enable Unix mode for kNet library
 if (NOT WIN32)
     add_definitions (-DKNET_UNIX)
-    set (URHO3D_OPENGL 1)
 endif ()
 
 # Add definition for Direct3D11
 if (URHO3D_D3D11)
-    if (NOT WIN32)
-        message(FATAL_ERROR "Direct3D 11 can only be used on Windows platform")
-    endif ()
     set (URHO3D_OPENGL 0)
     add_definitions (-DURHO3D_D3D11)
 endif ()

+ 1 - 1
Docs/GettingStarted.dox

@@ -93,7 +93,7 @@ A number of build options can be defined when invoking the build scripts or when
 |URHO3D_TESTING       |0|Enable testing support|
 |URHO3D_TEST_TIMEOUT  |*|Number of seconds to test run the executables (when testing support is enabled only), default to 10 on Emscripten platform and 5 on other platforms|
 |URHO3D_OPENGL        |0|Use OpenGL instead of Direct3D (Windows platform only)|
-|URHO3D_D3D11         |0|Use Direct3D11 instead of Direct3D9 (Windows platform only). Overrides URHO3D_OPENGL option.|
+|URHO3D_D3D11         |0|Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option|
 |URHO3D_STATIC_RUNTIME|0|Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)|
 |URHO3D_WIN32_CONSOLE |0|Use console main() as entry point when setting up Windows executable targets (Windows platform only)|
 |URHO3D_MACOSX_BUNDLE |0|Use MACOSX_BUNDLE when setting up Mac OS X executable targets (Xcode native build only)|