Browse Source

CMake: Allow for config-specific dtool-config vars

This makes it so some options can be toggled on a per-configuration
basis (for multi-config generators), as long as they don't affect what
targets are actually being generated.
Donny Lawrence 6 years ago
parent
commit
603e240788
2 changed files with 38 additions and 10 deletions
  1. 17 5
      dtool/Config.cmake
  2. 21 5
      dtool/LocalSetup.cmake

+ 17 - 5
dtool/Config.cmake

@@ -72,6 +72,7 @@ else()
   set(IS_NOT_DIST_BUILD True)
 endif()
 
+set(PER_CONFIG_OPTIONS)
 
 # Are we building with static or dynamic linking?
 option(BUILD_SHARED_LIBS
@@ -312,12 +313,16 @@ enables you to define the variable 'track-memory-usage' at runtime
 to help track memory leaks, and also report total memory usage on
 PStats.  There is some small overhead for having this ability
 available, even if it is unused." ${IS_DEBUG_BUILD})
+list(APPEND PER_CONFIG_OPTIONS DO_MEMORY_USAGE)
+set(DO_MEMORY_USAGE_Debug ON CACHE BOOL "")
 
 option(SIMULATE_NETWORK_DELAY
   "This option compiles in support for simulating network delay via
 the min-lag and max-lag prc variables.  It adds a tiny bit of
 overhead even when it is not activated, so it is typically enabled
 only in a development build." ${IS_DEBUG_BUILD})
+list(APPEND PER_CONFIG_OPTIONS SIMULATE_NETWORK_DELAY)
+set(SIMULATE_NETWORK_DELAY_Debug ON CACHE BOOL "")
 
 option(SUPPORT_IMMEDIATE_MODE
   "This option compiles in support for immediate-mode OpenGL
@@ -326,11 +331,15 @@ buggy drivers, and since there is a tiny bit of per-primitive
 overhead to have this option available even if it is unused, it is
 by default enabled only in a development build.  This has no effect
 on DirectX rendering." ${IS_DEBUG_BUILD})
+list(APPEND PER_CONFIG_OPTIONS SUPPORT_IMMEDIATE_MODE)
+set(SUPPORT_IMMEDIATE_MODE_Debug ON CACHE BOOL "")
 
 option(NOTIFY_DEBUG
   "Do you want to include the 'debug' and 'spam' Notify messages?
 Normally, these are stripped out when we build for release, but sometimes it's
 useful to keep them around. Turn this setting on to achieve that." ${IS_DEBUG_BUILD})
+list(APPEND PER_CONFIG_OPTIONS NOTIFY_DEBUG)
+set(NOTIFY_DEBUG_Debug ON CACHE BOOL "")
 
 option(SUPPORT_FIXED_FUNCTION
   "This option compiles in support for the fixed-function OpenGL
@@ -423,7 +432,7 @@ if(WIN32 AND IS_DEBUG_BUILD)
 else()
   set(USE_DEBUG_PYTHON OFF)
 endif()
-
+list(APPEND PER_CONFIG_OPTIONS USE_DEBUG_PYTHON)
 
 option(HAVE_VIDEO4LINUX
   "Set this to enable webcam support on Linux." ${IS_LINUX})
@@ -578,6 +587,8 @@ slightly slow down Panda for the single CPU case."
 
 # Configure debug threads
 option(DEBUG_THREADS "If on, enables debugging of thread and sync operations (i.e. mutexes, deadlocks)" ${IS_DEBUG_BUILD})
+list(APPEND PER_CONFIG_OPTIONS DEBUG_THREADS)
+set(DEBUG_THREADS_Debug ON CACHE BOOL "")
 
 option(SIMPLE_THREADS
   "If on, compile with simulated threads.  Threads, by default, use
@@ -587,7 +598,7 @@ On the other hand, compiling in this full OS-provided support can
 impose some substantial runtime overhead, making the application
 run slower on a single-CPU machine. This settings avoid the overhead,
 but still gain some of the basic functionality of threads." OFF)
-
+list(APPEND PER_CONFIG_OPTIONS SIMPLE_THREADS)
 
 option(OS_SIMPLE_THREADS
   "If on, OS threading constructs will be used to perform context switches.
@@ -596,7 +607,7 @@ normal SIMPLE_THREADS optimizations still apply, and the normal
 SIMPLE_THREADS scheduler is used to switch between threads (instead
 of the OS scheduler).  This may be more portable and more reliable,
 but it is a hybrid between user-space threads and os-provided threads." ON)
-
+list(APPEND PER_CONFIG_OPTIONS OS_SIMPLE_THREADS)
 
 ### Configure pipelining ###
 option(DO_PIPELINING "If on, compile with pipelined rendering." ON)
@@ -605,8 +616,9 @@ option(DO_PIPELINING "If on, compile with pipelined rendering." ON)
 option(COMPILE_IN_DEFAULT_FONT
   "If on, compiles in a default font, so that every TextNode will always
 have a font available without requiring the user to specify one.
-When turned off, the generated library will save a few kilobytes."
-  ${IS_NOT_MINSIZE_BUILD})
+When turned off, the generated library will save a few kilobytes." ${IS_NOT_MINSIZE_BUILD})
+list(APPEND PER_CONFIG_OPTIONS COMPILE_IN_DEFAULT_FONT)
+set(COMPILE_IN_DEFAULT_FONT_MinSizeRel OFF CACHE BOOL "")
 
 option(STDFLOAT_DOUBLE
   "Define this true to compile a special version of Panda to use a

+ 21 - 5
dtool/LocalSetup.cmake

@@ -193,12 +193,28 @@ else()
   set(intdir "${CMAKE_BUILD_TYPE}")
 endif()
 
-configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/include/dtool_config.h")
-
-# TODO: Add the ability to customize dtool_config.h based on configuration.
 if(IS_MULTICONFIG)
-  file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/$<CONFIG>/include/dtool_config.h"
-                INPUT "${PROJECT_BINARY_DIR}/include/dtool_config.h")
+  foreach(config ${CMAKE_CONFIGURATION_TYPES})
+    foreach(option ${PER_CONFIG_OPTIONS})
+      # Check for the presence of a config-specific option, and override what's
+      # in the cache if there is.
+      if(DEFINED ${option}_${config})
+        set(${option} ${${option}_${config}})
+      endif()
+    endforeach(option)
+
+    # Generate a dtool_config.h for this specific config
+    configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/${config}/include/dtool_config.h")
+
+    # unset() does not unset CACHE variables by default, just normal variables.
+    # By doing this we're reverting back to what was in the cache.
+    foreach(option ${PER_CONFIG_OPTIONS})
+      unset(${option})
+    endforeach(option)
+  endforeach(config)
+else()
+  # Just configure things like normal.
+  configure_file(dtool_config.h.in "${PROJECT_BINARY_DIR}/include/dtool_config.h")
 endif()
 
 install(FILES "${PROJECT_BINARY_DIR}/${intdir}/include/dtool_config.h"