Skip to content

Instantly share code, notes, and snippets.

@doccaico
Created November 27, 2025 13:28
Show Gist options
  • Select an option

  • Save doccaico/812ff1820fd3246daca201adfe631325 to your computer and use it in GitHub Desktop.

Select an option

Save doccaico/812ff1820fd3246daca201adfe631325 to your computer and use it in GitHub Desktop.
Winlibs + Raylib + STC (Cmake)
cmake_minimum_required(VERSION 3.10)
project(test-winlibs C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_FLAGS "")
set(CMAKE_C_FLAGS_DEBUG "")
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_C_STANDARD_LIBRARIES "")
STRING(REPLACE
"-Wl,--major-image-version,<TARGET_VERSION_MAJOR>,--minor-image-version,<TARGET_VERSION_MINOR>"
""
CMAKE_C_LINK_EXECUTABLE
"${CMAKE_C_LINK_EXECUTABLE}"
)
STRING(REPLACE
"-Wl,--out-implib,<TARGET_IMPLIB>"
""
CMAKE_C_LINK_EXECUTABLE
"${CMAKE_C_LINK_EXECUTABLE}"
)
file(GLOB SOURCES
${CMAKE_SOURCE_DIR}/src/*.c
)
add_executable(${PROJECT_NAME} ${SOURCES})
# Base
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wdouble-promotion
-Wno-unused-parameter
-Wno-unused-function
-Wno-sign-conversion
)
target_link_options(${PROJECT_NAME} PRIVATE
-L${CMAKE_SOURCE_DIR}/vendor/raylib/lib
-Wl,-rpath=${CMAKE_SOURCE_DIR}/vendor/raylib/lib
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/vendor/STC/include
${CMAKE_SOURCE_DIR}/vendor/raylib/include
)
# Debug
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:-g3>)
# https://nullprogram.com/blog/2023/04/29/
# target_compile_options(${PROJECT_NAME} PRIVATE
# $<$<CONFIG:Debug>:-fsanitize=undefined -fsanitize-trap=undefined>)
# $<$<CONFIG:Debug>:-fsanitize=address -fsanitize=undefined -fsanitize-trap=undefined>)
target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:DEBUG>)
# Release
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:-O2>)
target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:NDEBUG>)
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:-Wl,--subsystem,windows>)
# Link
# target_link_libraries(${PROJECT_NAME} PRIVATE raylib winmm)
target_link_libraries(${PROJECT_NAME} PRIVATE raylib winmm gdi32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment