├── .gitignore ├── include └── .include_dir ├── assets └── tn.png ├── LICENSE ├── README.md ├── CMakeLists.txt ├── IDE_USAGE.md ├── rename_project.sh ├── cmake └── sdl2 │ ├── Copyright.txt │ ├── README.md │ ├── FindSDL2_net.cmake │ ├── FindSDL2_ttf.cmake │ ├── FindSDL2_gfx.cmake │ ├── FindSDL2_mixer.cmake │ ├── FindSDL2_image.cmake │ └── FindSDL2.cmake └── src └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | CMakeLists.txt.* 3 | -------------------------------------------------------------------------------- /include/.include_dir: -------------------------------------------------------------------------------- 1 | This is the include directory 2 | -------------------------------------------------------------------------------- /assets/tn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aminosbh/sdl2-image-sample/HEAD/assets/tn.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # MIT license 2 | 3 | Copyright (c) 2018, 2019 Amine Ben Hassouna 4 | All rights reserved. 5 | 6 | Permission is hereby granted, free of charge, to any 7 | person obtaining a copy of this software and associated 8 | documentation files (the "Software"), to deal in the 9 | Software without restriction, including without 10 | limitation the rights to use, copy, modify, merge, 11 | publish, distribute, sublicense, and/or sell copies of 12 | the Software, and to permit persons to whom the Software 13 | is furnished to do so, subject to the following 14 | conditions: 15 | 16 | The above copyright notice and this permission notice 17 | shall be included in all copies or substantial portions 18 | of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 21 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 22 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 23 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 24 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 27 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SDL2_image sample 2 | 3 | This project is a basic sample written in C that demonstrates the usage of the 4 | [SDL2][SDL] and [SDL2_image][] libraries. It uses [CMake][] as a build system. 5 | 6 | 7 | It could be used as a base for any SDL2 project. Just fork it, clone it and 8 | execute the `rename_project.sh` script. You will be prompted to enter the new 9 | project name, the new executable name and the new git repository, but you can 10 | keep the autodetected values. Finally, just commit and push the result to your 11 | repository. 12 | 13 | ## Dependencies 14 | 15 | - [Git][] 16 | - C Compiler (gcc, ...) 17 | - [CMake][] 18 | - [SDL2][SDL] library 19 | - [SDL2_image][] library 20 | 21 | **On Debian/Ubuntu based distributions, use the following command:** 22 | 23 | ```sh 24 | sudo apt install git build-essential pkg-config cmake cmake-data libsdl2-dev libsdl2-image-dev 25 | ``` 26 | 27 | **Optional packages:** 28 | 29 | - [SDL2_ttf][] library 30 | - [SDL2_net][] library 31 | - [SDL2_mixer][] library 32 | - [SDL2_gfx][] library 33 | 34 | ```sh 35 | sudo apt install libsdl2-ttf-dev libsdl2-net-dev libsdl2-mixer-dev libsdl2-gfx-dev 36 | ``` 37 | 38 | ## Build instructions 39 | 40 | ```sh 41 | # Clone this repo 42 | git clone https://gitlab.com/aminosbh/sdl2-image-sample.git 43 | cd sdl2-image-sample 44 | 45 | # Create a build folder 46 | mkdir build 47 | cd build 48 | 49 | # Build 50 | cmake .. 51 | make 52 | 53 | # Run 54 | ./sdl2-image-sample 55 | ``` 56 | 57 | ***Note:*** To use SDL2_ttf, SDL2_net, SDL2_mixer or SDL2_gfx, you should 58 | uncomment some instructions in the CMakeLists.txt file and re-execute the 59 | `make` command. 60 | 61 | ### Open the project with an IDE under Linux 62 | 63 | See [IDE_USAGE.md](IDE_USAGE.md) for details. 64 | 65 | ## License 66 | 67 | Author: Amine B. Hassouna [@aminosbh](https://gitlab.com/aminosbh) 68 | 69 | This project is distributed under the terms of the MIT license 70 | [<LICENSE>](LICENSE). 71 | 72 | 73 | 74 | [SDL]: https://www.libsdl.org 75 | [CMake]: https://cmake.org 76 | [Git]: https://git-scm.com 77 | [SDL2_image]: https://www.libsdl.org/projects/SDL_image 78 | [SDL2_ttf]: https://www.libsdl.org/projects/SDL_ttf 79 | [SDL2_net]: https://www.libsdl.org/projects/SDL_net 80 | [SDL2_mixer]: https://www.libsdl.org/projects/SDL_mixer 81 | [SDL2_gfx]: http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx 82 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018, 2019 Amine Ben Hassouna 3 | # 4 | # Permission is hereby granted, free of charge, to any 5 | # person obtaining a copy of this software and associated 6 | # documentation files (the "Software"), to deal in the 7 | # Software without restriction, including without 8 | # limitation the rights to use, copy, modify, merge, 9 | # publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software 11 | # is furnished to do so, subject to the following 12 | # conditions: 13 | # 14 | # The above copyright notice and this permission notice 15 | # shall be included in all copies or substantial portions 16 | # of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | # ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | # DEALINGS IN THE SOFTWARE. 27 | # 28 | 29 | # Define the project name 30 | project(sdl2-image-sample) 31 | 32 | # Set the cmake minimum version to 3.5.1 33 | cmake_minimum_required(VERSION 3.5.1) 34 | 35 | # Add SDL2 CMake modules 36 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) 37 | 38 | # Add all c source files under the src directory 39 | file(GLOB SOURCES "src/*.c") 40 | add_executable(${PROJECT_NAME} ${SOURCES}) 41 | 42 | # Add all headers files under the include directory 43 | target_include_directories(${PROJECT_NAME} PRIVATE include) 44 | 45 | # Add compiler errors/warnings flags 46 | target_compile_options(${PROJECT_NAME} PRIVATE $<$:/W4 /WX>) 47 | target_compile_options(${PROJECT_NAME} PRIVATE $<$>:-Wall -Wextra -pedantic -Werror>) 48 | 49 | 50 | # Add SDL2 library 51 | find_package(SDL2 REQUIRED) 52 | target_link_libraries(${PROJECT_NAME} SDL2::Main) 53 | 54 | # Add SDL2_image library 55 | find_package(SDL2_image REQUIRED) 56 | target_link_libraries(${PROJECT_NAME} SDL2::Image) 57 | 58 | # Add SDL2_ttf library 59 | #find_package(SDL2_ttf REQUIRED) 60 | #target_link_libraries(${PROJECT_NAME} SDL2::TTF) 61 | 62 | # Add SDL2_net library 63 | #find_package(SDL2_net REQUIRED) 64 | #target_link_libraries(${PROJECT_NAME} SDL2::Net) 65 | 66 | # Add SDL2_mixer library 67 | #find_package(SDL2_mixer REQUIRED) 68 | #target_link_libraries(${PROJECT_NAME} SDL2::Mixer) 69 | 70 | # Add SDL2_gfx library 71 | #find_package(SDL2_gfx REQUIRED) 72 | #target_link_libraries(${PROJECT_NAME} SDL2::GFX) 73 | 74 | # Copy assets 75 | file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}) 76 | -------------------------------------------------------------------------------- /IDE_USAGE.md: -------------------------------------------------------------------------------- 1 | # CMake sdl project - IDE usage 2 | 3 | There is many IDEs that support CMake projects. It could be natively or via plugins.
4 | This is a short tutorial on how we can use some IDEs to open a CMake project on linux: 5 | 6 | - [Qt Creator](#open-the-project-with-qt-creator) 7 | - [Code::Blocks](#open-the-project-with-codeblocks) 8 | - [Eclipse](#open-the-project-with-eclipse-cc) 9 | 10 | ## Open the project with Qt Creator 11 | 12 | [Qt Creator][] is a cross-platform C/C++ IDE, originally dedicated for the Qt framework. 13 | It handle natively CMake projects and provide an efficient code completion. 14 | 15 | *Install Qt creator:* 16 | 17 | Install from Debian/Ubuntu repo: 18 | 19 | ```sh 20 | sudo apt install qtcreator 21 | ``` 22 | 23 | Online installer: https://www.qt.io/download-thank-you?hsLang=en
24 | Offline installer: https://www.qt.io/offline-installers 25 | 26 | *Open the project:*
27 | Run Qt Creator, use `Open Files or Project ...` and select the `CMakeLists.txt` 28 | file of the cloned project.
29 | Finally, build and run the project. 30 | 31 | 32 | ## Open the project with Code::blocks 33 | 34 | [Code::Blocks][] is a well-known cross-platform C/C++ and Fortran IDE. 35 | It handle CMake projects by wrapping them into native Code::Blocks projects. 36 | 37 | *Install Code::Blocks* 38 | 39 | ```sh 40 | sudo apt install codeblocks 41 | ``` 42 | 43 | *Prepare the Code::Blocks project:* 44 | 45 | ```sh 46 | # Create a folder for the Code::Blocks project 47 | cd sdl2-image-sample 48 | mkdir -p build/codeblocks 49 | cd build/codeblocks 50 | 51 | # Generate a Code::Blocks project 52 | cmake ../.. -G "CodeBlocks - Unix Makefiles" 53 | ``` 54 | 55 | *Open the project:*
56 | Run Code::Blocks, and open the project in `sdl2-image-sample/build/codeblocks`.
57 | Finally, build and run the project. 58 | 59 | 60 | ## Open the project with Eclipse C/C++ 61 | 62 | [Eclipse][] is a well-known IDE, widely used in Java projects development, but 63 | it also supports other programming languages, like in this case C/C++. 64 | It handle CMake projects by wrapping them into native Eclipse projects. 65 | 66 | *Download Eclipse C/C++:* 67 | 68 | Online installer: https://www.eclipse.org/downloads
69 | Offline package: https://www.eclipse.org/downloads/packages 70 | 71 | *Prepare the Eclipse project:* 72 | 73 | ```sh 74 | # Create a folder for the Eclipse project outside this project 75 | cd sdl2-image-sample 76 | mkdir ../eclipse-sdl2-image-sample 77 | cd ../eclipse-sdl2-image-sample 78 | 79 | # Generate an Eclipse project 80 | cmake ../sdl2-image-sample -G "Eclipse CDT4 - Unix Makefiles" 81 | ``` 82 | *Open the project:*
83 | Run Eclipse, and open the project in `eclipse-sdl2-image-sample`.
84 | Create a new run configuration: Go to `Run` > `Run configurations` > 85 | `C\C++ Application` and specify the C/C++ Application using `Search Project...`
86 | Finally, build and run the project. 87 | 88 | 89 | 90 | [Qt Creator]: https://doc.qt.io/qtcreator 91 | [Code::Blocks]: http://www.codeblocks.org 92 | [Eclipse]: https://www.eclipse.org 93 | -------------------------------------------------------------------------------- /rename_project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright (c) 2019 Amine Ben Hassouna 5 | # 6 | # Permission is hereby granted, free of charge, to any 7 | # person obtaining a copy of this software and associated 8 | # documentation files (the "Software"), to deal in the 9 | # Software without restriction, including without 10 | # limitation the rights to use, copy, modify, merge, 11 | # publish, distribute, sublicense, and/or sell copies of 12 | # the Software, and to permit persons to whom the Software 13 | # is furnished to do so, subject to the following 14 | # conditions: 15 | # 16 | # The above copyright notice and this permission notice 17 | # shall be included in all copies or substantial portions 18 | # of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 21 | # ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 22 | # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 23 | # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 24 | # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 25 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 27 | # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | # DEALINGS IN THE SOFTWARE. 29 | # 30 | 31 | 32 | # ---------------------------- 33 | # Script to rename the project 34 | # ---------------------------- 35 | 36 | # Autodetect the git repository 37 | PROJECT_GIT_REPO_AUTO=$(git remote get-url origin 2> /dev/null) 38 | if echo "${PROJECT_GIT_REPO_AUTO}" | grep -o "^git@.*:" > /dev/null 2>&1; then 39 | # Convert to https 40 | PROJECT_GIT_REPO_AUTO_=$(echo "${PROJECT_GIT_REPO_AUTO}" | cut -d'@' -f 2) 41 | PROJECT_GIT_REPO_AUTO_HOST=$(echo "${PROJECT_GIT_REPO_AUTO_}" | cut -d':' -f 1) 42 | PROJECT_GIT_REPO_AUTO_PATH=$(echo "${PROJECT_GIT_REPO_AUTO_}" | cut -d':' -f 2) 43 | PROJECT_GIT_REPO_AUTO="https://${PROJECT_GIT_REPO_AUTO_HOST}/${PROJECT_GIT_REPO_AUTO_PATH}" 44 | fi 45 | 46 | # Specify the git repository 47 | echo "Please enter the git repository path (No semicolons):" 48 | echo -e "Press enter to keep the autodetected git repository:\n\e[32m${PROJECT_GIT_REPO_AUTO}\e[0m" 49 | read PROJECT_GIT_REPO 50 | if [ -z "$PROJECT_GIT_REPO" ]; then 51 | PROJECT_GIT_REPO="${PROJECT_GIT_REPO_AUTO}" 52 | fi 53 | echo 54 | 55 | 56 | # Autodetect the project and executable name 57 | PROJECT_EXECUTABLE_NAME_AUTO="$(echo "${PROJECT_GIT_REPO}" | rev | cut -d'/' -f 1 | rev | cut -d'.' -f 1)" 58 | PROJECT_NAME_AUTO=$(echo "${PROJECT_EXECUTABLE_NAME_AUTO}" | sed 's/-/ /g') 59 | PROJECT_NAME_AUTO="${PROJECT_NAME_AUTO^}" 60 | 61 | # Specify the project name 62 | echo "Please enter the project name (No slashes '/'):" 63 | echo -e "Press enter to keep the autodetected project name: \e[32m'${PROJECT_NAME_AUTO}'\e[0m" 64 | read PROJECT_NAME 65 | if [ -z "$PROJECT_NAME" ]; then 66 | PROJECT_NAME="${PROJECT_NAME_AUTO}" 67 | fi 68 | echo 69 | 70 | # Specify the executable name 71 | echo "Please enter the project executable name (No spaces, no slashes '/')" 72 | echo -e "Press enter to keep the autodetected executable name: \e[32m'${PROJECT_EXECUTABLE_NAME_AUTO}'\e[0m" 73 | read PROJECT_EXECUTABLE_NAME 74 | if [ -z "$PROJECT_EXECUTABLE_NAME" ]; then 75 | PROJECT_EXECUTABLE_NAME="${PROJECT_EXECUTABLE_NAME_AUTO}" 76 | fi 77 | echo 78 | 79 | 80 | # Display a summary for confirmation 81 | echo 82 | echo "This script will rename your project, like the following:" 83 | echo -e "Project git repository: \e[32m'${PROJECT_GIT_REPO}'\e[0m" 84 | echo -e "Project name: \e[32m'${PROJECT_NAME}'\e[0m" 85 | echo -e "Project executable name: \e[32m'${PROJECT_EXECUTABLE_NAME}'\e[0m" 86 | echo 87 | echo -e "\e[31mDo you confirm your modifications ? [y/N]\e[0m" 88 | read RENAME_PROJECT 89 | if [ -n "$RENAME_PROJECT" ] && [ "$(echo "$RENAME_PROJECT" | tr a-z A-Z)" = "Y" ]; then 90 | sed -i "s/SDL2_image sample/${PROJECT_NAME}/g" README.md rename_project.sh 91 | sed -i "s/sdl2-image-sample/${PROJECT_EXECUTABLE_NAME}/g" README.md IDE_USAGE.md CMakeLists.txt rename_project.sh 92 | sed -i "s;https://gitlab.com/aminosbh/sdl2-image-sample.git;${PROJECT_GIT_REPO};g" README.md rename_project.sh 93 | echo -e "\e[32mThe project was successfully renamed\e[0m" 94 | else 95 | echo -e "\e[33mOperation aborted\e[0m" 96 | fi 97 | 98 | -------------------------------------------------------------------------------- /cmake/sdl2/Copyright.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2019 Kitware, Inc. and Contributors 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Kitware, Inc. nor the names of Contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ------------------------------------------------------------------------------ 33 | 34 | The following individuals and institutions are among the Contributors: 35 | 36 | * Aaron C. Meadows 37 | * Adriaan de Groot 38 | * Aleksey Avdeev 39 | * Alexander Neundorf 40 | * Alexander Smorkalov 41 | * Alexey Sokolov 42 | * Alex Merry 43 | * Alex Turbov 44 | * Amine Ben Hassouna 45 | * Andreas Pakulat 46 | * Andreas Schneider 47 | * André Rigland Brodtkorb 48 | * Axel Huebl, Helmholtz-Zentrum Dresden - Rossendorf 49 | * Benjamin Eikel 50 | * Bjoern Ricks 51 | * Brad Hards 52 | * Christopher Harvey 53 | * Christoph Grüninger 54 | * Clement Creusot 55 | * Daniel Blezek 56 | * Daniel Pfeifer 57 | * Enrico Scholz 58 | * Eran Ifrah 59 | * Esben Mose Hansen, Ange Optimization ApS 60 | * Geoffrey Viola 61 | * Google Inc 62 | * Gregor Jasny 63 | * Helio Chissini de Castro 64 | * Ilya Lavrenov 65 | * Insight Software Consortium 66 | * Jan Woetzel 67 | * Julien Schueller 68 | * Kelly Thompson 69 | * Laurent Montel 70 | * Konstantin Podsvirov 71 | * Mario Bensi 72 | * Martin Gräßlin 73 | * Mathieu Malaterre 74 | * Matthaeus G. Chajdas 75 | * Matthias Kretz 76 | * Matthias Maennich 77 | * Michael Hirsch, Ph.D. 78 | * Michael Stürmer 79 | * Miguel A. Figueroa-Villanueva 80 | * Mike Jackson 81 | * Mike McQuaid 82 | * Nicolas Bock 83 | * Nicolas Despres 84 | * Nikita Krupen'ko 85 | * NVIDIA Corporation 86 | * OpenGamma Ltd. 87 | * Patrick Stotko 88 | * Per Øyvind Karlsen 89 | * Peter Collingbourne 90 | * Petr Gotthard 91 | * Philip Lowman 92 | * Philippe Proulx 93 | * Raffi Enficiaud, Max Planck Society 94 | * Raumfeld 95 | * Roger Leigh 96 | * Rolf Eike Beer 97 | * Roman Donchenko 98 | * Roman Kharitonov 99 | * Ruslan Baratov 100 | * Sebastian Holtermann 101 | * Stephen Kelly 102 | * Sylvain Joubert 103 | * Thomas Sondergaard 104 | * Tobias Hunger 105 | * Todd Gamblin 106 | * Tristan Carel 107 | * University of Dundee 108 | * Vadim Zhukov 109 | * Will Dicharry 110 | 111 | See version control history for details of individual contributions. 112 | 113 | The above copyright and license notice applies to distributions of 114 | CMake in source and binary form. Third-party software packages supplied 115 | with CMake under compatible licenses provide their own copyright notices 116 | documented in corresponding subdirectories or source files. 117 | 118 | ------------------------------------------------------------------------------ 119 | 120 | CMake was initially developed by Kitware with the following sponsorship: 121 | 122 | * National Library of Medicine at the National Institutes of Health 123 | as part of the Insight Segmentation and Registration Toolkit (ITK). 124 | 125 | * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel 126 | Visualization Initiative. 127 | 128 | * National Alliance for Medical Image Computing (NAMIC) is funded by the 129 | National Institutes of Health through the NIH Roadmap for Medical Research, 130 | Grant U54 EB005149. 131 | 132 | * Kitware, Inc. 133 | -------------------------------------------------------------------------------- /cmake/sdl2/README.md: -------------------------------------------------------------------------------- 1 | # SDL2 CMake modules 2 | 3 | This repository contains [CMake][] modules for finding and using the SDL2 4 | library as well as other related libraries: 5 | 6 | - [SDL2][] 7 | - [SDL2_image][] 8 | - [SDL2_ttf][] 9 | - [SDL2_net][] 10 | - [SDL2_mixer][] 11 | - [SDL2_gfx][] 12 | 13 | These modules are based on the SDL (1.2) modules, with the same names, 14 | distributed with the CMake project. The SDL2_gfx module is also based 15 | on the SDL_image module. 16 | 17 | ## Details and Improvements 18 | 19 | The improvements made to these modules are as follows: 20 | 21 | **FindSDL2.cmake** 22 | 23 | - Adapt `FindSDL.cmake` to `SDL2` (`FindSDL2.cmake`). 24 | - Add cache variables for more flexibility:
25 | `SDL2_PATH`, `SDL2_NO_DEFAULT_PATH` 26 | - Mark `Threads` as a required dependency for non-OSX systems. 27 | - Modernize the `FindSDL2.cmake` module by creating specific targets: 28 | - `SDL2::Core` : Library project should link to `SDL2::Core` 29 | - `SDL2::Main` : Application project should link to `SDL2::Main` 30 | 31 | *For more details, please see the embedded documentation in `FindSDL2.cmake` file.* 32 | 33 | **FindSDL2_<COMPONENT>.cmake** 34 | 35 | - Adapt `FindSDL_.cmake` to `SDL2_` (`FindSDL2_.cmake`). 36 | - Add cache variables for more flexibility:
37 | `SDL2__PATH`, `SDL2__NO_DEFAULT_PATH` 38 | - Add `SDL2` as a required dependency. 39 | - Modernize the `FindSDL2_.cmake` modules by creating specific targets:
40 | `SDL2::Image`, `SDL2::TTF`, `SDL2::Net`, `SDL2::Mixer` and `SDL2::GFX`. 41 | 42 | *For more details, please see the embedded documentation in 43 | `FindSDL2_.cmake` file.* 44 | 45 | ## Usage 46 | 47 | In order to use the SDL2 CMake modules, we have to clone this repository in a 48 | sud-directory `cmake/sdl2` in our project as follows: 49 | 50 | ```sh 51 | cd 52 | git clone https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2 53 | rm -rf cmake/sdl2/.git 54 | ``` 55 | 56 | Or if we are using git for our project, we can add this repository as a 57 | submodule as follows: 58 | 59 | ```sh 60 | cd 61 | git submodule add https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2 62 | git commit -m "Add SDL2 CMake modules" 63 | ``` 64 | 65 | Then we should specify the modules path in the main CMakeLists.txt file like 66 | the following: 67 | 68 | ```cmake 69 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) 70 | ``` 71 | 72 | Finally, we can use the SDL2 modules. There is two approaches that can be 73 | adopted: A legacy approach and a modern approach. Both of them are supported. 74 | 75 | ### Modern CMake 76 | 77 | We can link to the SDL2:: targets like the following example:
78 | *This example requires the SDL2, SDL2_image and the SDL2_gfx libraries* 79 | 80 | ```cmake 81 | # Find SDL2, SDL2_image and SDL2_gfx libraries 82 | find_package(SDL2 REQUIRED) 83 | find_package(SDL2_image REQUIRED) 84 | find_package(SDL2_gfx REQUIRED) 85 | 86 | # Link SDL2::Main, SDL2::Image and SDL2::GFX to our project 87 | target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2::Image SDL2::GFX) 88 | ``` 89 | 90 | *Use the appropriate packages for you project.*
91 | *Please see above, for the whole list of packages*
92 | *For more details, please see the embedded documentation in modules files* 93 | 94 | ### Legacy CMake 95 | 96 | We can also specify manually the include directories and libraries to link to: 97 | 98 | ```cmake 99 | # Find and link SDL2 100 | find_package(SDL2 REQUIRED) 101 | target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIRS}) 102 | target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES}) 103 | 104 | # Find and link SDL2_image 105 | find_package(SDL2_image REQUIRED) 106 | target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS}) 107 | target_link_libraries(${PROJECT_NAME} ${SDL2_IMAGE_LIBRARIES}) 108 | 109 | # Find and link SDL2_gfx 110 | find_package(SDL2_gfx REQUIRED) 111 | target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_GFX_INCLUDE_DIRS}) 112 | target_link_libraries(${PROJECT_NAME} ${SDL2_GFX_LIBRARIES}) 113 | 114 | ``` 115 | 116 | *For more details, please see the embedded documentation in modules files* 117 | 118 | ## Special customization variables 119 | 120 | Each module have special customization cache variables that can be used to help 121 | the modules find the appropriate libraries: 122 | 123 | - `SDL2_PATH` and `SDL2__PATH`:
124 | Can be specified to set the root search path for the `SDL2` and `SDL2_` 125 | - `SDL2_NO_DEFAULT_PATH` and `SDL2__NO_DEFAULT_PATH`:
126 | Disable search `SDL2/SDL2_` library in default path:
127 | If `SDL2[_]_PATH` is set, defaults to ON
128 | Else defaults to OFF 129 | - `SDL2_INCLUDE_DIR` and `SDL2__INCLUDE_DIR`:
130 | Set headers path. (Override) 131 | - `SDL2_LIBRARY` and `SDL2__LIBRARY`:
132 | Set the library (.dll, .so, .a, etc) path. (Override) 133 | - `SDL2MAIN_LIBRAY`:
134 | Set the `SDL2main` library (.a) path. (Override) 135 | 136 | These variables could be used in case of Windows projects, and when the 137 | libraries are not localized in a standard pathes. They can be specified when 138 | executing the `cmake` command or when using the [CMake GUI][] (They are marked 139 | as advanced). 140 | 141 | **cmake command example:** 142 | 143 | ```sh 144 | mkdir build 145 | cd build 146 | cmake .. -DSDL2_PATH="/path/to/sdl2" 147 | ``` 148 | 149 | **CMakeLists.txt example:** 150 | 151 | If we embed, for example, binaries of the SDL2_ttf in our project, we can 152 | specify the cache variables values just before calling the `find_package` 153 | command as follows: 154 | 155 | ```cmake 156 | set(SDL2_TTF_PATH "/path/to/sdl2_ttf" CACHE BOOL "" FORCE) 157 | find_package(SDL2_ttf REQUIRED) 158 | ``` 159 | 160 | ## License 161 | 162 | Maintainer: Amine B. Hassouna [@aminosbh](https://gitlab.com/aminosbh) 163 | 164 | The SDL2 CMake modules are based on the SDL (1.2) modules available with the 165 | CMake project which is distributed under the OSI-approved BSD 3-Clause License. 166 | 167 | The SDL2 CMake modules are also distributed under the OSI-approved BSD 168 | 3-Clause License. See accompanying file [Copyright.txt](Copyright.txt). 169 | 170 | 171 | 172 | [CMake]: https://cmake.org 173 | [CMake GUI]: https://cmake.org/runningcmake 174 | [SDL2]: https://www.libsdl.org 175 | [SDL2_image]: https://www.libsdl.org/projects/SDL_image 176 | [SDL2_ttf]: https://www.libsdl.org/projects/SDL_ttf 177 | [SDL2_net]: https://www.libsdl.org/projects/SDL_net 178 | [SDL2_mixer]: https://www.libsdl.org/projects/SDL_mixer 179 | [SDL2_gfx]: http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx 180 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, 2019 Amine Ben Hassouna 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any 6 | * person obtaining a copy of this software and associated 7 | * documentation files (the "Software"), to deal in the 8 | * Software without restriction, including without 9 | * limitation the rights to use, copy, modify, merge, 10 | * publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software 12 | * is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice 16 | * shall be included in all copies or substantial portions 17 | * of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 20 | * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 21 | * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 22 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 23 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 26 | * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | * DEALINGS IN THE SOFTWARE. 28 | * 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | // Define MAX and MIN macros 38 | #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) 39 | #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) 40 | 41 | // Define screen dimensions 42 | #define SCREEN_WIDTH 800 43 | #define SCREEN_HEIGHT 600 44 | 45 | // Define Tunisia flag image path 46 | #define TN_FLAG_IMAGE_PATH "assets/tn.png" 47 | 48 | int main(int argc, char* argv[]) 49 | { 50 | // Unused argc, argv 51 | (void) argc; 52 | (void) argv; 53 | 54 | // Initialize SDL2 55 | if(SDL_Init(SDL_INIT_VIDEO) < 0) 56 | { 57 | printf("SDL2 could not be initialized!\n" 58 | "SDL2 Error: %s\n", SDL_GetError()); 59 | return 0; 60 | } 61 | 62 | // Initialize SDL2_image 63 | int flags = IMG_INIT_PNG; // Can be: IMG_INIT_JPG | IMG_INIT_PNG 64 | if((IMG_Init(flags) & flags) != flags) { 65 | printf("SDL2_image could not be initialized with PNG support!\n" 66 | "SDL2_image Error: %s\n", IMG_GetError()); 67 | return 0; 68 | } 69 | 70 | #if defined linux && SDL_VERSION_ATLEAST(2, 0, 8) 71 | // Disable compositor bypass 72 | if(!SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0")) 73 | { 74 | printf("SDL can not disable compositor bypass!\n"); 75 | return 0; 76 | } 77 | #endif 78 | 79 | // Create window 80 | SDL_Window *window = SDL_CreateWindow("SDL2_image sample", 81 | SDL_WINDOWPOS_CENTERED, 82 | SDL_WINDOWPOS_CENTERED, 83 | SCREEN_WIDTH, SCREEN_HEIGHT, 84 | SDL_WINDOW_SHOWN); 85 | if(!window) 86 | { 87 | printf("Window could not be created!\n" 88 | "SDL_Error: %s\n", SDL_GetError()); 89 | } 90 | else 91 | { 92 | // Create renderer 93 | SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); 94 | if(!renderer) 95 | { 96 | printf("Renderer could not be created!\n" 97 | "SDL_Error: %s\n", SDL_GetError()); 98 | } 99 | else 100 | { 101 | // Load image from file 102 | SDL_Texture *flag = IMG_LoadTexture(renderer, TN_FLAG_IMAGE_PATH); 103 | if(!flag) 104 | { 105 | printf("Unable to load image '%s'!\n" 106 | "SDL_image Error: %s", TN_FLAG_IMAGE_PATH, IMG_GetError()); 107 | return false; 108 | } 109 | 110 | // Get dimensions 111 | int w, h; 112 | SDL_QueryTexture(flag, NULL, NULL, &w, &h); 113 | 114 | // Flag dimensions/position 115 | SDL_Rect flagRect; 116 | 117 | // Scale the flag dimensions to fit the screen 118 | if(w > h) { 119 | flagRect.w = SCREEN_WIDTH * 0.6; 120 | flagRect.h = h * flagRect.w / w; 121 | } else { 122 | flagRect.h = SCREEN_HEIGHT * 0.6; 123 | flagRect.w = w * flagRect.h / h; 124 | } 125 | 126 | // Flag position: In the middle of the screen 127 | flagRect.x = SCREEN_WIDTH / 2 - flagRect.w / 2; 128 | flagRect.y = SCREEN_HEIGHT / 2 - flagRect.h / 2; 129 | 130 | // Set the border size 131 | const int flagBorderSize = 5; 132 | 133 | // Declare rect of square 134 | SDL_Rect squareRect; 135 | 136 | // Square dimensions 137 | squareRect.w = flagRect.w + flagBorderSize * 2; 138 | squareRect.h = flagRect.h + flagBorderSize * 2; 139 | 140 | // Square position: 141 | squareRect.x = flagRect.x - flagBorderSize; 142 | squareRect.y = flagRect.y - flagBorderSize; 143 | 144 | 145 | // Event loop exit flag 146 | bool quit = false; 147 | 148 | // Event loop 149 | while(!quit) 150 | { 151 | SDL_Event e; 152 | 153 | // Wait indefinitely for the next available event 154 | SDL_WaitEvent(&e); 155 | 156 | // User requests quit 157 | if(e.type == SDL_QUIT) 158 | { 159 | quit = true; 160 | } 161 | 162 | // Initialize renderer color white for the background 163 | SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); 164 | 165 | // Clear screen 166 | SDL_RenderClear(renderer); 167 | 168 | // Set renderer color black to draw the square 169 | SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); 170 | 171 | // Draw filled square 172 | SDL_RenderFillRect(renderer, &squareRect); 173 | 174 | // Draw the tunisian flag 175 | SDL_RenderCopy(renderer, flag, NULL, &flagRect); 176 | 177 | // Update screen 178 | SDL_RenderPresent(renderer); 179 | } 180 | 181 | // Destroy renderer 182 | SDL_DestroyRenderer(renderer); 183 | } 184 | 185 | // Destroy window 186 | SDL_DestroyWindow(window); 187 | } 188 | 189 | // Quit SDL_image 190 | IMG_Quit(); 191 | 192 | // Quit SDL 193 | SDL_Quit(); 194 | 195 | return 0; 196 | } 197 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2_net.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_net 37 | ------------ 38 | 39 | Locate SDL2_net library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::Net 46 | The SDL2_net library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_NET_LIBRARIES, the name of the library to link against 56 | SDL2_NET_INCLUDE_DIRS, where to find the headers 57 | SDL2_NET_FOUND, if false, do not try to link against 58 | SDL2_NET_VERSION_STRING - human-readable string containing the 59 | version of SDL2_net 60 | 61 | 62 | 63 | This module responds to the following cache variables: 64 | 65 | :: 66 | 67 | SDL2_NET_PATH 68 | Set a custom SDL2_net Library path (default: empty) 69 | 70 | SDL2_NET_NO_DEFAULT_PATH 71 | Disable search SDL2_net Library in default path. 72 | If SDL2_NET_PATH (default: ON) 73 | Else (default: OFF) 74 | 75 | SDL2_NET_INCLUDE_DIR 76 | SDL2_net headers path. 77 | 78 | SDL2_NET_LIBRARY 79 | SDL2_net Library (.dll, .so, .a, etc) path. 80 | 81 | 82 | Additional Note: If you see an empty SDL2_NET_LIBRARY in your project 83 | configuration, it means CMake did not find your SDL2_net library 84 | (SDL2_net.dll, libsdl2_net.so, etc). Set SDL2_NET_LIBRARY to point 85 | to your SDL2_net library, and configure again. This value is used to 86 | generate the final SDL2_NET_LIBRARIES variable and the SDL2::Net target, 87 | but when this value is unset, SDL2_NET_LIBRARIES and SDL2::Net does not 88 | get created. 89 | 90 | 91 | $SDL2NETDIR is an environment variable that would correspond to the 92 | ./configure --prefix=$SDL2NETDIR used in building SDL2_net. 93 | 94 | $SDL2DIR is an environment variable that would correspond to the 95 | ./configure --prefix=$SDL2DIR used in building SDL2. 96 | 97 | 98 | 99 | Created by Amine Ben Hassouna: 100 | Adapt FindSDL_net.cmake to SDL2_net (FindSDL2_net.cmake). 101 | Add cache variables for more flexibility: 102 | SDL2_NET_PATH, SDL2_NET_NO_DEFAULT_PATH (for details, see doc above). 103 | Add SDL2 as a required dependency. 104 | Modernize the FindSDL2_net.cmake module by creating a specific target: 105 | SDL2::Net (for details, see doc above). 106 | 107 | Original FindSDL_net.cmake module: 108 | Created by Eric Wing. This was influenced by the FindSDL.cmake 109 | module, but with modifications to recognize OS X frameworks and 110 | additional Unix paths (FreeBSD, etc). 111 | #]=======================================================================] 112 | 113 | # SDL2 Library required 114 | find_package(SDL2 QUIET) 115 | if(NOT SDL2_FOUND) 116 | set(SDL2_NET_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_net).") 117 | if(SDL2_net_FIND_REQUIRED) 118 | message(FATAL_ERROR ${SDL2_NET_SDL2_NOT_FOUND}) 119 | else() 120 | if(NOT SDL2_net_FIND_QUIETLY) 121 | message(STATUS ${SDL2_NET_SDL2_NOT_FOUND}) 122 | endif() 123 | return() 124 | endif() 125 | unset(SDL2_NET_SDL2_NOT_FOUND) 126 | endif() 127 | 128 | 129 | # Define options for searching SDL2_net Library in a custom path 130 | 131 | set(SDL2_NET_PATH "" CACHE STRING "Custom SDL2_net Library path") 132 | 133 | set(_SDL2_NET_NO_DEFAULT_PATH OFF) 134 | if(SDL2_NET_PATH) 135 | set(_SDL2_NET_NO_DEFAULT_PATH ON) 136 | endif() 137 | 138 | set(SDL2_NET_NO_DEFAULT_PATH ${_SDL2_NET_NO_DEFAULT_PATH} 139 | CACHE BOOL "Disable search SDL2_net Library in default path") 140 | unset(_SDL2_NET_NO_DEFAULT_PATH) 141 | 142 | set(SDL2_NET_NO_DEFAULT_PATH_CMD) 143 | if(SDL2_NET_NO_DEFAULT_PATH) 144 | set(SDL2_NET_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 145 | endif() 146 | 147 | # Search for the SDL2_net include directory 148 | find_path(SDL2_NET_INCLUDE_DIR SDL_net.h 149 | HINTS 150 | ENV SDL2NETDIR 151 | ENV SDL2DIR 152 | ${SDL2_NET_NO_DEFAULT_PATH_CMD} 153 | PATH_SUFFIXES SDL2 154 | # path suffixes to search inside ENV{SDL2DIR} 155 | # and ENV{SDL2NETDIR} 156 | include/SDL2 include 157 | PATHS ${SDL2_NET_PATH} 158 | DOC "Where the SDL2_net headers can be found" 159 | ) 160 | 161 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 162 | set(VC_LIB_PATH_SUFFIX lib/x64) 163 | else() 164 | set(VC_LIB_PATH_SUFFIX lib/x86) 165 | endif() 166 | 167 | # Search for the SDL2_net library 168 | find_library(SDL2_NET_LIBRARY 169 | NAMES SDL2_net 170 | HINTS 171 | ENV SDL2NETDIR 172 | ENV SDL2DIR 173 | ${SDL2_NET_NO_DEFAULT_PATH_CMD} 174 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 175 | PATHS ${SDL2_NET_PATH} 176 | DOC "Where the SDL2_net Library can be found" 177 | ) 178 | 179 | # Read SDL2_net version 180 | if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h") 181 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$") 182 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$") 183 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$") 184 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MAJOR "${SDL2_NET_VERSION_MAJOR_LINE}") 185 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MINOR "${SDL2_NET_VERSION_MINOR_LINE}") 186 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_PATCH "${SDL2_NET_VERSION_PATCH_LINE}") 187 | set(SDL2_NET_VERSION_STRING ${SDL2_NET_VERSION_MAJOR}.${SDL2_NET_VERSION_MINOR}.${SDL2_NET_VERSION_PATCH}) 188 | unset(SDL2_NET_VERSION_MAJOR_LINE) 189 | unset(SDL2_NET_VERSION_MINOR_LINE) 190 | unset(SDL2_NET_VERSION_PATCH_LINE) 191 | unset(SDL2_NET_VERSION_MAJOR) 192 | unset(SDL2_NET_VERSION_MINOR) 193 | unset(SDL2_NET_VERSION_PATCH) 194 | endif() 195 | 196 | set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY}) 197 | set(SDL2_NET_INCLUDE_DIRS ${SDL2_NET_INCLUDE_DIR}) 198 | 199 | include(FindPackageHandleStandardArgs) 200 | 201 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_net 202 | REQUIRED_VARS SDL2_NET_LIBRARIES SDL2_NET_INCLUDE_DIRS 203 | VERSION_VAR SDL2_NET_VERSION_STRING) 204 | 205 | 206 | mark_as_advanced(SDL2_NET_PATH 207 | SDL2_NET_NO_DEFAULT_PATH 208 | SDL2_NET_LIBRARY 209 | SDL2_NET_INCLUDE_DIR) 210 | 211 | 212 | if(SDL2_NET_FOUND) 213 | 214 | # SDL2::Net target 215 | if(SDL2_NET_LIBRARY AND NOT TARGET SDL2::Net) 216 | add_library(SDL2::Net UNKNOWN IMPORTED) 217 | set_target_properties(SDL2::Net PROPERTIES 218 | IMPORTED_LOCATION "${SDL2_NET_LIBRARY}" 219 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_NET_INCLUDE_DIR}" 220 | INTERFACE_LINK_LIBRARIES SDL2::Core) 221 | endif() 222 | endif() 223 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2_ttf.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_ttf 37 | ------------ 38 | 39 | Locate SDL2_ttf library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::TTF 46 | The SDL2_ttf library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_TTF_LIBRARIES, the name of the library to link against 56 | SDL2_TTF_INCLUDE_DIRS, where to find the headers 57 | SDL2_TTF_FOUND, if false, do not try to link against 58 | SDL2_TTF_VERSION_STRING - human-readable string containing the 59 | version of SDL2_ttf 60 | 61 | 62 | 63 | This module responds to the following cache variables: 64 | 65 | :: 66 | 67 | SDL2_TTF_PATH 68 | Set a custom SDL2_ttf Library path (default: empty) 69 | 70 | SDL2_TTF_NO_DEFAULT_PATH 71 | Disable search SDL2_ttf Library in default path. 72 | If SDL2_TTF_PATH (default: ON) 73 | Else (default: OFF) 74 | 75 | SDL2_TTF_INCLUDE_DIR 76 | SDL2_ttf headers path. 77 | 78 | SDL2_TTF_LIBRARY 79 | SDL2_ttf Library (.dll, .so, .a, etc) path. 80 | 81 | 82 | Additional Note: If you see an empty SDL2_TTF_LIBRARY in your project 83 | configuration, it means CMake did not find your SDL2_ttf library 84 | (SDL2_ttf.dll, libsdl2_ttf.so, etc). Set SDL2_TTF_LIBRARY to point 85 | to your SDL2_ttf library, and configure again. This value is used to 86 | generate the final SDL2_TTF_LIBRARIES variable and the SDL2::TTF target, 87 | but when this value is unset, SDL2_TTF_LIBRARIES and SDL2::TTF does not 88 | get created. 89 | 90 | 91 | $SDL2TTFDIR is an environment variable that would correspond to the 92 | ./configure --prefix=$SDL2TTFDIR used in building SDL2_ttf. 93 | 94 | $SDL2DIR is an environment variable that would correspond to the 95 | ./configure --prefix=$SDL2DIR used in building SDL2. 96 | 97 | 98 | 99 | Created by Amine Ben Hassouna: 100 | Adapt FindSDL_ttf.cmake to SDL2_ttf (FindSDL2_ttf.cmake). 101 | Add cache variables for more flexibility: 102 | SDL2_TTF_PATH, SDL2_TTF_NO_DEFAULT_PATH (for details, see doc above). 103 | Add SDL2 as a required dependency. 104 | Modernize the FindSDL2_ttf.cmake module by creating a specific target: 105 | SDL2::TTF (for details, see doc above). 106 | 107 | Original FindSDL_ttf.cmake module: 108 | Created by Eric Wing. This was influenced by the FindSDL.cmake 109 | module, but with modifications to recognize OS X frameworks and 110 | additional Unix paths (FreeBSD, etc). 111 | #]=======================================================================] 112 | 113 | # SDL2 Library required 114 | find_package(SDL2 QUIET) 115 | if(NOT SDL2_FOUND) 116 | set(SDL2_TTF_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_ttf).") 117 | if(SDL2_ttf_FIND_REQUIRED) 118 | message(FATAL_ERROR ${SDL2_TTF_SDL2_NOT_FOUND}) 119 | else() 120 | if(NOT SDL2_ttf_FIND_QUIETLY) 121 | message(STATUS ${SDL2_TTF_SDL2_NOT_FOUND}) 122 | endif() 123 | return() 124 | endif() 125 | unset(SDL2_TTF_SDL2_NOT_FOUND) 126 | endif() 127 | 128 | 129 | # Define options for searching SDL2_ttf Library in a custom path 130 | 131 | set(SDL2_TTF_PATH "" CACHE STRING "Custom SDL2_ttf Library path") 132 | 133 | set(_SDL2_TTF_NO_DEFAULT_PATH OFF) 134 | if(SDL2_TTF_PATH) 135 | set(_SDL2_TTF_NO_DEFAULT_PATH ON) 136 | endif() 137 | 138 | set(SDL2_TTF_NO_DEFAULT_PATH ${_SDL2_TTF_NO_DEFAULT_PATH} 139 | CACHE BOOL "Disable search SDL2_ttf Library in default path") 140 | unset(_SDL2_TTF_NO_DEFAULT_PATH) 141 | 142 | set(SDL2_TTF_NO_DEFAULT_PATH_CMD) 143 | if(SDL2_TTF_NO_DEFAULT_PATH) 144 | set(SDL2_TTF_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 145 | endif() 146 | 147 | # Search for the SDL2_ttf include directory 148 | find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h 149 | HINTS 150 | ENV SDL2TTFDIR 151 | ENV SDL2DIR 152 | ${SDL2_TTF_NO_DEFAULT_PATH_CMD} 153 | PATH_SUFFIXES SDL2 154 | # path suffixes to search inside ENV{SDL2DIR} 155 | # and ENV{SDL2TTFDIR} 156 | include/SDL2 include 157 | PATHS ${SDL2_TTF_PATH} 158 | DOC "Where the SDL2_ttf headers can be found" 159 | ) 160 | 161 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 162 | set(VC_LIB_PATH_SUFFIX lib/x64) 163 | else() 164 | set(VC_LIB_PATH_SUFFIX lib/x86) 165 | endif() 166 | 167 | # Search for the SDL2_ttf library 168 | find_library(SDL2_TTF_LIBRARY 169 | NAMES SDL2_ttf 170 | HINTS 171 | ENV SDL2TTFDIR 172 | ENV SDL2DIR 173 | ${SDL2_TTF_NO_DEFAULT_PATH_CMD} 174 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 175 | PATHS ${SDL2_TTF_PATH} 176 | DOC "Where the SDL2_ttf Library can be found" 177 | ) 178 | 179 | # Read SDL2_ttf version 180 | if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") 181 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") 182 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") 183 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") 184 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") 185 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") 186 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") 187 | set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) 188 | unset(SDL2_TTF_VERSION_MAJOR_LINE) 189 | unset(SDL2_TTF_VERSION_MINOR_LINE) 190 | unset(SDL2_TTF_VERSION_PATCH_LINE) 191 | unset(SDL2_TTF_VERSION_MAJOR) 192 | unset(SDL2_TTF_VERSION_MINOR) 193 | unset(SDL2_TTF_VERSION_PATCH) 194 | endif() 195 | 196 | set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) 197 | set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) 198 | 199 | include(FindPackageHandleStandardArgs) 200 | 201 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf 202 | REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS 203 | VERSION_VAR SDL2_TTF_VERSION_STRING) 204 | 205 | 206 | mark_as_advanced(SDL2_TTF_PATH 207 | SDL2_TTF_NO_DEFAULT_PATH 208 | SDL2_TTF_LIBRARY 209 | SDL2_TTF_INCLUDE_DIR) 210 | 211 | 212 | if(SDL2_TTF_FOUND) 213 | 214 | # SDL2::TTF target 215 | if(SDL2_TTF_LIBRARY AND NOT TARGET SDL2::TTF) 216 | add_library(SDL2::TTF UNKNOWN IMPORTED) 217 | set_target_properties(SDL2::TTF PROPERTIES 218 | IMPORTED_LOCATION "${SDL2_TTF_LIBRARY}" 219 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_TTF_INCLUDE_DIR}" 220 | INTERFACE_LINK_LIBRARIES SDL2::Core) 221 | endif() 222 | endif() 223 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2_gfx.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_gfx 37 | -------------- 38 | 39 | Locate SDL2_gfx library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::GFX 46 | The SDL2_gfx library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_GFX_LIBRARIES, the name of the library to link against 56 | SDL2_GFX_INCLUDE_DIRS, where to find the headers 57 | SDL2_GFX_FOUND, if false, do not try to link against 58 | SDL2_GFX_VERSION_STRING - human-readable string containing the 59 | version of SDL2_gfx 60 | 61 | 62 | 63 | This module responds to the following cache variables: 64 | 65 | :: 66 | 67 | SDL2_GFX_PATH 68 | Set a custom SDL2_gfx Library path (default: empty) 69 | 70 | SDL2_GFX_NO_DEFAULT_PATH 71 | Disable search SDL2_gfx Library in default path. 72 | If SDL2_GFX_PATH (default: ON) 73 | Else (default: OFF) 74 | 75 | SDL2_GFX_INCLUDE_DIR 76 | SDL2_gfx headers path. 77 | 78 | SDL2_GFX_LIBRARY 79 | SDL2_gfx Library (.dll, .so, .a, etc) path. 80 | 81 | 82 | Additional Note: If you see an empty SDL2_GFX_LIBRARY in your project 83 | configuration, it means CMake did not find your SDL2_gfx library 84 | (SDL2_gfx.dll, libsdl2_gfx.so, etc). Set SDL2_GFX_LIBRARY to point 85 | to your SDL2_gfx library, and configure again. This value is used to 86 | generate the final SDL2_GFX_LIBRARIES variable and the SDL2::GFX target, 87 | but when this value is unset, SDL2_GFX_LIBRARIES and SDL2::GFX does not 88 | get created. 89 | 90 | 91 | $SDL2GFXDIR is an environment variable that would correspond to the 92 | ./configure --prefix=$SDL2GFXDIR used in building SDL2_gfx. 93 | 94 | $SDL2DIR is an environment variable that would correspond to the 95 | ./configure --prefix=$SDL2DIR used in building SDL2. 96 | 97 | 98 | 99 | Created by Amine Ben Hassouna: 100 | Adapt FindSDL_image.cmake to SDL2_gfx (FindSDL2_gfx.cmake). 101 | Add cache variables for more flexibility: 102 | SDL2_GFX_PATH, SDL2_GFX_NO_DEFAULT_PATH (for details, see doc above). 103 | Add SDL2 as a required dependency. 104 | Modernize the FindSDL2_gfx.cmake module by creating a specific target: 105 | SDL2::GFX (for details, see doc above). 106 | 107 | Original FindSDL_image.cmake module: 108 | Created by Eric Wing. This was influenced by the FindSDL.cmake 109 | module, but with modifications to recognize OS X frameworks and 110 | additional Unix paths (FreeBSD, etc). 111 | #]=======================================================================] 112 | 113 | # SDL2 Library required 114 | find_package(SDL2 QUIET) 115 | if(NOT SDL2_FOUND) 116 | set(SDL2_GFX_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_gfx).") 117 | if(SDL2_gfx_FIND_REQUIRED) 118 | message(FATAL_ERROR ${SDL2_GFX_SDL2_NOT_FOUND}) 119 | else() 120 | if(NOT SDL2_gfx_FIND_QUIETLY) 121 | message(STATUS ${SDL2_GFX_SDL2_NOT_FOUND}) 122 | endif() 123 | return() 124 | endif() 125 | unset(SDL2_GFX_SDL2_NOT_FOUND) 126 | endif() 127 | 128 | 129 | # Define options for searching SDL2_gfx Library in a custom path 130 | 131 | set(SDL2_GFX_PATH "" CACHE STRING "Custom SDL2_gfx Library path") 132 | 133 | set(_SDL2_GFX_NO_DEFAULT_PATH OFF) 134 | if(SDL2_GFX_PATH) 135 | set(_SDL2_GFX_NO_DEFAULT_PATH ON) 136 | endif() 137 | 138 | set(SDL2_GFX_NO_DEFAULT_PATH ${_SDL2_GFX_NO_DEFAULT_PATH} 139 | CACHE BOOL "Disable search SDL2_gfx Library in default path") 140 | unset(_SDL2_GFX_NO_DEFAULT_PATH) 141 | 142 | set(SDL2_GFX_NO_DEFAULT_PATH_CMD) 143 | if(SDL2_GFX_NO_DEFAULT_PATH) 144 | set(SDL2_GFX_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 145 | endif() 146 | 147 | # Search for the SDL2_gfx include directory 148 | find_path(SDL2_GFX_INCLUDE_DIR SDL2_gfxPrimitives.h 149 | HINTS 150 | ENV SDL2GFXDIR 151 | ENV SDL2DIR 152 | ${SDL2_GFX_NO_DEFAULT_PATH_CMD} 153 | PATH_SUFFIXES SDL2 154 | # path suffixes to search inside ENV{SDL2DIR} 155 | # and ENV{SDL2GFXDIR} 156 | include/SDL2 include 157 | PATHS ${SDL2_GFX_PATH} 158 | DOC "Where the SDL2_gfx headers can be found" 159 | ) 160 | 161 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 162 | set(VC_LIB_PATH_SUFFIX lib/x64) 163 | else() 164 | set(VC_LIB_PATH_SUFFIX lib/x86) 165 | endif() 166 | 167 | # Search for the SDL2_gfx library 168 | find_library(SDL2_GFX_LIBRARY 169 | NAMES SDL2_gfx 170 | HINTS 171 | ENV SDL2GFXDIR 172 | ENV SDL2DIR 173 | ${SDL2_GFX_NO_DEFAULT_PATH_CMD} 174 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 175 | PATHS ${SDL2_GFX_PATH} 176 | DOC "Where the SDL2_gfx Library can be found" 177 | ) 178 | 179 | # Read SDL2_gfx version 180 | if(SDL2_GFX_INCLUDE_DIR AND EXISTS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h") 181 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$") 182 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$") 183 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$") 184 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_MAJOR "${SDL2_GFX_VERSION_MAJOR_LINE}") 185 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_MINOR "${SDL2_GFX_VERSION_MINOR_LINE}") 186 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_PATCH "${SDL2_GFX_VERSION_PATCH_LINE}") 187 | set(SDL2_GFX_VERSION_STRING ${SDL2_GFX_VERSION_MAJOR}.${SDL2_GFX_VERSION_MINOR}.${SDL2_GFX_VERSION_PATCH}) 188 | unset(SDL2_GFX_VERSION_MAJOR_LINE) 189 | unset(SDL2_GFX_VERSION_MINOR_LINE) 190 | unset(SDL2_GFX_VERSION_PATCH_LINE) 191 | unset(SDL2_GFX_VERSION_MAJOR) 192 | unset(SDL2_GFX_VERSION_MINOR) 193 | unset(SDL2_GFX_VERSION_PATCH) 194 | endif() 195 | 196 | set(SDL2_GFX_LIBRARIES ${SDL2_GFX_LIBRARY}) 197 | set(SDL2_GFX_INCLUDE_DIRS ${SDL2_GFX_INCLUDE_DIR}) 198 | 199 | include(FindPackageHandleStandardArgs) 200 | 201 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_gfx 202 | REQUIRED_VARS SDL2_GFX_LIBRARIES SDL2_GFX_INCLUDE_DIRS 203 | VERSION_VAR SDL2_GFX_VERSION_STRING) 204 | 205 | 206 | mark_as_advanced(SDL2_GFX_PATH 207 | SDL2_GFX_NO_DEFAULT_PATH 208 | SDL2_GFX_LIBRARY 209 | SDL2_GFX_INCLUDE_DIR) 210 | 211 | 212 | if(SDL2_GFX_FOUND) 213 | 214 | # SDL2::GFX target 215 | if(SDL2_GFX_LIBRARY AND NOT TARGET SDL2::GFX) 216 | add_library(SDL2::GFX UNKNOWN IMPORTED) 217 | set_target_properties(SDL2::GFX PROPERTIES 218 | IMPORTED_LOCATION "${SDL2_GFX_LIBRARY}" 219 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_GFX_INCLUDE_DIR}" 220 | INTERFACE_LINK_LIBRARIES SDL2::Core) 221 | endif() 222 | endif() 223 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2_mixer.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_mixer 37 | -------------- 38 | 39 | Locate SDL2_mixer library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::Mixer 46 | The SDL2_mixer library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_MIXER_LIBRARIES, the name of the library to link against 56 | SDL2_MIXER_INCLUDE_DIRS, where to find the headers 57 | SDL2_MIXER_FOUND, if false, do not try to link against 58 | SDL2_MIXER_VERSION_STRING - human-readable string containing the 59 | version of SDL2_mixer 60 | 61 | This module responds to the following cache variables: 62 | 63 | :: 64 | 65 | SDL2_MIXER_PATH 66 | Set a custom SDL2_mixer Library path (default: empty) 67 | 68 | SDL2_MIXER_NO_DEFAULT_PATH 69 | Disable search SDL2_mixer Library in default path. 70 | If SDL2_MIXER_PATH (default: ON) 71 | Else (default: OFF) 72 | 73 | SDL2_MIXER_INCLUDE_DIR 74 | SDL2_mixer headers path. 75 | 76 | SDL2_MIXER_LIBRARY 77 | SDL2_mixer Library (.dll, .so, .a, etc) path. 78 | 79 | 80 | Additional Note: If you see an empty SDL2_MIXER_LIBRARY in your project 81 | configuration, it means CMake did not find your SDL2_mixer library 82 | (SDL2_mixer.dll, libsdl2_mixer.so, etc). Set SDL2_MIXER_LIBRARY to point 83 | to your SDL2_mixer library, and configure again. This value is used to 84 | generate the final SDL2_MIXER_LIBRARIES variable and the SDL2::Mixer target, 85 | but when this value is unset, SDL2_MIXER_LIBRARIES and SDL2::Mixer does not 86 | get created. 87 | 88 | 89 | $SDL2MIXERDIR is an environment variable that would correspond to the 90 | ./configure --prefix=$SDL2MIXERDIR used in building SDL2_mixer. 91 | 92 | $SDL2DIR is an environment variable that would correspond to the 93 | ./configure --prefix=$SDL2DIR used in building SDL2. 94 | 95 | 96 | 97 | Created by Amine Ben Hassouna: 98 | Adapt FindSDL_mixer.cmake to SDL2_mixer (FindSDL2_mixer.cmake). 99 | Add cache variables for more flexibility: 100 | SDL2_MIXER_PATH, SDL2_MIXER_NO_DEFAULT_PATH (for details, see doc above). 101 | Add SDL2 as a required dependency. 102 | Modernize the FindSDL2_mixer.cmake module by creating a specific target: 103 | SDL2::Mixer (for details, see doc above). 104 | 105 | Original FindSDL_mixer.cmake module: 106 | Created by Eric Wing. This was influenced by the FindSDL.cmake 107 | module, but with modifications to recognize OS X frameworks and 108 | additional Unix paths (FreeBSD, etc). 109 | #]=======================================================================] 110 | 111 | # SDL2 Library required 112 | find_package(SDL2 QUIET) 113 | if(NOT SDL2_FOUND) 114 | set(SDL2_MIXER_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_mixer).") 115 | if(SDL2_mixer_FIND_REQUIRED) 116 | message(FATAL_ERROR ${SDL2_MIXER_SDL2_NOT_FOUND}) 117 | else() 118 | if(NOT SDL2_mixer_FIND_QUIETLY) 119 | message(STATUS ${SDL2_MIXER_SDL2_NOT_FOUND}) 120 | endif() 121 | return() 122 | endif() 123 | unset(SDL2_MIXER_SDL2_NOT_FOUND) 124 | endif() 125 | 126 | 127 | # Define options for searching SDL2_mixer Library in a custom path 128 | 129 | set(SDL2_MIXER_PATH "" CACHE STRING "Custom SDL2_mixer Library path") 130 | 131 | set(_SDL2_MIXER_NO_DEFAULT_PATH OFF) 132 | if(SDL2_MIXER_PATH) 133 | set(_SDL2_MIXER_NO_DEFAULT_PATH ON) 134 | endif() 135 | 136 | set(SDL2_MIXER_NO_DEFAULT_PATH ${_SDL2_MIXER_NO_DEFAULT_PATH} 137 | CACHE BOOL "Disable search SDL2_mixer Library in default path") 138 | unset(_SDL2_MIXER_NO_DEFAULT_PATH) 139 | 140 | set(SDL2_MIXER_NO_DEFAULT_PATH_CMD) 141 | if(SDL2_MIXER_NO_DEFAULT_PATH) 142 | set(SDL2_MIXER_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 143 | endif() 144 | 145 | # Search for the SDL2_mixer include directory 146 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 147 | HINTS 148 | ENV SDL2MIXERDIR 149 | ENV SDL2DIR 150 | ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} 151 | PATH_SUFFIXES SDL2 152 | # path suffixes to search inside ENV{SDL2DIR} 153 | # and ENV{SDL2MIXERDIR} 154 | include/SDL2 include 155 | PATHS ${SDL2_MIXER_PATH} 156 | DOC "Where the SDL2_mixer headers can be found" 157 | ) 158 | 159 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 160 | set(VC_LIB_PATH_SUFFIX lib/x64) 161 | else() 162 | set(VC_LIB_PATH_SUFFIX lib/x86) 163 | endif() 164 | 165 | # Search for the SDL2_mixer library 166 | find_library(SDL2_MIXER_LIBRARY 167 | NAMES SDL2_mixer 168 | HINTS 169 | ENV SDL2MIXERDIR 170 | ENV SDL2DIR 171 | ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} 172 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 173 | PATHS ${SDL2_MIXER_PATH} 174 | DOC "Where the SDL2_mixer Library can be found" 175 | ) 176 | 177 | # Read SDL2_mixer version 178 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 179 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 180 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 181 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 182 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 183 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 184 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 185 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 186 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 187 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 188 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 189 | unset(SDL2_MIXER_VERSION_MAJOR) 190 | unset(SDL2_MIXER_VERSION_MINOR) 191 | unset(SDL2_MIXER_VERSION_PATCH) 192 | endif() 193 | 194 | set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) 195 | set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) 196 | 197 | include(FindPackageHandleStandardArgs) 198 | 199 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer 200 | REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS 201 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 202 | 203 | 204 | mark_as_advanced(SDL2_MIXER_PATH 205 | SDL2_MIXER_NO_DEFAULT_PATH 206 | SDL2_MIXER_LIBRARY 207 | SDL2_MIXER_INCLUDE_DIR) 208 | 209 | 210 | if(SDL2_MIXER_FOUND) 211 | 212 | # SDL2::Mixer target 213 | if(SDL2_MIXER_LIBRARY AND NOT TARGET SDL2::Mixer) 214 | add_library(SDL2::Mixer UNKNOWN IMPORTED) 215 | set_target_properties(SDL2::Mixer PROPERTIES 216 | IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}" 217 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" 218 | INTERFACE_LINK_LIBRARIES SDL2::Core) 219 | endif() 220 | endif() 221 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2_image.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2_image 37 | -------------- 38 | 39 | Locate SDL2_image library 40 | 41 | This module defines the following 'IMPORTED' target: 42 | 43 | :: 44 | 45 | SDL2::Image 46 | The SDL2_image library, if found. 47 | Have SDL2::Core as a link dependency. 48 | 49 | 50 | 51 | This module will set the following variables in your project: 52 | 53 | :: 54 | 55 | SDL2_IMAGE_LIBRARIES, the name of the library to link against 56 | SDL2_IMAGE_INCLUDE_DIRS, where to find the headers 57 | SDL2_IMAGE_FOUND, if false, do not try to link against 58 | SDL2_IMAGE_VERSION_STRING - human-readable string containing the 59 | version of SDL2_image 60 | 61 | 62 | 63 | This module responds to the following cache variables: 64 | 65 | :: 66 | 67 | SDL2_IMAGE_PATH 68 | Set a custom SDL2_image Library path (default: empty) 69 | 70 | SDL2_IMAGE_NO_DEFAULT_PATH 71 | Disable search SDL2_image Library in default path. 72 | If SDL2_IMAGE_PATH (default: ON) 73 | Else (default: OFF) 74 | 75 | SDL2_IMAGE_INCLUDE_DIR 76 | SDL2_image headers path. 77 | 78 | SDL2_IMAGE_LIBRARY 79 | SDL2_image Library (.dll, .so, .a, etc) path. 80 | 81 | 82 | Additional Note: If you see an empty SDL2_IMAGE_LIBRARY in your project 83 | configuration, it means CMake did not find your SDL2_image library 84 | (SDL2_image.dll, libsdl2_image.so, etc). Set SDL2_IMAGE_LIBRARY to point 85 | to your SDL2_image library, and configure again. This value is used to 86 | generate the final SDL2_IMAGE_LIBRARIES variable and the SDL2::Image target, 87 | but when this value is unset, SDL2_IMAGE_LIBRARIES and SDL2::Image does not 88 | get created. 89 | 90 | 91 | $SDL2IMAGEDIR is an environment variable that would correspond to the 92 | ./configure --prefix=$SDL2IMAGEDIR used in building SDL2_image. 93 | 94 | $SDL2DIR is an environment variable that would correspond to the 95 | ./configure --prefix=$SDL2DIR used in building SDL2. 96 | 97 | 98 | 99 | Created by Amine Ben Hassouna: 100 | Adapt FindSDL_image.cmake to SDL2_image (FindSDL2_image.cmake). 101 | Add cache variables for more flexibility: 102 | SDL2_IMAGE_PATH, SDL2_IMAGE_NO_DEFAULT_PATH (for details, see doc above). 103 | Add SDL2 as a required dependency. 104 | Modernize the FindSDL2_image.cmake module by creating a specific target: 105 | SDL2::Image (for details, see doc above). 106 | 107 | Original FindSDL_image.cmake module: 108 | Created by Eric Wing. This was influenced by the FindSDL.cmake 109 | module, but with modifications to recognize OS X frameworks and 110 | additional Unix paths (FreeBSD, etc). 111 | #]=======================================================================] 112 | 113 | # SDL2 Library required 114 | find_package(SDL2 QUIET) 115 | if(NOT SDL2_FOUND) 116 | set(SDL2_IMAGE_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_image).") 117 | if(SDL2_image_FIND_REQUIRED) 118 | message(FATAL_ERROR ${SDL2_IMAGE_SDL2_NOT_FOUND}) 119 | else() 120 | if(NOT SDL2_image_FIND_QUIETLY) 121 | message(STATUS ${SDL2_IMAGE_SDL2_NOT_FOUND}) 122 | endif() 123 | return() 124 | endif() 125 | unset(SDL2_IMAGE_SDL2_NOT_FOUND) 126 | endif() 127 | 128 | 129 | # Define options for searching SDL2_image Library in a custom path 130 | 131 | set(SDL2_IMAGE_PATH "" CACHE STRING "Custom SDL2_image Library path") 132 | 133 | set(_SDL2_IMAGE_NO_DEFAULT_PATH OFF) 134 | if(SDL2_IMAGE_PATH) 135 | set(_SDL2_IMAGE_NO_DEFAULT_PATH ON) 136 | endif() 137 | 138 | set(SDL2_IMAGE_NO_DEFAULT_PATH ${_SDL2_IMAGE_NO_DEFAULT_PATH} 139 | CACHE BOOL "Disable search SDL2_image Library in default path") 140 | unset(_SDL2_IMAGE_NO_DEFAULT_PATH) 141 | 142 | set(SDL2_IMAGE_NO_DEFAULT_PATH_CMD) 143 | if(SDL2_IMAGE_NO_DEFAULT_PATH) 144 | set(SDL2_IMAGE_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 145 | endif() 146 | 147 | # Search for the SDL2_image include directory 148 | find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h 149 | HINTS 150 | ENV SDL2IMAGEDIR 151 | ENV SDL2DIR 152 | ${SDL2_IMAGE_NO_DEFAULT_PATH_CMD} 153 | PATH_SUFFIXES SDL2 154 | # path suffixes to search inside ENV{SDL2DIR} 155 | # and ENV{SDL2IMAGEDIR} 156 | include/SDL2 include 157 | PATHS ${SDL2_IMAGE_PATH} 158 | DOC "Where the SDL2_image headers can be found" 159 | ) 160 | 161 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 162 | set(VC_LIB_PATH_SUFFIX lib/x64) 163 | else() 164 | set(VC_LIB_PATH_SUFFIX lib/x86) 165 | endif() 166 | 167 | # Search for the SDL2_image library 168 | find_library(SDL2_IMAGE_LIBRARY 169 | NAMES SDL2_image 170 | HINTS 171 | ENV SDL2IMAGEDIR 172 | ENV SDL2DIR 173 | ${SDL2_IMAGE_NO_DEFAULT_PATH_CMD} 174 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 175 | PATHS ${SDL2_IMAGE_PATH} 176 | DOC "Where the SDL2_image Library can be found" 177 | ) 178 | 179 | # Read SDL2_image version 180 | if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") 181 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") 182 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") 183 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") 184 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") 185 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") 186 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") 187 | set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) 188 | unset(SDL2_IMAGE_VERSION_MAJOR_LINE) 189 | unset(SDL2_IMAGE_VERSION_MINOR_LINE) 190 | unset(SDL2_IMAGE_VERSION_PATCH_LINE) 191 | unset(SDL2_IMAGE_VERSION_MAJOR) 192 | unset(SDL2_IMAGE_VERSION_MINOR) 193 | unset(SDL2_IMAGE_VERSION_PATCH) 194 | endif() 195 | 196 | set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) 197 | set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) 198 | 199 | include(FindPackageHandleStandardArgs) 200 | 201 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image 202 | REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS 203 | VERSION_VAR SDL2_IMAGE_VERSION_STRING) 204 | 205 | 206 | mark_as_advanced(SDL2_IMAGE_PATH 207 | SDL2_IMAGE_NO_DEFAULT_PATH 208 | SDL2_IMAGE_LIBRARY 209 | SDL2_IMAGE_INCLUDE_DIR) 210 | 211 | 212 | if(SDL2_IMAGE_FOUND) 213 | 214 | # SDL2::Image target 215 | if(SDL2_IMAGE_LIBRARY AND NOT TARGET SDL2::Image) 216 | add_library(SDL2::Image UNKNOWN IMPORTED) 217 | set_target_properties(SDL2::Image PROPERTIES 218 | IMPORTED_LOCATION "${SDL2_IMAGE_LIBRARY}" 219 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_IMAGE_INCLUDE_DIR}" 220 | INTERFACE_LINK_LIBRARIES SDL2::Core) 221 | endif() 222 | endif() 223 | -------------------------------------------------------------------------------- /cmake/sdl2/FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | # Copyright 2019 Amine Ben Hassouna 5 | # Copyright 2000-2019 Kitware, Inc. and Contributors 6 | # All rights reserved. 7 | 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | 15 | # * Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | 19 | # * Neither the name of Kitware, Inc. nor the names of Contributors 20 | # may be used to endorse or promote products derived from this 21 | # software without specific prior written permission. 22 | 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #[=======================================================================[.rst: 36 | FindSDL2 37 | -------- 38 | 39 | Locate SDL2 library 40 | 41 | This module defines the following 'IMPORTED' targets: 42 | 43 | :: 44 | 45 | SDL2::Core 46 | The SDL2 library, if found. 47 | Libraries should link to SDL2::Core 48 | 49 | SDL2::Main 50 | The SDL2main library, if found. 51 | Applications should link to SDL2::Main instead of SDL2::Core 52 | 53 | 54 | 55 | This module will set the following variables in your project: 56 | 57 | :: 58 | 59 | SDL2_LIBRARIES, the name of the library to link against 60 | SDL2_INCLUDE_DIRS, where to find SDL.h 61 | SDL2_FOUND, if false, do not try to link to SDL2 62 | SDL2MAIN_FOUND, if false, do not try to link to SDL2main 63 | SDL2_VERSION_STRING, human-readable string containing the version of SDL2 64 | 65 | 66 | 67 | This module responds to the following cache variables: 68 | 69 | :: 70 | 71 | SDL2_PATH 72 | Set a custom SDL2 Library path (default: empty) 73 | 74 | SDL2_NO_DEFAULT_PATH 75 | Disable search SDL2 Library in default path. 76 | If SDL2_PATH (default: ON) 77 | Else (default: OFF) 78 | 79 | SDL2_INCLUDE_DIR 80 | SDL2 headers path. 81 | 82 | SDL2_LIBRARY 83 | SDL2 Library (.dll, .so, .a, etc) path. 84 | 85 | SDL2MAIN_LIBRAY 86 | SDL2main Library (.a) path. 87 | 88 | SDL2_BUILDING_LIBRARY 89 | This flag is useful only when linking to SDL2_LIBRARIES insead of 90 | SDL2::Main. It is required only when building a library that links to 91 | SDL2_LIBRARIES, because only applications need main() (No need to also 92 | link to SDL2main). 93 | If this flag is defined, then no SDL2main will be added to SDL2_LIBRARIES 94 | and no SDL2::Main target will be created. 95 | 96 | 97 | Don't forget to include SDLmain.h and SDLmain.m in your project for the 98 | OS X framework based version. (Other versions link to -lSDL2main which 99 | this module will try to find on your behalf.) Also for OS X, this 100 | module will automatically add the -framework Cocoa on your behalf. 101 | 102 | 103 | Additional Note: If you see an empty SDL2_LIBRARY in your project 104 | configuration, it means CMake did not find your SDL2 library 105 | (SDL2.dll, libsdl2.so, SDL2.framework, etc). Set SDL2_LIBRARY to point 106 | to your SDL2 library, and configure again. Similarly, if you see an 107 | empty SDL2MAIN_LIBRARY, you should set this value as appropriate. These 108 | values are used to generate the final SDL2_LIBRARIES variable and the 109 | SDL2::Core and SDL2::Main targets, but when these values are unset, 110 | SDL2_LIBRARIES, SDL2::Core and SDL2::Main does not get created. 111 | 112 | 113 | $SDL2DIR is an environment variable that would correspond to the 114 | ./configure --prefix=$SDL2DIR used in building SDL2. l.e.galup 9-20-02 115 | 116 | 117 | 118 | Created by Amine Ben Hassouna: 119 | Adapt FindSDL.cmake to SDL2 (FindSDL2.cmake). 120 | Add cache variables for more flexibility: 121 | SDL2_PATH, SDL2_NO_DEFAULT_PATH (for details, see doc above). 122 | Mark 'Threads' as a required dependency for non-OSX systems. 123 | Modernize the FindSDL2.cmake module by creating specific targets: 124 | SDL2::Core and SDL2::Main (for details, see doc above). 125 | 126 | 127 | Original FindSDL.cmake module: 128 | Modified by Eric Wing. Added code to assist with automated building 129 | by using environmental variables and providing a more 130 | controlled/consistent search behavior. Added new modifications to 131 | recognize OS X frameworks and additional Unix paths (FreeBSD, etc). 132 | Also corrected the header search path to follow "proper" SDL 133 | guidelines. Added a search for SDLmain which is needed by some 134 | platforms. Added a search for threads which is needed by some 135 | platforms. Added needed compile switches for MinGW. 136 | 137 | On OSX, this will prefer the Framework version (if found) over others. 138 | People will have to manually change the cache value of SDL2_LIBRARY to 139 | override this selection or set the SDL2_PATH variable or the CMake 140 | environment CMAKE_INCLUDE_PATH to modify the search paths. 141 | 142 | Note that the header path has changed from SDL/SDL.h to just SDL.h 143 | This needed to change because "proper" SDL convention is #include 144 | "SDL.h", not . This is done for portability reasons 145 | because not all systems place things in SDL/ (see FreeBSD). 146 | #]=======================================================================] 147 | 148 | # Define options for searching SDL2 Library in a custom path 149 | 150 | set(SDL2_PATH "" CACHE STRING "Custom SDL2 Library path") 151 | 152 | set(_SDL2_NO_DEFAULT_PATH OFF) 153 | if(SDL2_PATH) 154 | set(_SDL2_NO_DEFAULT_PATH ON) 155 | endif() 156 | 157 | set(SDL2_NO_DEFAULT_PATH ${_SDL2_NO_DEFAULT_PATH} 158 | CACHE BOOL "Disable search SDL2 Library in default path") 159 | unset(_SDL2_NO_DEFAULT_PATH) 160 | 161 | set(SDL2_NO_DEFAULT_PATH_CMD) 162 | if(SDL2_NO_DEFAULT_PATH) 163 | set(SDL2_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) 164 | endif() 165 | 166 | # Search for the SDL2 include directory 167 | find_path(SDL2_INCLUDE_DIR SDL.h 168 | HINTS 169 | ENV SDL2DIR 170 | ${SDL2_NO_DEFAULT_PATH_CMD} 171 | PATH_SUFFIXES SDL2 172 | # path suffixes to search inside ENV{SDL2DIR} 173 | include/SDL2 include 174 | PATHS ${SDL2_PATH} 175 | DOC "Where the SDL2 headers can be found" 176 | ) 177 | 178 | set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}") 179 | 180 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 181 | set(VC_LIB_PATH_SUFFIX lib/x64) 182 | else() 183 | set(VC_LIB_PATH_SUFFIX lib/x86) 184 | endif() 185 | 186 | # SDL-2.0 is the name used by FreeBSD ports... 187 | # don't confuse it for the version number. 188 | find_library(SDL2_LIBRARY 189 | NAMES SDL2 SDL-2.0 190 | HINTS 191 | ENV SDL2DIR 192 | ${SDL2_NO_DEFAULT_PATH_CMD} 193 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 194 | PATHS ${SDL2_PATH} 195 | DOC "Where the SDL2 Library can be found" 196 | ) 197 | 198 | set(SDL2_LIBRARIES "${SDL2_LIBRARY}") 199 | 200 | if(NOT SDL2_BUILDING_LIBRARY) 201 | if(NOT SDL2_INCLUDE_DIR MATCHES ".framework") 202 | # Non-OS X framework versions expect you to also dynamically link to 203 | # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms 204 | # seem to provide SDL2main for compatibility even though they don't 205 | # necessarily need it. 206 | 207 | if(SDL2_PATH) 208 | set(SDL2MAIN_LIBRARY_PATHS "${SDL2_PATH}") 209 | endif() 210 | 211 | if(NOT SDL2_NO_DEFAULT_PATH) 212 | set(SDL2MAIN_LIBRARY_PATHS 213 | /sw 214 | /opt/local 215 | /opt/csw 216 | /opt 217 | "${SDL2MAIN_LIBRARY_PATHS}" 218 | ) 219 | endif() 220 | 221 | find_library(SDL2MAIN_LIBRARY 222 | NAMES SDL2main 223 | HINTS 224 | ENV SDL2DIR 225 | ${SDL2_NO_DEFAULT_PATH_CMD} 226 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 227 | PATHS ${SDL2MAIN_LIBRARY_PATHS} 228 | DOC "Where the SDL2main library can be found" 229 | ) 230 | unset(SDL2MAIN_LIBRARY_PATHS) 231 | endif() 232 | endif() 233 | 234 | # SDL2 may require threads on your system. 235 | # The Apple build may not need an explicit flag because one of the 236 | # frameworks may already provide it. 237 | # But for non-OSX systems, I will use the CMake Threads package. 238 | if(NOT APPLE) 239 | find_package(Threads QUIET) 240 | if(NOT Threads_FOUND) 241 | set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).") 242 | if(SDL2_FIND_REQUIRED) 243 | message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND}) 244 | else() 245 | if(NOT SDL2_FIND_QUIETLY) 246 | message(STATUS ${SDL2_THREADS_NOT_FOUND}) 247 | endif() 248 | return() 249 | endif() 250 | unset(SDL2_THREADS_NOT_FOUND) 251 | endif() 252 | endif() 253 | 254 | # MinGW needs an additional link flag, -mwindows 255 | # It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows 256 | if(MINGW) 257 | set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "link flags for MinGW") 258 | endif() 259 | 260 | if(SDL2_LIBRARY) 261 | # For SDL2main 262 | if(SDL2MAIN_LIBRARY AND NOT SDL2_BUILDING_LIBRARY) 263 | list(FIND SDL2_LIBRARIES "${SDL2MAIN_LIBRARY}" _SDL2_MAIN_INDEX) 264 | if(_SDL2_MAIN_INDEX EQUAL -1) 265 | set(SDL2_LIBRARIES "${SDL2MAIN_LIBRARY}" ${SDL2_LIBRARIES}) 266 | endif() 267 | unset(_SDL2_MAIN_INDEX) 268 | endif() 269 | 270 | # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. 271 | # CMake doesn't display the -framework Cocoa string in the UI even 272 | # though it actually is there if I modify a pre-used variable. 273 | # I think it has something to do with the CACHE STRING. 274 | # So I use a temporary variable until the end so I can set the 275 | # "real" variable in one-shot. 276 | if(APPLE) 277 | set(SDL2_LIBRARIES ${SDL2_LIBRARIES} -framework Cocoa) 278 | endif() 279 | 280 | # For threads, as mentioned Apple doesn't need this. 281 | # In fact, there seems to be a problem if I used the Threads package 282 | # and try using this line, so I'm just skipping it entirely for OS X. 283 | if(NOT APPLE) 284 | set(SDL2_LIBRARIES ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 285 | endif() 286 | 287 | # For MinGW library 288 | if(MINGW) 289 | set(SDL2_LIBRARIES ${MINGW32_LIBRARY} ${SDL2_LIBRARIES}) 290 | endif() 291 | 292 | endif() 293 | 294 | # Read SDL2 version 295 | if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") 296 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") 297 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") 298 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") 299 | string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") 300 | string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") 301 | string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") 302 | set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) 303 | unset(SDL2_VERSION_MAJOR_LINE) 304 | unset(SDL2_VERSION_MINOR_LINE) 305 | unset(SDL2_VERSION_PATCH_LINE) 306 | unset(SDL2_VERSION_MAJOR) 307 | unset(SDL2_VERSION_MINOR) 308 | unset(SDL2_VERSION_PATCH) 309 | endif() 310 | 311 | include(FindPackageHandleStandardArgs) 312 | 313 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 314 | REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR 315 | VERSION_VAR SDL2_VERSION_STRING) 316 | 317 | if(SDL2MAIN_LIBRARY) 318 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2main 319 | REQUIRED_VARS SDL2MAIN_LIBRARY SDL2_INCLUDE_DIR 320 | VERSION_VAR SDL2_VERSION_STRING) 321 | endif() 322 | 323 | 324 | mark_as_advanced(SDL2_PATH 325 | SDL2_NO_DEFAULT_PATH 326 | SDL2_LIBRARY 327 | SDL2MAIN_LIBRARY 328 | SDL2_INCLUDE_DIR 329 | SDL2_BUILDING_LIBRARY) 330 | 331 | 332 | # SDL2:: targets (SDL2::Core and SDL2::Main) 333 | if(SDL2_FOUND) 334 | 335 | # SDL2::Core target 336 | if(SDL2_LIBRARY AND NOT TARGET SDL2::Core) 337 | add_library(SDL2::Core UNKNOWN IMPORTED) 338 | set_target_properties(SDL2::Core PROPERTIES 339 | IMPORTED_LOCATION "${SDL2_LIBRARY}" 340 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}") 341 | 342 | if(APPLE) 343 | # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. 344 | # For more details, please see above. 345 | set_property(TARGET SDL2::Core APPEND PROPERTY 346 | INTERFACE_LINK_OPTIONS -framework Cocoa) 347 | else() 348 | # For threads, as mentioned Apple doesn't need this. 349 | # For more details, please see above. 350 | set_property(TARGET SDL2::Core APPEND PROPERTY 351 | INTERFACE_LINK_LIBRARIES Threads::Threads) 352 | endif() 353 | endif() 354 | 355 | # SDL2::Main target 356 | # Applications should link to SDL2::Main instead of SDL2::Core 357 | # For more details, please see above. 358 | if(NOT SDL2_BUILDING_LIBRARY AND NOT TARGET SDL2::Main) 359 | 360 | if(SDL2_INCLUDE_DIR MATCHES ".framework" OR NOT SDL2MAIN_LIBRARY) 361 | add_library(SDL2::Main INTERFACE IMPORTED) 362 | set_property(TARGET SDL2::Main PROPERTY 363 | INTERFACE_LINK_LIBRARIES SDL2::Core) 364 | elseif(SDL2MAIN_LIBRARY) 365 | # MinGW requires that the mingw32 library is specified before the 366 | # libSDL2main.a static library when linking. 367 | # The SDL2::MainInternal target is used internally to make sure that 368 | # CMake respects this condition. 369 | add_library(SDL2::MainInternal UNKNOWN IMPORTED) 370 | set_property(TARGET SDL2::MainInternal PROPERTY 371 | IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}") 372 | set_property(TARGET SDL2::MainInternal PROPERTY 373 | INTERFACE_LINK_LIBRARIES SDL2::Core) 374 | 375 | add_library(SDL2::Main INTERFACE IMPORTED) 376 | 377 | if(MINGW) 378 | # MinGW needs an additional link flag '-mwindows' and link to mingw32 379 | set_property(TARGET SDL2::Main PROPERTY 380 | INTERFACE_LINK_LIBRARIES "mingw32" "-mwindows") 381 | endif() 382 | 383 | set_property(TARGET SDL2::Main APPEND PROPERTY 384 | INTERFACE_LINK_LIBRARIES SDL2::MainInternal) 385 | endif() 386 | 387 | endif() 388 | endif() 389 | --------------------------------------------------------------------------------