Modernize CMakeList.txt

This commit is contained in:
Amine B. Hassouna
2019-02-04 00:06:04 +01:00
parent 83d681301a
commit 40f9d234ca
2 changed files with 32 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
# #
# Copyright (c) 2018 Amine Ben Hassouna <amine.benhassouna@gmail.com> # Copyright (c) 2018, 2019 Amine Ben Hassouna <amine.benhassouna@gmail.com>
# #
# Permission is hereby granted, free of charge, to any # Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated # person obtaining a copy of this software and associated
@@ -32,33 +32,37 @@ project(basic-c-sdl-project)
# Set the cmake minimum version to 3.5.1 # Set the cmake minimum version to 3.5.1
cmake_minimum_required(VERSION 3.5.1) cmake_minimum_required(VERSION 3.5.1)
# Add all headers files under the include directory # Add SDL2 CMake modules
include_directories(include) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
# Add all c source files under the src directory # Add all c source files under the src directory
file(GLOB SOURCES "src/*.c") file(GLOB SOURCES "src/*.c")
add_executable(${PROJECT_NAME} ${SOURCES}) add_executable(${PROJECT_NAME} ${SOURCES})
# Load CMake module : FindPkgConfig # Add all headers files under the include directory
include(FindPkgConfig) target_include_directories(${PROJECT_NAME} PRIVATE include)
# Add SDL2 library # Add SDL2 library
pkg_search_module(SDL2 REQUIRED sdl2) find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} SDL2::Main)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
# Add SDL2_image library # Add SDL2_image library
#pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0) #find_package(SDL2_image REQUIRED)
#include_directories(${SDL2IMAGE_INCLUDE_DIRS}) #target_link_libraries(${PROJECT_NAME} SDL2::Image)
#target_link_libraries(${PROJECT_NAME} ${SDL2IMAGE_LIBRARIES})
# Add SDL2_ttf library # Add SDL2_ttf library
#pkg_search_module(SDL2TTF REQUIRED SDL2_ttf>=2.0.0) #find_package(SDL2_ttf REQUIRED)
#include_directories(${SDL2TTF_INCLUDE_DIRS}) #target_link_libraries(${PROJECT_NAME} SDL2::TTF)
#target_link_libraries(${PROJECT_NAME} ${SDL2TTF_LIBRARIES})
# Add SDL2_net library
#find_package(SDL2_net REQUIRED)
#target_link_libraries(${PROJECT_NAME} SDL2::Net)
# Add SDL2_mixer library
#find_package(SDL2_mixer REQUIRED)
#target_link_libraries(${PROJECT_NAME} SDL2::Mixer)
# Add SDL2_gfx library # Add SDL2_gfx library
#pkg_search_module(SDL2GFX REQUIRED SDL2_gfx) #find_package(SDL2_gfx REQUIRED)
#include_directories(${SDL2GFX_INCLUDE_DIRS}) #target_link_libraries(${PROJECT_NAME} SDL2::GFX)
#target_link_libraries(${PROJECT_NAME} ${SDL2GFX_LIBRARIES})

View File

@@ -1,6 +1,6 @@
# Basic C SDL project # Basic C SDL2 project
This project is a basic C [SDL][] project that uses [CMake][] as a build system. This project is a basic C [SDL2][SDL] project that uses [CMake][] as a build system.
## Dependencies ## Dependencies
@@ -19,17 +19,19 @@ sudo apt install git build-essential pkg-config cmake cmake-data libsdl2-dev
- [SDL2_image][] library - [SDL2_image][] library
- [SDL2_ttf][] library - [SDL2_ttf][] library
- [SDL2_net][] library
- [SDL2_mixer][] library
- [SDL2_gfx][] library - [SDL2_gfx][] library
```sh ```sh
sudo apt install libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev sudo apt install libsdl2-image-dev libsdl2-ttf-dev libsdl2-net-dev libsdl2-mixer-dev libsdl2-gfx-dev
``` ```
## Build instructions ## Build instructions
```sh ```sh
# Clone this repo # Clone this repo
git clone https://gitlab.com/aminosbh/basic-c-sdl-project.git git clone --recurse-submodules https://gitlab.com/aminosbh/basic-c-sdl-project.git
cd basic-c-sdl-project cd basic-c-sdl-project
# Create a build folder # Create a build folder
@@ -44,8 +46,9 @@ make
./basic-c-sdl-project ./basic-c-sdl-project
``` ```
***Note:*** To use SDL2_image, SDL2_ttf or SDL2_gfx, you should uncomment ***Note:*** To use SDL2_image, SDL2_ttf, SDL2_net, SDL2_mixer or SDL2_gfx, you
some instructions in the CMakeLists.txt file and re-execute `cmake ..` and `make` should uncomment some instructions in the CMakeLists.txt file and re-execute
the `make` command.
### Open the project with an IDE under Linux ### Open the project with an IDE under Linux
@@ -65,4 +68,6 @@ This project is distributed under the terms of the MIT license
[Git]: https://git-scm.com [Git]: https://git-scm.com
[SDL2_image]: https://www.libsdl.org/projects/SDL_image [SDL2_image]: https://www.libsdl.org/projects/SDL_image
[SDL2_ttf]: https://www.libsdl.org/projects/SDL_ttf [SDL2_ttf]: https://www.libsdl.org/projects/SDL_ttf
[SDL2_net]: https://www.libsdl.org/projects/SDL_net
[SDL2_mixer]: https://www.libsdl.org/projects/SDL_mixer
[SDL2_gfx]: http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx [SDL2_gfx]: http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx