-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from furudbat/main
Add CMake support
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
cmake_minimum_required(VERSION 3.19...3.24) | ||
|
||
# Generate compile_commands.json | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
# Not ideal to use this global variable, but necessary to make sure that tooling and projects use the same version | ||
#set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_C_STANDARD 99) | ||
|
||
# strongly encouraged to enable this globally to avoid conflicts between -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for | ||
# example when compiling with PCH enabled | ||
#set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_C_EXTENSIONS ON) | ||
|
||
# Set the project name to your project name, my project isn't very descriptive | ||
project(raylib_game | ||
VERSION 0.1.0 | ||
LANGUAGES C CXX) | ||
|
||
# ---- Add dependencies via CPM ---- | ||
## https://github.com/cpm-cmake/CPM.cmake | ||
set(CPM_DOWNLOAD_VERSION 0.40.2) | ||
if(CPM_SOURCE_CACHE) | ||
# Expand relative path. This is important if the provided path contains a tilde (~) | ||
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE) | ||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
elseif(DEFINED ENV{CPM_SOURCE_CACHE}) | ||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
else() | ||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
endif() | ||
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) | ||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") | ||
file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION}) | ||
endif() | ||
include(${CPM_DOWNLOAD_LOCATION}) | ||
## add raylib (3rd-party) https://github.com/raysan5/raylib | ||
cpmaddpackage( | ||
NAME | ||
raylib | ||
GITHUB_REPOSITORY | ||
raysan5/raylib | ||
GIT_TAG | ||
#5.5 | ||
master # use up-to-date branch | ||
) | ||
target_compile_options(raylib PRIVATE $<$<C_COMPILER_ID:GNU,Clang>:-Wno-error=implicit-function-declaration>) | ||
target_compile_options(raylib PRIVATE $<$<C_COMPILER_ID:GNU,Clang>:-Wno-unused-result>) | ||
target_compile_options(raylib PRIVATE $<$<C_COMPILER_ID:GNU>:-Wno-stringop-overflow>) | ||
target_compile_options(raylib PRIVATE $<$<C_COMPILER_ID:Clang>:-Wno-implicit-const-int-float-conversion>) | ||
target_compile_features(raylib PRIVATE c_std_99) | ||
if("${PLATFORM}" STREQUAL "Desktop") | ||
target_compile_features(glfw PRIVATE c_std_99) | ||
endif() | ||
|
||
# ########################################################################################################################################## | ||
# Project | ||
# ########################################################################################################################################## | ||
|
||
add_subdirectory(src) | ||
|
||
# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment so that it behaves well with MSVC's debugger, and we | ||
# can run the target from visual studio | ||
if(MSVC) | ||
get_all_installable_targets(all_targets) | ||
message("all_targets=${all_targets}") | ||
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
add_executable(raylib_game) | ||
# @NOTE: add more source files here | ||
target_sources(raylib_game PRIVATE raylib_game.c) | ||
|
||
target_include_directories(raylib_game PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>") | ||
target_link_libraries(raylib_game raylib) | ||
if(NOT WIN32) | ||
target_link_libraries(raylib_game m) | ||
endif() | ||
|
||
# Web Configurations | ||
if (${PLATFORM} STREQUAL "Web") | ||
set_target_properties(raylib_game PROPERTIES SUFFIX ".html") # Tell Emscripten to build an example.html file. | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s FORCE_FILESYSTEM=1 -s WASM=1") | ||
|
||
set(web_link_flags) | ||
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) | ||
set(web_link_flags "${web_link_flags} -s ASSERTIONS=1") | ||
endif() | ||
set(web_link_flags "${web_link_flags} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/resources@resources --use-preload-plugins") | ||
set(web_link_flags "${web_link_flags} --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/minshell.html") | ||
|
||
set_target_properties(raylib_game PROPERTIES LINK_FLAGS "${web_link_flags}") | ||
endif() | ||
|
||
# Checks if OSX and links appropriate frameworks (only required on MacOS) | ||
if(APPLE) | ||
target_link_libraries(raylib_game "-framework IOKit") | ||
target_link_libraries(raylib_game "-framework Cocoa") | ||
target_link_libraries(raylib_game "-framework OpenGL") | ||
endif() | ||
|
||
# misc | ||
set_target_properties(raylib_game PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") | ||
# set the startup project for the "play" button in MSVC | ||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT raylib_game) |