From 4726740e4210e70b1baa336f4ac0219d3c044e1a Mon Sep 17 00:00:00 2001 From: PSZ Date: Sun, 25 Feb 2024 18:53:34 +0800 Subject: [PATCH] fix the link error of raylib_opengl_interop and rlgl_standalone, and the error of un-removed cache in AddIfFlagCompiles.cmake --- cmake/AddIfFlagCompiles.cmake | 3 +++ cmake/CompilerFlags.cmake | 6 ++++++ examples/CMakeLists.txt | 3 +++ examples/others/raylib_opengl_interop.c | 3 +++ 4 files changed, 15 insertions(+) diff --git a/cmake/AddIfFlagCompiles.cmake b/cmake/AddIfFlagCompiles.cmake index 403607b57..6eae242ea 100644 --- a/cmake/AddIfFlagCompiles.cmake +++ b/cmake/AddIfFlagCompiles.cmake @@ -9,4 +9,7 @@ function(add_if_flag_compiles flag) set(outcome "compiles") endif() message(STATUS "Testing if ${flag} can be used -- ${outcome}") + # It must be manually removed from the cache; otherwise, the check won't be re-evalated + # https://cmake.org/cmake/help/latest/module/CheckCCompilerFlag.html + unset(COMPILER_HAS_THOSE_TOGGLES CACHE) endfunction() diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 970462c8b..651f6e4f1 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -11,6 +11,12 @@ add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS) # Allows some casting of pointers without generating a warning add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS) +# Set the charset of input files and executable files as utf-8 +# Since the default charset of MSVC is not utf-8 +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + add_if_flag_compiles(-utf-8 CMAKE_C_FLAGS) +endif() + if (ENABLE_MSAN AND ENABLE_ASAN) # MSAN and ASAN both work on memory - ASAN does more things MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3bcdc19f0..c93c6b911 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -142,5 +142,8 @@ foreach (example_source ${example_sources}) endif () endforeach () +# Need glfw implemention for glfw3.h +target_sources(rlgl_standalone PRIVATE ${CMAKE_SOURCE_DIR}/src/rglfw.c) + # Copy all of the resource files to the destination file(COPY ${example_resources} DESTINATION "resources/") diff --git a/examples/others/raylib_opengl_interop.c b/examples/others/raylib_opengl_interop.c index 33a58a227..0947bc96f 100644 --- a/examples/others/raylib_opengl_interop.c +++ b/examples/others/raylib_opengl_interop.c @@ -38,6 +38,9 @@ #include // OpenGL 3 library for OSX #include // OpenGL 3 extensions library for OSX #else + #if defined(_WIN32) && defined(_MSC_VER) + #define GLAD_IMPLEMENTATION // Need self-implementation for MSVC + #endif #include "glad.h" // Required for: OpenGL functionality #endif #define GLSL_VERSION 330