CMake based build system.

Some people might find this handly
This commit is contained in:
ASDF 2017-07-22 19:45:36 -04:00 committed by Benjamin N. summerton
parent 0fc1323c80
commit e173db19f7
14 changed files with 416 additions and 2 deletions

22
.gitignore vendored
View File

@ -131,3 +131,25 @@ src/libraylib.bc
# Meson build system
builddir/
# CMake stuff
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
build
# Unignore These makefiles...
!examples/CMakeLists.txt
!games/CMakeLists.txt
# binaries made from raylib
libraylib.a
libraylib.so
libraylib.dylib
libraylib.dll

16
CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.0)
# Config options
set(BUILD_EXAMPLES ON CACHE BOOL "Build the examples.")
set(BUILD_GAMES ON CACHE BOOL "Build the example games.")
add_subdirectory(src release)
if (${BUILD_EXAMPLES})
add_subdirectory(examples)
endif()
if (${BUILD_GAMES})
add_subdirectory(games)
endif()

39
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,39 @@
# Setup the project and settings
project(examples)
include("../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
# TODO place somewhere else?
include_directories("../build/release")
# Get the sources together
set(example_dirs audio core models others physac shaders text texutures)
set(example_sources)
set(example_resources)
foreach(example_dir ${example_dirs})
# Get the .c files
file(GLOB sources ${example_dir}/*.c)
list(APPEND example_sources ${sources})
# Any any resources
file(GLOB resources ${example_dir}/resources/*)
list(APPEND example_resources ${resources})
endforeach()
# Do each example
foreach(example_source ${example_sources})
# Create the basename for the example
get_filename_component(example_name ${example_source} NAME)
string(REPLACE ".c" "" example_name ${example_name})
# Setup the example
add_executable(${example_name} ${example_source})
# Link the libraries
link_libraries_to_executable(${example_name})
endforeach()
# Copy all of the resource files to the destination
file(COPY ${example_resources} DESTINATION "resources/")

View File

@ -189,7 +189,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
# libraries for Debian GNU/Linux desktop compiling
# requires the following packages:
# libglfw3-dev libopenal-dev libegl1-mesa-dev
LIBS = -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl
LIBS = -lraylib -lglfw -lGL -lopenal -lm -lpthread -ldl
# on XWindow requires also below libraries
LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
else

33
games/CMakeLists.txt Normal file
View File

@ -0,0 +1,33 @@
# Setup the project and settings
project(games)
include("../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
# TODO place somewhere else?
include_directories("../build/release")
# Get the source toegher
file(GLOB sources *.c)
# Do each game
foreach(game_source ${sources})
# Create the basename for the game
get_filename_component(game_name ${game_source} NAME)
string(REPLACE ".c" "" game_name ${game_name})
# Setup the game
add_executable(${game_name} ${game_source})
# Link the libraries
link_libraries_to_executable(${game_name})
endforeach()
# Do the games with subdirectories
add_subdirectory(drturtle)
add_subdirectory(just_do)
add_subdirectory(koala_seasons)
add_subdirectory(light_my_ritual)
add_subdirectory(skully_escape)
add_subdirectory(wave_collector)

View File

@ -0,0 +1,18 @@
# Setup the project and settings
project(drturtle)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Executable & linking
add_executable(drturtle 06_drturtle_final.c)
link_libraries_to_executable(drturtle)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

View File

@ -0,0 +1,21 @@
# Setup the project and settings
project(just_do)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Grab the screens
file(GLOB screen_sources "screens/*.c")
# Executable & linking
add_executable(just_do just_do.c ${screen_sources})
link_libraries_to_executable(just_do)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

View File

@ -0,0 +1,21 @@
# Setup the project and settings
project(koala_seasons)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Grab the screens
file(GLOB screen_sources "screens/*.c")
# Executable & linking
add_executable(koala_seasons koala_seasons.c ${screen_sources})
link_libraries_to_executable(koala_seasons)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

View File

@ -0,0 +1,21 @@
# Setup the project and settings
project(light_my_ritual)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Grab the screens
file(GLOB screen_sources "screens/*.c")
# Executable & linking
add_executable(light_my_ritual light_my_ritual.c ${screen_sources})
link_libraries_to_executable(light_my_ritual)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

View File

@ -0,0 +1,21 @@
# Setup the project and settings
project(skully_escape)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Grab the screens
file(GLOB screen_sources "screens/*.c")
# Executable & linking
add_executable(skully_escape skully_escape.c player.c monster.c ${screen_sources})
link_libraries_to_executable(skully_escape)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

View File

@ -0,0 +1,21 @@
# Setup the project and settings
project(wave_collector)
include("../../utils.cmake")
# Make sure raylib has been built
# TODO `build` directory should maybe be something else...
include_directories("../../build/release")
# Grab the screens
file(GLOB screen_sources "screens/*.c")
# Executable & linking
add_executable(wave_collector wave_collector.c ${screen_sources})
link_libraries_to_executable(wave_collector)
# Resources
# Copy all of the resource files to the destination
file(COPY "resources/" DESTINATION "resources/")

132
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,132 @@
# Setup the project and settings
project(raylib)
include("../utils.cmake")
set(raylib_VERSION_MAJOR 1)
set(raylib_VERSION_MINOR 8)
set(RAYLIB raylib) # Name of the generated library
### Config options ###
# Build a static or shared raylib?
set(SHARED_RAYLIB OFF CACHE BOOL "Build raylib as a dynamic library")
# Platform
set(PLATFORM "Desktop" CACHE STRING "Platform to build for.")
set_property(CACHE PLATFORM PROPERTY STRINGS "Desktop" "Web" "Android" "Raspberry Pi")
# OpenGL version
set(OPENGL_VERSION "3.3" CACHE STRING "OpenGL Version to build raylib with")
set_property(CACHE OPENGL_VERSION PROPERTY STRINGS "3.3" "2.1" "1.1" "ES 2.0")
### Config options ###
# Translate the config options to what raylib wants
if(${PLATFORM} MATCHES "Desktop")
set(PLATFORM "PLATFORM_DESKTOP")
# OpenGL version
if (${OPENGL_VERSION} MATCHES "3.3")
set(GRAPHICS "GRAPHICS_API_OPENGL_33")
elseif (${OPENGL_VERSION} MATCHES "2.1")
set(GRAPHICS "GRAPHICS_API_OPENGL_21")
elseif (${OPENGL_VERSION} MATCHES "1.1")
set(GRAPHICS "GRAPHICS_API_OPENGL_11")
elseif (${OPENGL_VERSION} MATCHES "ES 2.0")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
endif()
# Need to force OpenGL 3.3 on OS X
# See: https://github.com/raysan5/raylib/issues/341
if(APPLE)
set(GRAPHICS "GRAPHICS_API_OPENGL_33")
endif()
elseif(${PLATFORM} MATCHES "Web")
set(PLATFORM "PLATFORM_WEB")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
# Need to use `emcc`
set(CMAKE_C_COMPILER "emcc")
set(CMAKE_CXX_COMPILER "em++")
# Change the name of the output library
set(RAYLIB "libraylib.bc")
elseif(${PLATFORM} MATCHES "Android")
set(PLATFORM "PLATFORM_ANDROID")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
elseif(${PLATFORM} MATCHES "Raspberry Pi")
set(PLATFORM "PLATFORM_RPI")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
endif()
# Get the sources together
file(GLOB raylib_sources *.c)
file(GLOB stb_vorbis external/stb_vorbis.c)
set(sources ${raylib_sources} ${stb_vorbis})
# Which platform?
if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
# Build a static or shared raylib?
# TODO clean this up a bit?
if(${SHARED_RAYLIB})
# Shared library
add_library(${RAYLIB} SHARED ${sources})
# Will link -framework (if on OS X)
link_os_x_frameworks(raylib)
else()
# Static library
add_library(${RAYLIB} STATIC ${sources})
if(LINUX)
# On Linux, need to link a few extra things for static
target_link_libraries(${RAYLIB} m pthread dl)
target_link_libraries(${RAYLIB} X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
endif()
endif()
# Always need to link OpenAL and OpenGL
if(LINUX)
# Elsewhere (such as Linux), need `-lopenal -lGL`
target_link_libraries(${RAYLIB} openal)
target_link_libraries(${RAYLIB} GL)
endif()
# Add in GLFW as a linking target
target_link_libraries(${RAYLIB} glfw)
# Library file & Header
set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h")
install(
TARGETS ${RAYLIB}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
# Copy the header files to the build directory
file(COPY "raylib.h" DESTINATION ".")
file(COPY "rlgl.h" DESTINATION ".")
file(COPY "physac.h" DESTINATION ".")
file(COPY "raymath.h" DESTINATION ".")
file(COPY "audio.h" DESTINATION ".")
elseif(${PLATFORM} MATCHES "PLATFORM_WEB")
# For the web.
add_executable(${RAYLIB} ${sources})
endif()
# Set the compile flags to raylib
target_compile_definitions(${RAYLIB}
PUBLIC ${PLATFORM}
PUBLIC ${GRAPHICS}
)
# Print the flags for the user
message(STATUS "Compiling with the flags:")
message(STATUS " PLATFORM=" ${PLATFORM})
message(STATUS " GRAPHICS=" ${GRAPHICS})

View File

@ -332,7 +332,7 @@ else
ifeq ($(PLATFORM_OS),LINUX)
# compile raylib to shared library version for GNU/Linux.
# WARNING: you should type "make clean" before doing this target
$(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS) -lglfw3 -lGL -lopenal -lm -lpthread -ldl
$(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS) -lglfw -lGL -lopenal -lm -lpthread -ldl
@echo "raylib shared library generated (libraylib.so)!"
endif
ifeq ($(PLATFORM_OS),OSX)

49
utils.cmake Normal file
View File

@ -0,0 +1,49 @@
# All sorts of things that we need cross project
cmake_minimum_required(VERSION 3.0)
# Detect linux
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
# Need GLFW 3.2.1
find_package(glfw3 3.2.1 REQUIRED)
# Linking for OS X -framework options
# Will do nothing on other OSes
function(link_os_x_frameworks binary)
if(APPLE)
find_library(OPENGL_LIBRARY OpenGL)
find_library(OPENAL_LIBRARY OpenAL)
find_library(COCOA_LIBRARY Cocoa)
set(OSX_FRAMEWORKS ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} ${COCOA_LIBRARY})
target_link_libraries(${binary} ${OSX_FRAMEWORKS})
endif()
endfunction()
# Do the linking for executables that are meant to link raylib
function(link_libraries_to_executable executable)
# Link the libraries
if(APPLE)
# OS X, we use frameworks
link_os_x_frameworks(${executable})
elseif(LINUX)
# Elsewhere (such as Linux), need `-lopenal -lGL`, etc...
target_link_libraries(${executable} m pthread dl)
target_link_libraries(${executable} openal)
target_link_libraries(${executable} GL)
target_link_libraries(${executable} X11 Xrandr Xinerama Xi Xxf86vm Xcursor) # X11 stuff
else()
# TODO windows
endif()
# Add in GLFW as a linking target
target_link_libraries(${executable} glfw)
# And raylib
target_link_libraries(${executable} raylib)
endfunction()