Skip to content

Commit

Permalink
improve CMakeLists.txt examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Bigfoot71 committed Sep 16, 2024
1 parent e801796 commit a1fe274
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 120 deletions.
25 changes: 13 additions & 12 deletions examples/LinuxFB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ cmake_minimum_required(VERSION 3.21)
# Path to example resources
add_definitions(-DRESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../resources/")

# Basic 2D example
add_executable(LinuxFB_2D ${PF_ROOT_PATH}/examples/LinuxFB/LinuxFB_2D.c)
target_link_libraries(LinuxFB_2D PRIVATE pixelforge m)
target_include_directories(LinuxFB_2D PRIVATE ${PF_ROOT_PATH}/src)
# Function to link all libraries accordingly to the compiler / target platform
function(link_libraries_linuxfb target)
target_link_libraries(${target} PRIVATE pixelforge m)
endfunction()

# Basic 3D example
add_executable(LinuxFB_3D ${PF_ROOT_PATH}/examples/LinuxFB/LinuxFB_3D.c)
target_link_libraries(LinuxFB_3D PRIVATE pixelforge m)
target_include_directories(LinuxFB_3D PRIVATE ${PF_ROOT_PATH}/src)
# Get all .c files in the LinuxFB examples directory
file(GLOB LINUXFB_EXAMPLES_SOURCES "${PF_ROOT_PATH}/examples/LinuxFB/*.c")

# Gears example
add_executable(LinuxFB_Gears ${PF_ROOT_PATH}/examples/LinuxFB/LinuxFB_Gears.c)
target_link_libraries(LinuxFB_Gears PRIVATE pixelforge m)
target_include_directories(LinuxFB_Gears PRIVATE ${PF_ROOT_PATH}/src)
# Loop over each .c file and create an executable for each one
foreach(SOURCE_FILE ${LINUXFB_EXAMPLES_SOURCES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE)
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE})
link_libraries_linuxfb(${EXECUTABLE_NAME})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${PF_ROOT_PATH}/src)
endforeach()
28 changes: 16 additions & 12 deletions examples/SDL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ cmake_minimum_required(VERSION 3.21)
# Path to example resources
add_definitions(-DRESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../resources/")

# Basic 2D example
add_executable(SDL2_2D ${PF_ROOT_PATH}/examples/SDL2/SDL2_2D.c)
target_link_libraries(SDL2_2D PRIVATE pixelforge SDL2 m)
target_include_directories(SDL2_2D PRIVATE ${PF_ROOT_PATH}/src)
# Function to link all libraries accordingly to the compiler / target platform
function(link_libraries_sdl2 target)
target_link_libraries(${target} PRIVATE pixelforge SDL2)
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
target_link_libraries(${target} PRIVATE m)
endif()
endfunction()

# Basic 3D example
add_executable(SDL2_3D ${PF_ROOT_PATH}/examples/SDL2/SDL2_3D.c)
target_link_libraries(SDL2_3D PRIVATE pixelforge SDL2 m)
target_include_directories(SDL2_3D PRIVATE ${PF_ROOT_PATH}/src)
# Get all .c files in the SDL2 examples directory
file(GLOB SDL2_EXAMPLES_SOURCES "${PF_ROOT_PATH}/examples/SDL2/*.c")

# Gears example
add_executable(SDL2_Gears ${PF_ROOT_PATH}/examples/SDL2/SDL2_Gears.c)
target_link_libraries(SDL2_Gears PRIVATE pixelforge SDL2 m)
target_include_directories(SDL2_Gears PRIVATE ${PF_ROOT_PATH}/src)
# Loop over each .c file and create an executable for each one
foreach(SOURCE_FILE ${SDL2_EXAMPLES_SOURCES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE)
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE})
link_libraries_sdl2(${EXECUTABLE_NAME})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${PF_ROOT_PATH}/src)
endforeach()
29 changes: 17 additions & 12 deletions examples/WinAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ cmake_minimum_required(VERSION 3.21)
# Path to example resources
add_definitions(-DRESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../resources/")

# Basic 2D example
add_executable(WinAPI_2D ${PF_ROOT_PATH}/examples/WinAPI/WinAPI_2D.c)
target_link_libraries(WinAPI_2D PRIVATE pixelforge gdi32 m)
target_include_directories(WinAPI_2D PRIVATE ${PF_ROOT_PATH}/src)
# Function link all libraries accordingly to the compiler / target platform
function(link_libraries_winapi target)
target_link_libraries(${target} PRIVATE pixelforge gdi32 winmm)
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
target_link_libraries(${target} PRIVATE m)
endif()
endfunction()

# Basic 3D example
add_executable(WinAPI_3D ${PF_ROOT_PATH}/examples/WinAPI/WinAPI_3D.c)
target_link_libraries(WinAPI_3D PRIVATE pixelforge gdi32 m)
target_include_directories(WinAPI_3D PRIVATE ${PF_ROOT_PATH}/src)
# Get all .c files in the WinAPI examples directory
file(GLOB WINAPI_EXAMPLES_SOURCES "${PF_ROOT_PATH}/examples/WinAPI/*.c")

# Gears example
add_executable(WinAPI_Gears ${PF_ROOT_PATH}/examples/WinAPI/WinAPI_Gears.c)
target_link_libraries(WinAPI_Gears PRIVATE pixelforge gdi32 m)
target_include_directories(WinAPI_Gears PRIVATE ${PF_ROOT_PATH}/src)
# Loop over each .c file and create an executable for each one
foreach(SOURCE_FILE ${WINAPI_EXAMPLES_SOURCES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE)
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE})
link_libraries_winapi(${EXECUTABLE_NAME})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${PF_ROOT_PATH}/src)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
endforeach()
28 changes: 16 additions & 12 deletions examples/X11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ cmake_minimum_required(VERSION 3.21)
# Path to example resources
add_definitions(-DRESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../resources/")

# Basic 2D example
add_executable(X11_2D ${PF_ROOT_PATH}/examples/X11/X11_2D.c)
target_link_libraries(X11_2D PRIVATE pixelforge X11 m)
target_include_directories(X11_2D PRIVATE ${PF_ROOT_PATH}/src)
# Function to link all libraries accordingly to the compiler / target platform
function(link_libraries_x11 target)
target_link_libraries(${target} PRIVATE pixelforge X11)
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
target_link_libraries(${target} PRIVATE m)
endif()
endfunction()

# Basic 3D example
add_executable(X11_3D ${PF_ROOT_PATH}/examples/X11/X11_3D.c)
target_link_libraries(X11_3D PRIVATE pixelforge X11 m)
target_include_directories(X11_3D PRIVATE ${PF_ROOT_PATH}/src)
# Get all .c files in the X11 examples directory
file(GLOB X11_EXAMPLES_SOURCES "${PF_ROOT_PATH}/examples/X11/*.c")

# Gears example
add_executable(X11_Gears ${PF_ROOT_PATH}/examples/X11/X11_Gears.c)
target_link_libraries(X11_Gears PRIVATE pixelforge X11 m)
target_include_directories(X11_Gears PRIVATE ${PF_ROOT_PATH}/src)
# Loop over each .c file and create an executable for each one
foreach(SOURCE_FILE ${X11_EXAMPLES_SOURCES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE)
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE})
link_libraries_x11(${EXECUTABLE_NAME})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${PF_ROOT_PATH}/src)
endforeach()
87 changes: 15 additions & 72 deletions examples/raylib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,24 @@ cmake_minimum_required(VERSION 3.21)
# Path to example resources
add_definitions(-DRESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../resources/")

# Function to add gdi32 and winmm if compiling under Windows
function(link_windows_libraries target)
# Function link all librairies accordingly to the compiler / target platform
function(link_libraries_raylib target)
target_link_libraries(${target} PRIVATE pixelforge raylib)
if(WIN32)
target_link_libraries(${target} PRIVATE gdi32 winmm)
endif()
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
target_link_libraries(${target} PRIVATE m)
endif()
endfunction()

# Basic 2D example
add_executable(raylib_2D ${PF_ROOT_PATH}/examples/raylib/raylib_2D.c)
target_link_libraries(raylib_2D PRIVATE pixelforge raylib m)
target_include_directories(raylib_2D PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_2D)

# Basic 3D example
add_executable(raylib_3D ${PF_ROOT_PATH}/examples/raylib/raylib_3D.c)
target_link_libraries(raylib_3D PRIVATE pixelforge raylib m)
target_include_directories(raylib_3D PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_3D)

# Gears example
add_executable(raylib_Gears ${PF_ROOT_PATH}/examples/raylib/raylib_Gears.c)
target_link_libraries(raylib_Gears PRIVATE pixelforge raylib m)
target_include_directories(raylib_Gears PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_Gears)

# Gears example
add_executable(raylib_PostProcess ${PF_ROOT_PATH}/examples/raylib/raylib_PostProcess.c)
target_link_libraries(raylib_PostProcess PRIVATE pixelforge raylib m)
target_include_directories(raylib_PostProcess PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_PostProcess)

# Points example
add_executable(raylib_Points ${PF_ROOT_PATH}/examples/raylib/raylib_Points.c)
target_link_libraries(raylib_Points PRIVATE pixelforge raylib m)
target_include_directories(raylib_Points PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_Points)

# Framebuffer example
add_executable(raylib_Framebuffer ${PF_ROOT_PATH}/examples/raylib/raylib_Framebuffer.c)
target_link_libraries(raylib_Framebuffer PRIVATE pixelforge raylib m)
target_include_directories(raylib_Framebuffer PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_Framebuffer)

# Texture 2D example
add_executable(raylib_Texture2D ${PF_ROOT_PATH}/examples/raylib/raylib_Texture2D.c)
target_link_libraries(raylib_Texture2D PRIVATE pixelforge raylib m)
target_include_directories(raylib_Texture2D PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_Texture2D)

# Texture Matrix example
add_executable(raylib_TextureMatrix ${PF_ROOT_PATH}/examples/raylib/raylib_TextureMatrix.c)
target_link_libraries(raylib_TextureMatrix PRIVATE pixelforge raylib m)
target_include_directories(raylib_TextureMatrix PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_TextureMatrix)

# Textured 3D Model example
add_executable(raylib_ModelTextured ${PF_ROOT_PATH}/examples/raylib/raylib_ModelTextured.c)
target_link_libraries(raylib_ModelTextured PRIVATE pixelforge raylib m)
target_include_directories(raylib_ModelTextured PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_ModelTextured)

# Animated 3D Model example
add_executable(raylib_ModelAnimation ${PF_ROOT_PATH}/examples/raylib/raylib_ModelAnimation.c)
target_link_libraries(raylib_ModelAnimation PRIVATE pixelforge raylib m)
target_include_directories(raylib_ModelAnimation PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_ModelAnimation)

# Wire Mode 3D example
add_executable(raylib_ModelWires ${PF_ROOT_PATH}/examples/raylib/raylib_ModelWires.c)
target_link_libraries(raylib_ModelWires PRIVATE pixelforge raylib m)
target_include_directories(raylib_ModelWires PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_ModelWires)
# Get all .c files in the raylib examples directory
file(GLOB EXAMPLES_SOURCES "${PF_ROOT_PATH}/examples/raylib/*.c")

# First Person 3D example
add_executable(raylib_FirstPerson ${PF_ROOT_PATH}/examples/raylib/raylib_FirstPerson.c)
target_link_libraries(raylib_FirstPerson PRIVATE pixelforge raylib m)
target_include_directories(raylib_FirstPerson PRIVATE ${PF_ROOT_PATH}/src)
link_windows_libraries(raylib_FirstPerson)
# Loop over each .c file and create an executable for each one
foreach(SOURCE_FILE ${EXAMPLES_SOURCES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE)
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE})
link_libraries_raylib(${EXECUTABLE_NAME})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${PF_ROOT_PATH}/src)
endforeach()

0 comments on commit a1fe274

Please sign in to comment.