Procházet zdrojové kódy

CMake: Generate config.h from CMakeOptions.txt

I would have liked config.h to be selected by include dir configuration,
but this way is less intrusive.
Ahmad Fatoum před 7 roky
rodič
revize
1dbce35247
5 změnil soubory, kde provedl 151 přidání a 15 odebrání
  1. 7 3
      src/CMakeLists.txt
  2. 61 1
      src/CMakeOptions.txt
  3. 6 2
      src/config.h
  4. 74 0
      src/config.h.in
  5. 3 9
      utils.cmake

+ 7 - 3
src/CMakeLists.txt

@@ -1,22 +1,26 @@
 # Setup the project and settings
 project(raylib)
-include("../utils.cmake")
 include(GNUInstallDirs)
 
 set(PROJECT_VERSION 1.9.4)
 set(API_VERSION 1)
 set(RAYLIB raylib)    # Name of the generated library
 
+include("CMakeOptions.txt")
+configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h)
+include_directories(${CMAKE_BINARY_DIR})
+
+include("../utils.cmake")
+
 # Get the sources together
 file(GLOB raylib_sources *.c)
+
 if(glfw3_FOUND)
   list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c)
 else()
   include_directories(external/glfw/include)
 endif()
 
-include("CMakeOptions.txt")
-
 if(USE_AUDIO)
   file(GLOB stb_vorbis external/stb_vorbis.c)
   file(GLOB mini_al external/mini_al.c ${stb_vorbis})

+ 61 - 1
src/CMakeOptions.txt

@@ -1,11 +1,19 @@
 ### Config options ###
+include(CMakeDependentOption)
 
 # Shared library is always PIC. Static library should be PIC too if linked into a shared library
 option(WITH_PIC "Compile static library as position-independent code" OFF)
 option(SHARED "Build raylib as a dynamic library" OFF)
 option(STATIC "Build raylib as a static library" ON)
-option(USE_AUDIO "Build raylib with audio module" ON)
 option(MACOS_FATLIB  "Build fat library for both i386 and x86_64 on macOS" ON)
+option(USE_AUDIO "Build raylib with audio module" ON)
+cmake_dependent_option(USE_OPENAL_BACKEND "Link raylib with openAL instead of mini-al" OFF "USE_AUDIO" OFF)
+set(USE_EXTERNAL_GLFW  OFF  CACHE STRING "Link raylib against system GLFW instead of embedded one")
+set_property(CACHE USE_EXTERNAL_GLFW PROPERTY STRINGS ON OFF IF_POSSIBLE)
+if(UNIX AND NOT APPLE)
+    option(USE_WAYLAND "Use Wayland for window creation" OFF)
+endif()
+
 
 set(PLATFORM "Desktop" CACHE STRING "Platform to build for.")
 set_property(CACHE PLATFORM PROPERTY STRINGS "Desktop" "Web" "Android" "Raspberry Pi")
@@ -13,6 +21,58 @@ set_property(CACHE PLATFORM PROPERTY STRINGS "Desktop" "Web" "Android" "Raspberr
 set(OPENGL_VERSION "3.3" CACHE STRING "OpenGL Version to build raylib with")
 set_property(CACHE OPENGL_VERSION PROPERTY STRINGS "3.3" "2.1" "1.1" "ES 2.0")
 
+# core.c
+option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" ON)
+option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON)
+option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON)
+option(SUPPORT_GIF_RECORDING "Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()" ON)
+option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag" ON)
+option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON)
+
+# rlgl.c
+option(SUPPORT_VR_SIMULATOR "Support VR simulation functionality (stereo rendering)" ON)
+option(SUPPORT_DISTORTION_SHADER "Include stereo rendering distortion shader (shader_distortion.h)" ON)
+
+# models.c
+option(SUPPORT_FILEFORMAT_OBJ "Support loading OBJ file format" ON)
+option(SUPPORT_FILEFORMAT_MTL "Support loading MTL file format" ON)
+option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON)
+
+# textures.c
+option(SUPPORT_IMAGE_GENERATION "Support proedural image generation functionality (gradient, spot, perlin-noise, cellular)" ON)
+option(SUPPORT_FILEFORMAT_PNG "Support loading PNG as textures" ON)
+option(SUPPORT_FILEFORMAT_DDS "Support loading DDS as textures" ON)
+option(SUPPORT_FILEFORMAT_HDR "Support loading HDR as textures" ON)
+option(SUPPORT_FILEFORMAT_KTX "Support loading KTX as textures" ON)
+option(SUPPORT_FILEFORMAT_ASTC "Support loading ASTC as  textures" ON)
+option(SUPPORT_FILEFORMAT_BMP "Support loading BMP as textures" OFF)
+option(SUPPORT_FILEFORMAT_TGA "Support loading TGA as textures" OFF)
+option(SUPPORT_FILEFORMAT_JPG "Support loading JPG as textures" OFF)
+option(SUPPORT_FILEFORMAT_GIF "Support loading GIF as textures" OFF)
+option(SUPPORT_FILEFORMAT_PSD "Support loading PSD as textures" OFF)
+option(SUPPORT_FILEFORMAT_PKM "Support loading PKM as textures" OFF)
+option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" OFF)
+
+# audio.c
+option(SUPPORT_FILEFORMAT_WAV  "Support loading WAV for sound" ON)
+option(SUPPORT_FILEFORMAT_OGG  "Support loading OGG for sound" ON)
+option(SUPPORT_FILEFORMAT_XM   "Support loading XM for sound" ON)
+option(SUPPORT_FILEFORMAT_MOD  "Support loading MOD for sound" ON)
+option(SUPPORT_FILEFORMAT_FLAC "Support loading FLAC for sound" OFF)
+
+# shapes.c
+option(USE_DEFAULT_FONT_TEXTURE "Draw rectangle shapes using font texture white character instead of default white texture. Allows drawing rectangles and text with a single draw call, very useful for GUI systems!" ON)
+
+# utils.c
+option(SUPPORT_SAVE_PNG "Support saving image data in PNG file format" ON)
+option(SUPPORT_SAVE_BMP "Support saving image data in BMP file format" OFF)
+option(SUPPORT_TRACELOG "Show TraceLog() output messages. NOTE: By default LOG_DEBUG traces not shown" ON)
+
+option(SUPPORT_FILEFORMAT_FNT "Support loading fonts in FNT format" ON)
+option(SUPPORT_FILEFORMAT_TTF "Support loading font in TTF format" ON)
+
+option(SUPPORT_IMAGE_MANIPULATION "Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT()" ON)
+
 if(NOT (STATIC OR SHARED))
   message(FATAL_ERROR "Nothing to do if both -DSHARED=OFF and -DSTATIC=OFF...")
 endif()

+ 6 - 2
src/config.h

@@ -1,5 +1,7 @@
-/* Edit to control what features raylib is compiled with. */
-
+/* Edit to control what features Makefile'd raylib is compiled with. */
+#ifdef RAYLIB_CMAKE /* Edit CMakeOptions.txt for CMake instead! */
+#include "cmake/config.h"
+#else
 // text.c
 /* Default font is loaded on window initialization to be available for the user to render simple text. NOTE: If enabled, uses external module functions to load default raylib font (module: text) */
 #define SUPPORT_DEFAULT_FONT 1
@@ -72,3 +74,5 @@
 #define SUPPORT_SAVE_PNG 1
 /* Support saving image data as PMP fileformat. NOTE: Requires stb_image_write library */
 /* #undef SUPPORT_SAVE_BMP */
+
+#endif

+ 74 - 0
src/config.h.in

@@ -0,0 +1,74 @@
+/* config.h.in */
+
+// text.c
+/* Default font is loaded on window initialization to be available for the user to render simple text. NOTE: If enabled, uses external module functions to load default raylib font (module: text) */
+#cmakedefine SUPPORT_DEFAULT_FONT 1
+/* Selected desired fileformats to be supported for loading.  */
+#cmakedefine SUPPORT_FILEFORMAT_FNT 1
+#cmakedefine SUPPORT_FILEFORMAT_TTF 1
+
+// textures.c
+/* Selecte desired fileformats to be supported for image data loading. */
+#cmakedefine SUPPORT_FILEFORMAT_PNG 1
+#cmakedefine SUPPORT_FILEFORMAT_DDS 1
+#cmakedefine SUPPORT_FILEFORMAT_HDR 1
+#cmakedefine SUPPORT_FILEFORMAT_KTX 1
+#cmakedefine SUPPORT_FILEFORMAT_ASTC 1
+#cmakedefine SUPPORT_FILEFORMAT_BMP 1
+#cmakedefine SUPPORT_FILEFORMAT_TGA 1
+#cmakedefine SUPPORT_FILEFORMAT_JPG 1
+#cmakedefine SUPPORT_FILEFORMAT_GIF 1
+#cmakedefine SUPPORT_FILEFORMAT_PSD 1
+#cmakedefine SUPPORT_FILEFORMAT_PKM 1
+#cmakedefine SUPPORT_FILEFORMAT_PVR 1
+
+/* Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT() */
+#cmakedefine SUPPORT_IMAGE_MANIPULATION 1
+
+/* Support proedural image generation functionality (gradient, spot, perlin-noise, cellular) */
+#cmakedefine SUPPORT_IMAGE_GENERATION 1
+
+// rlgl.c
+/* Support VR simulation functionality (stereo rendering) */
+#cmakedefine SUPPORT_VR_SIMULATOR 1
+/* Include stereo rendering distortion shader (shader_distortion.h) */
+#cmakedefine SUPPORT_DISTORTION_SHADER 1
+
+// core.c
+/* Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital */
+#cmakedefine SUPPORT_CAMERA_SYSTEM 1
+/* Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag */
+#cmakedefine SUPPORT_GESTURES_SYSTEM 1
+/* Mouse gestures are directly mapped like touches and processed by gestures system. */
+#cmakedefine SUPPORT_MOUSE_GESTURES 1
+/* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used */
+#cmakedefine SUPPORT_BUSY_WAIT_LOOP 1
+/* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() */
+#cmakedefine SUPPORT_GIF_RECORDING 1
+
+// audio.c
+/* Desired fileformats to be supported for loading. */
+#cmakedefine SUPPORT_FILEFORMAT_WAV 1
+#cmakedefine SUPPORT_FILEFORMAT_OGG 1
+#cmakedefine SUPPORT_FILEFORMAT_XM 1
+#cmakedefine SUPPORT_FILEFORMAT_MOD 1
+#cmakedefine SUPPORT_FILEFORMAT_FLAC 1
+
+// models.c
+/* Selected desired fileformats to be supported for loading. */
+#cmakedefine SUPPORT_FILEFORMAT_OBJ 1
+#cmakedefine SUPPORT_FILEFORMAT_MTL 1
+
+/* Support procedural mesh generation functions, uses external par_shapes.h library
+ * NOTE: Some generated meshes DO NOT include generated texture coordinates
+ */
+#cmakedefine SUPPORT_MESH_GENERATION 1
+
+// utils.c
+/* Show TraceLog() output messages. NOTE: By default LOG_DEBUG traces not shown */
+#cmakedefine SUPPORT_TRACELOG 1
+
+/* Support saving image data as PNG fileformat. NOTE: Requires stb_image_write library */
+#cmakedefine SUPPORT_SAVE_PNG 1
+/* Support saving image data as PMP fileformat. NOTE: Requires stb_image_write library */
+#cmakedefine SUPPORT_SAVE_BMP 1

+ 3 - 9
utils.cmake

@@ -1,12 +1,7 @@
 # All sorts of things that we need cross project
 cmake_minimum_required(VERSION 2.8.0)
 
-set(USE_EXTERNAL_GLFW  OFF  CACHE STRING "Link raylib against system GLFW instead of embedded one")
-set_property(CACHE USE_EXTERNAL_GLFW PROPERTY STRINGS ON OFF IF_POSSIBLE)
-
-if(UNIX AND NOT APPLE)
-    option(USE_WAYLAND "Use Wayland for window creation" OFF)
-endif()
+add_definitions("-DRAYLIB_CMAKE=1")
 
 # Linking for OS X -framework options
 # Will do nothing on other OSes
@@ -29,7 +24,7 @@ else()
   endif()
 
   find_library(pthread NAMES pthread)
-  find_package(OpenGL)
+  find_package(OpenGL QUIET)
   if ("${OPENGL_LIBRARIES}" STREQUAL "")
     if(NOT USE_WAYLAND)
       # CFLAGS=-m32 cmake on Linux fails for some reason, so fallback to hardcoding
@@ -69,7 +64,7 @@ endif()
 if(USE_EXTERNAL_GLFW STREQUAL "ON")
     find_package(glfw3 3.2.1 REQUIRED)
 elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE")
-    find_package(glfw3 3.2.1)
+    find_package(glfw3 3.2.1 QUIET)
 endif()
 if (glfw3_FOUND)
   set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw)
@@ -114,4 +109,3 @@ function(link_libraries_to_executable executable)
     target_link_libraries(${executable} raylib ${__PKG_CONFIG_LIBS_PRIVATE})
   endif()
 endfunction()
-