From 40f9d234ca14aad976b81e21066994591c25aa4e Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Mon, 4 Feb 2019 00:06:04 +0100 Subject: [PATCH] Modernize CMakeList.txt --- CMakeLists.txt | 38 +++++++++++++++++++++----------------- README.md | 17 +++++++++++------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5aada1..cf15d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 Amine Ben Hassouna +# Copyright (c) 2018, 2019 Amine Ben Hassouna # # Permission is hereby granted, free of charge, to any # 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 cmake_minimum_required(VERSION 3.5.1) -# Add all headers files under the include directory -include_directories(include) +# Add SDL2 CMake modules +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) # Add all c source files under the src directory file(GLOB SOURCES "src/*.c") add_executable(${PROJECT_NAME} ${SOURCES}) -# Load CMake module : FindPkgConfig -include(FindPkgConfig) +# Add all headers files under the include directory +target_include_directories(${PROJECT_NAME} PRIVATE include) # Add SDL2 library -pkg_search_module(SDL2 REQUIRED sdl2) -include_directories(${SDL2_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES}) +find_package(SDL2 REQUIRED) +target_link_libraries(${PROJECT_NAME} SDL2::Main) # Add SDL2_image library -#pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0) -#include_directories(${SDL2IMAGE_INCLUDE_DIRS}) -#target_link_libraries(${PROJECT_NAME} ${SDL2IMAGE_LIBRARIES}) +#find_package(SDL2_image REQUIRED) +#target_link_libraries(${PROJECT_NAME} SDL2::Image) # Add SDL2_ttf library -#pkg_search_module(SDL2TTF REQUIRED SDL2_ttf>=2.0.0) -#include_directories(${SDL2TTF_INCLUDE_DIRS}) -#target_link_libraries(${PROJECT_NAME} ${SDL2TTF_LIBRARIES}) +#find_package(SDL2_ttf REQUIRED) +#target_link_libraries(${PROJECT_NAME} SDL2::TTF) + +# 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 -#pkg_search_module(SDL2GFX REQUIRED SDL2_gfx) -#include_directories(${SDL2GFX_INCLUDE_DIRS}) -#target_link_libraries(${PROJECT_NAME} ${SDL2GFX_LIBRARIES}) +#find_package(SDL2_gfx REQUIRED) +#target_link_libraries(${PROJECT_NAME} SDL2::GFX) diff --git a/README.md b/README.md index ba42001..1e7abd5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -19,17 +19,19 @@ sudo apt install git build-essential pkg-config cmake cmake-data libsdl2-dev - [SDL2_image][] library - [SDL2_ttf][] library +- [SDL2_net][] library +- [SDL2_mixer][] library - [SDL2_gfx][] library ```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 ```sh # 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 # Create a build folder @@ -44,8 +46,9 @@ make ./basic-c-sdl-project ``` -***Note:*** To use SDL2_image, SDL2_ttf or SDL2_gfx, you should uncomment -some instructions in the CMakeLists.txt file and re-execute `cmake ..` and `make` +***Note:*** To use SDL2_image, SDL2_ttf, SDL2_net, SDL2_mixer or SDL2_gfx, you +should uncomment some instructions in the CMakeLists.txt file and re-execute +the `make` command. ### 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 [SDL2_image]: https://www.libsdl.org/projects/SDL_image [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