diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9eb0293 --- /dev/null +++ b/CMakeLists.txt @@ -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 $<$:-Wno-error=implicit-function-declaration>) +target_compile_options(raylib PRIVATE $<$:-Wno-unused-result>) +target_compile_options(raylib PRIVATE $<$:-Wno-stringop-overflow>) +target_compile_options(raylib PRIVATE $<$:-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() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..ef4f637 --- /dev/null +++ b/src/CMakeLists.txt @@ -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 "$") +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) diff --git a/src/Makefile b/src/Makefile index 25c4ddd..081322c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -264,7 +264,11 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) # NOTE: WinMM library required to set high-res timer resolution LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm -lcomdlg32 -lole32 # Required for physac examples - LDLIBS += -static -lpthread + ifeq ($(RAYLIB_LIBTYPE),SHARED) + LDLIBS += -lpthread + else + LDLIBS += -static -lpthread + endif endif ifeq ($(PLATFORM_OS),LINUX) # Libraries for Debian GNU/Linux desktop compiling