Files
reilua-enhanced/CMakeLists.txt
Indrajith K L 4859c415cc Add build scripts and Windows icon/resources
Added:
- build_dev.bat / build_dev.sh - Development build scripts
- build_release.bat / build_release.sh - Release build scripts with embedding
- icon.ico - Default Windows icon for executable
- resources.rc - Windows resource file for icon and exe metadata
- BUILD_SCRIPTS.md - Complete documentation for build scripts

Features:
- Automated development builds (no embedding, fast iteration)
- Automated release builds (with Lua and asset embedding)
- Interactive verification and cleanup
- Custom icon and version info in Windows executables
- Cross-platform scripts (Windows .bat and Unix .sh)
- Safety checks and helpful messages

The build scripts provide one-command building for both development
and release workflows, with clear instructions and progress feedback.
2025-11-03 18:11:34 +05:30

215 lines
8.0 KiB
CMake

set( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
include( CMakeDependentOption )
include( EnumOption )
cmake_minimum_required( VERSION 3.9 )
project( ReiLua )
# To make web build
# cmake .. -DCMAKE_TOOLCHAIN_FILE=<YOUR PATH HERE>/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DPLATFORM=Web
set( CMAKE_C_STANDARD 99 ) # Requires C99 standard
option( SHARED "Build using dynamic libraries." off )
option( LUAJIT "Use LuaJIT." off )
option( LUA_EVENTS "Enable Lua event callbacks (RL.event)." off )
option( DYNAMIC_SYMBOLS "Expose all dynamic symbols with rdynamic." off )
option( EXPOSE_API_SYMBOLS "Expose dynamic symbols only for get and push functions of variable types." off )
option( EMBED_MAIN "Embed all Lua files from build directory into executable." off )
option( EMBED_ASSETS "Embed all files from assets folder into executable." off )
enum_option( PLATFORM "Desktop;Desktop_SDL2;Desktop_SDL3;Web" "Platform to build for." )
if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
endif()
file( GLOB SOURCES src/*.c )
# Always embed logo files for splash screens
set( LOGO_FILES
"${CMAKE_SOURCE_DIR}/logo/raylib_logo.png"
"${CMAKE_SOURCE_DIR}/logo/reilua_logo.png"
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/embedded_logo.h
COMMAND python ${CMAKE_SOURCE_DIR}/embed_logo.py
${CMAKE_CURRENT_BINARY_DIR}/embedded_logo.h
${CMAKE_SOURCE_DIR}/logo/raylib_logo.png
${CMAKE_SOURCE_DIR}/logo/reilua_logo.png
DEPENDS ${LOGO_FILES}
COMMENT "Embedding logo files for splash screens..."
)
list( APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/embedded_logo.h )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMBED_LOGO" )
# Always embed font file
set( FONT_FILE "${CMAKE_SOURCE_DIR}/fonts/Oleaguid.ttf" )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/embedded_font.h
COMMAND python ${CMAKE_SOURCE_DIR}/embed_font.py
${CMAKE_CURRENT_BINARY_DIR}/embedded_font.h
${CMAKE_SOURCE_DIR}/fonts/Oleaguid.ttf
DEPENDS ${FONT_FILE}
COMMENT "Embedding font file..."
)
list( APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/embedded_font.h )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMBED_FONT" )
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( include )
# Add Windows resource file for icon and exe details
if( WIN32 )
list( APPEND SOURCES ${CMAKE_SOURCE_DIR}/resources.rc )
endif()
# Embed Lua files if EMBED_MAIN is ON
if( EMBED_MAIN )
file( GLOB LUA_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.lua" )
if( LUA_FILES )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/embedded_main.h
COMMAND python ${CMAKE_SOURCE_DIR}/embed_lua.py ${CMAKE_CURRENT_BINARY_DIR}/embedded_main.h ${LUA_FILES}
DEPENDS ${LUA_FILES}
COMMENT "Embedding Lua files into executable..."
)
list( APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/embedded_main.h )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMBED_MAIN" )
else()
message( WARNING "EMBED_MAIN is ON but no .lua files found in build directory!" )
endif()
endif()
# Embed asset files if EMBED_ASSETS is ON
if( EMBED_ASSETS )
file( GLOB_RECURSE ASSET_FILES "${CMAKE_CURRENT_BINARY_DIR}/assets/*" )
if( ASSET_FILES )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.h
COMMAND python ${CMAKE_SOURCE_DIR}/embed_assets.py ${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.h ${ASSET_FILES}
DEPENDS ${ASSET_FILES}
COMMENT "Embedding asset files into executable..."
)
list( APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.h )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMBED_ASSETS" )
else()
message( WARNING "EMBED_ASSETS is ON but no files found in build/assets/ directory!" )
endif()
endif()
add_executable( ${PROJECT_NAME} ${SOURCES} )
if( PLATFORM STREQUAL "Desktop" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" )
elseif( PLATFORM STREQUAL "Desktop_SDL2" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL2" )
elseif( PLATFORM STREQUAL "Desktop_SDL3" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL3" )
elseif( PLATFORM STREQUAL "Web" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" )
endif()
if( LUA_EVENTS )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUA_EVENTS" )
endif()
if( DYNAMIC_SYMBOLS )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic" )
endif()
if( PLATFORM STREQUAL "Web" )
target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/libraylib.a )
target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/liblua.a )
# Try "-s USE_PTHREADS" if not getting pixel perfect rendering.
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY" )
# set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s FORCE_FILESYSTEM=1" )
set( CMAKE_EXECUTABLE_SUFFIX ".html" ) # This line is used to set your executable to build with the emscripten html template so that you can directly open it.
set( resources_dir "resources@/" ) # Sets resources as root for the virtual file system.
set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}" )
else() # Desktop
if( SHARED )
message( Shared )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSHARED" )
# find_package( raylib 5.0 REQUIRED ) # Requires at least version 5.0
target_link_libraries( ${PROJECT_NAME} raylib )
if( LUAJIT )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT" )
target_link_libraries( ${PROJECT_NAME} luajit )
else()
target_link_libraries( ${PROJECT_NAME} lua )
endif()
else()
message( Static )
target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libraylib.a )
if( LUAJIT )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT" )
target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libluajit.a )
else()
target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/liblua.a )
endif()
endif()
if( UNIX )
set( CMAKE_C_COMPILER "gcc" )
if( EXPOSE_API_SYMBOLS )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS -rdynamic -fvisibility=hidden" )
endif()
if ( PLATFORM MATCHES "Desktop_SDL2" )
include( FindPkgConfig )
pkg_search_module( SDL2 REQUIRED sdl2 )
include_directories( ${SDL2_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} )
elseif ( PLATFORM MATCHES "Desktop_SDL3" )
include( FindPkgConfig )
pkg_search_module( SDL3 REQUIRED sdl3 )
include_directories( ${SDL3_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} )
endif()
if( DRM ) # For Raspberry Pi.
# target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt bcm_host m dl pthread )
# target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm pthread rt m dl )
target_link_libraries( ${PROJECT_NAME} raylib GLESv2 EGL pthread rt m gbm drm dl atomic )
else()
# target_link_libraries( ${PROJECT_NAME} m dl pthread )
target_link_libraries( ${PROJECT_NAME} m dl pthread glfw )
endif()
elseif( APPLE )
set( CMAKE_C_COMPILER "clang" )
# //TODO Linking to SDL.
target_link_libraries( ${PROJECT_NAME} "-framework IOKit" )
target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" )
target_link_libraries( ${PROJECT_NAME} "-framework OpenGL" )
elseif( WIN32 )
if( EXPOSE_API_SYMBOLS )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS" )
endif()
if ( PLATFORM MATCHES "Desktop_SDL2" )
find_package( SDL2 REQUIRED )
include_directories( ${SDL2_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL2MAIN_LIBRARIES} )
target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} )
elseif ( PLATFORM MATCHES "Desktop_SDL3" )
find_package( SDL3 REQUIRED )
include_directories( ${SDL3_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL3MAIN_LIBRARIES} )
target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} )
endif()
# Remove this to get console. //TODO Could be build option.
set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-mwindows" )
target_link_libraries( ${PROJECT_NAME} mingw32 opengl32 gdi32 winmm )
endif()
endif()