Skip to content

Commit

Permalink
Add a working Cmake setup
Browse files Browse the repository at this point in the history
This will compile SDL libraries, dependencies, nene itself and the collisions.c example.
  • Loading branch information
Andre-LA committed Apr 25, 2023
1 parent defb226 commit f7c9a91
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 18 deletions.
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2021-present André Luiz Alvares
# Nene is licensed under the Zlib license.
# Please refer to the LICENSE file for details
# SPDX-License-Identifier: Zlib

# Set minimum cmake version, this should go until the latest available release,
# the first version it's still to be decided though, but it shouldn't be older than the one used by SDL's CMakeLists.
cmake_minimum_required(VERSION 3.15-3.26)

# Set the project name, version and language
project(
nene
VERSION 0.4
LANGUAGES C
)

# set the C standard, be sure to review compile_flags.txt file too.
set(CMAKE_C_STANDARD_REQUIRED 99)

add_library(${PROJECT_NAME} STATIC)

# add the src and external directories on the building procedure
add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(examples/c)

4 changes: 4 additions & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
-Wpedantic
-std=c99
-I./include/
-I./external/SDL/include
-I./external/SDL_mixer/include
-I./external/SDL_image
-I./external/SDL_ttf
9 changes: 9 additions & 0 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021-present André Luiz Alvares
# Nene is licensed under the Zlib license.
# Please refer to the LICENSE file for details
# SPDX-License-Identifier: Zlib

add_executable(nene_c_collisions collisions.c)

target_link_libraries(nene_c_collisions nene)

24 changes: 24 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2021-present André Luiz Alvares
# Nene is licensed under the Zlib license.
# Please refer to the LICENSE file for details
# SPDX-License-Identifier: Zlib

# This cmake file add the "external_libs" library target, with all external modules (that is, SDL libraries)

# Adds the SDL subdirectories, which are git sub-modules,
# be sure to clone nene with "recurse-submodules" flag, otherwise the SDL
# libraries will not be clonned with nene.
add_subdirectory(SDL)
add_subdirectory(SDL_image)
add_subdirectory(SDL_mixer)
add_subdirectory(SDL_ttf)

# creating the "external_libs" library target
add_library(external_libs INTERFACE)

# adding linking to the SDL libraries to the project build.
target_link_libraries(${PROJECT_NAME} INTERFACE SDL2::SDL2)
target_link_libraries(${PROJECT_NAME} INTERFACE SDL2_image::SDL2_image)
target_link_libraries(${PROJECT_NAME} INTERFACE SDL2_mixer::SDL2_mixer)
target_link_libraries(${PROJECT_NAME} INTERFACE SDL2_ttf::SDL2_ttf)

2 changes: 1 addition & 1 deletion include/nene/audio/music.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SPDX-License-Identifier: Zlib

#include <stdbool.h>
#include <stdint.h>
#include <SDL2/SDL_mixer.h>
#include <SDL_mixer.h>

typedef struct nene_Music {
Mix_Music *raw;
Expand Down
2 changes: 1 addition & 1 deletion include/nene/audio/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SPDX-License-Identifier: Zlib

#include <stdint.h>
#include <stdbool.h>
#include <SDL2/SDL_mixer.h>
#include <SDL_mixer.h>

typedef struct nene_Sound {
Mix_Chunk *raw;
Expand Down
2 changes: 1 addition & 1 deletion include/nene/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: Zlib
#define NENE_COLOR_H

#include <stdbool.h>
#include <SDL2/SDL.h>
#include <SDL.h>

/// Alias to SDL_color
typedef SDL_Color nene_Color;
Expand Down
2 changes: 1 addition & 1 deletion include/nene/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: Zlib
#define NENE_CORE_H

#include <stdbool.h>
#include <SDL2/SDL.h>
#include <SDL.h>
#include "nene/config.h"
#include "nene/math/vec2.h"
#include "nene/math/vec2i.h"
Expand Down
2 changes: 1 addition & 1 deletion include/nene/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SPDX-License-Identifier: Zlib

#include <stdint.h>
#include <stdbool.h>
#include <SDL2/SDL_ttf.h>
#include <SDL_ttf.h>
#include "nene/math/vec2i.h"
#include "nene/texture.h"
#include "nene/color.h"
Expand Down
2 changes: 1 addition & 1 deletion include/nene/math/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: Zlib
#define NENE_RECT_H

#include <stdbool.h>
#include <SDL2/SDL.h>
#include <SDL.h>

#include "nene/math/vec2i.h"

Expand Down
2 changes: 1 addition & 1 deletion include/nene/math/rectf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: Zlib
#define NENE_RECTF_H

#include <stdbool.h>
#include <SDL2/SDL.h>
#include <SDL.h>

#include "nene/math/vec2.h"
#include "nene/math/rect.h"
Expand Down
2 changes: 1 addition & 1 deletion include/nene/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SPDX-License-Identifier: Zlib

#include <stdint.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
#include <SDL.h>

#include "nene/math/vec2.h"
#include "nene/math/rect.h"
Expand Down
38 changes: 38 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2021-present André Luiz Alvares
# Nene is licensed under the Zlib license.
# Please refer to the LICENSE file for details
# SPDX-License-Identifier: Zlib

target_sources(${PROJECT_NAME} PUBLIC
core.c
texture.c
font.c
texture_atlas.c
audio/music.c
audio/sound.c
math/vec2i.c
math/vec2.c
math/rect.c
math/rectf.c
math/grid.c
math/segment.c
math/shape.c
intersections.c
collision.c
animation.c
tilemap.c
color.c
)

# # add the nene include directory
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)

# # add the sdl include directories (NOTE: remove these once the (game) usage of SDL get's unnecessary)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/external/SDL/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/external/SDL_mixer/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/external/SDL_image)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/external/SDL_ttf)

# add linking to the external dependencies (SDL libraries) to the target
target_link_libraries(${PROJECT_NAME} PUBLIC external_libs)
target_link_libraries(${PROJECT_NAME} PUBLIC m)
2 changes: 1 addition & 1 deletion src/audio/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: Zlib
*/

#include "nene/audio/music.h"
#include "SDL2/SDL.h"
#include <SDL.h>

Mix_Music *nene_Music_get_raw(nene_Music music) {
SDL_assert(music.raw != NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: Zlib
*/

#include "nene/audio/sound.h"
#include <SDL2/SDL.h>
#include <SDL.h>

Mix_Chunk *nene_Sound_get_raw(nene_Sound sound) {
SDL_assert(sound.raw != NULL);
Expand Down
10 changes: 5 additions & 5 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Please refer to the LICENSE file for details
SPDX-License-Identifier: Zlib
*/

#include <SDL2/SDL.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include <math.h>
#include <SDL_events.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include "nene/core.h"
#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Please refer to the LICENSE file for details
SPDX-License-Identifier: Zlib
*/

#include <SDL2/SDL.h>
#include <SDL.h>
#include "nene/font.h"
#include "nene/core.h"

Expand Down
4 changes: 2 additions & 2 deletions src/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Please refer to the LICENSE file for details
SPDX-License-Identifier: Zlib
*/

#include <SDL2/SDL_image.h>
#include <SDL2/SDL_render.h>
#include <SDL_image.h>
#include <SDL_render.h>
#include "nene/texture.h"
#include "nene/core.h"

Expand Down

0 comments on commit f7c9a91

Please sign in to comment.