{"id":13620557,"url":"https://github.com/aminosbh/sdl2-cmake-modules","last_synced_at":"2025-04-14T21:31:33.553Z","repository":{"id":46085115,"uuid":"171045339","full_name":"aminosbh/sdl2-cmake-modules","owner":"aminosbh","description":"Modern CMake modules for finding and using the SDL2 library as well as other related libraries: SDL2_image, SDL2_ttf, SDL2_net, SDL2_mixer and SDL2_gfx. (Targets: SDL2::Core, SDL2::Main, SDL2::Image, SDL2::TTF, SDL2::Net, SDL2::Mixer and SDL2::GFX). Mirror of https://gitlab.com/aminosbh/sdl2-cmake-modules","archived":false,"fork":false,"pushed_at":"2022-09-10T10:47:34.000Z","size":36,"stargazers_count":353,"open_issues_count":5,"forks_count":58,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-01T21:44:37.764Z","etag":null,"topics":["cmake","cmake-modules","sdl2"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aminosbh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-16T19:53:50.000Z","updated_at":"2024-07-20T00:02:51.000Z","dependencies_parsed_at":"2023-01-18T03:00:27.730Z","dependency_job_id":null,"html_url":"https://github.com/aminosbh/sdl2-cmake-modules","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminosbh%2Fsdl2-cmake-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminosbh%2Fsdl2-cmake-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminosbh%2Fsdl2-cmake-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminosbh%2Fsdl2-cmake-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminosbh","download_url":"https://codeload.github.com/aminosbh/sdl2-cmake-modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223647988,"owners_count":17179364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cmake-modules","sdl2"],"created_at":"2024-08-01T21:00:57.145Z","updated_at":"2024-11-08T07:30:36.859Z","avatar_url":"https://github.com/aminosbh.png","language":"CMake","funding_links":[],"categories":["CMake"],"sub_categories":[],"readme":"# SDL2 CMake modules\n\nThis repository contains [CMake][] modules for finding and using the SDL2\nlibrary as well as other related libraries:\n\n- [SDL2][]\n- [SDL2_image][]\n- [SDL2_ttf][]\n- [SDL2_net][]\n- [SDL2_mixer][]\n- [SDL2_gfx][]\n\nThese modules are based on the SDL (1.2) modules, with the same names,\ndistributed with the CMake project. The SDL2_gfx module is also based\non the SDL_image module.\n\n## Details and Improvements\n\nThe improvements made to these modules are as follows:\n\n**FindSDL2.cmake**\n\n- Adapt `FindSDL.cmake` to `SDL2` (`FindSDL2.cmake`).\n- Add cache variables for more flexibility:\u003cbr\u003e\n    `SDL2_PATH`, `SDL2_NO_DEFAULT_PATH`\n- Mark `Threads` as a required dependency for non-OSX systems.\n- Modernize the `FindSDL2.cmake` module by creating specific targets:\n  - `SDL2::Core` : Library project should link to `SDL2::Core`\n  - `SDL2::Main` : Application project should link to `SDL2::Main`\n\n*For more details, please see the embedded documentation in `FindSDL2.cmake` file.*\n\n**FindSDL2_\u0026lt;COMPONENT\u0026gt;.cmake**\n\n- Adapt `FindSDL_\u003cCOMPONENT\u003e.cmake` to `SDL2_\u003cCOMPONENT\u003e` (`FindSDL2_\u003cCOMPONENT\u003e.cmake`).\n- Add cache variables for more flexibility:\u003cbr\u003e\n    `SDL2_\u003cCOMPONENT\u003e_PATH`, `SDL2_\u003cCOMPONENT\u003e_NO_DEFAULT_PATH`\n- Add `SDL2` as a required dependency.\n- Modernize the `FindSDL2_\u003cCOMPONENT\u003e.cmake` modules by creating specific targets:\u003cbr\u003e\n    `SDL2::Image`, `SDL2::TTF`, `SDL2::Net`, `SDL2::Mixer` and `SDL2::GFX`.\n\n*For more details, please see the embedded documentation in\n`FindSDL2_\u003cCOMPONENT\u003e.cmake` file.*\n\n## Usage\n\nIn order to use the SDL2 CMake modules, we have to clone this repository in a\nsud-directory `cmake/sdl2` in our project as follows:\n\n```sh\ncd \u003cPROJECT_DIR\u003e\ngit clone https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2\nrm -rf cmake/sdl2/.git\n```\n\nOr if we are using git for our project, we can add this repository as a\nsubmodule as follows:\n\n```sh\ncd \u003cPROJECT_DIR\u003e\ngit submodule add https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2\ngit commit -m \"Add SDL2 CMake modules\"\n```\n\nThen we should specify the modules path in the main CMakeLists.txt file like\nthe following:\n\n```cmake\nlist(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)\n```\n\nFinally, we can use the SDL2 modules. There is two approaches that can be\nadopted: A legacy approach and a modern approach. Both of them are supported.\n\n### Modern CMake\n\nWe can link to the SDL2:: targets like the following example:\u003cbr\u003e\n*This example requires the SDL2, SDL2_image and the SDL2_gfx libraries*\n\n```cmake\n# Find SDL2, SDL2_image and SDL2_gfx libraries\nfind_package(SDL2 REQUIRED)\nfind_package(SDL2_image REQUIRED)\nfind_package(SDL2_gfx REQUIRED)\n\n# Link SDL2::Main, SDL2::Image and SDL2::GFX to our project\ntarget_link_libraries(${PROJECT_NAME} SDL2::Main SDL2::Image SDL2::GFX)\n```\n\n*Use the appropriate packages for you project.*\u003cbr\u003e\n*Please see above, for the whole list of packages*\u003cbr\u003e\n*For more details, please see the embedded documentation in modules files*\n\n### Legacy CMake\n\nWe can also specify manually the include directories and libraries to link to:\n\n```cmake\n# Find and link SDL2\nfind_package(SDL2 REQUIRED)\ntarget_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIRS})\ntarget_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})\n\n# Find and link SDL2_image\nfind_package(SDL2_image REQUIRED)\ntarget_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS})\ntarget_link_libraries(${PROJECT_NAME} ${SDL2_IMAGE_LIBRARIES})\n\n# Find and link SDL2_gfx\nfind_package(SDL2_gfx REQUIRED)\ntarget_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_GFX_INCLUDE_DIRS})\ntarget_link_libraries(${PROJECT_NAME} ${SDL2_GFX_LIBRARIES})\n\n```\n\n*For more details, please see the embedded documentation in modules files*\n\n## Special customization variables\n\nEach module have special customization cache variables that can be used to help\nthe modules find the appropriate libraries:\n\n- `SDL2_PATH` and `SDL2_\u003cCOMPONENT\u003e_PATH`:\u003cbr\u003e\n  Can be specified to set the root search path for the `SDL2` and `SDL2_\u003cCOMPONENT\u003e`\n- `SDL2_NO_DEFAULT_PATH` and `SDL2_\u003cCOMPONENT\u003e_NO_DEFAULT_PATH`:\u003cbr\u003e\n  Disable search `SDL2/SDL2_\u003cCOMPONENT\u003e` library in default path:\u003cbr\u003e\n    If `SDL2[_\u003cCOMPONENT\u003e]_PATH` is set, defaults to ON\u003cbr\u003e\n    Else defaults to OFF\n- `SDL2_INCLUDE_DIR` and `SDL2_\u003cCOMPONENT\u003e_INCLUDE_DIR`:\u003cbr\u003e\n  Set headers path. (Override)\n- `SDL2_LIBRARY` and `SDL2_\u003cCOMPONENT\u003e_LIBRARY`:\u003cbr\u003e\n  Set the library (.dll, .so, .a, etc) path. (Override)\n- `SDL2MAIN_LIBRAY`:\u003cbr\u003e\n  Set the `SDL2main` library (.a) path. (Override)\n\nThese variables could be used in case of Windows projects, and when the\nlibraries are not localized in a standard pathes. They can be specified when\nexecuting the `cmake` command or when using the [CMake GUI][] (They are marked\nas advanced).\n\n**cmake command example:**\n\n```sh\nmkdir build\ncd build\ncmake .. -DSDL2_PATH=\"/path/to/sdl2\"\n```\n\n**CMakeLists.txt example:**\n\nIf we embed, for example, binaries of the SDL2_ttf in our project, we can\nspecify the cache variables values just before calling the `find_package`\ncommand as follows:\n\n```cmake\nset(SDL2_TTF_PATH \"/path/to/sdl2_ttf\" CACHE BOOL \"\" FORCE)\nfind_package(SDL2_ttf REQUIRED)\n```\n\n## License\n\nMaintainer: Amine B. Hassouna [@aminosbh](https://gitlab.com/aminosbh)\n\nThe SDL2 CMake modules are based on the SDL (1.2) modules available with the\nCMake project which is distributed under the OSI-approved BSD 3-Clause License.\n\nThe SDL2 CMake modules are also distributed under the OSI-approved BSD\n3-Clause License. See accompanying file [Copyright.txt](Copyright.txt).\n\n\n\n[CMake]: https://cmake.org\n[CMake GUI]: https://cmake.org/runningcmake\n[SDL2]: https://www.libsdl.org\n[SDL2_image]: https://www.libsdl.org/projects/SDL_image\n[SDL2_ttf]: https://www.libsdl.org/projects/SDL_ttf\n[SDL2_net]: https://www.libsdl.org/projects/SDL_net\n[SDL2_mixer]: https://www.libsdl.org/projects/SDL_mixer\n[SDL2_gfx]: http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminosbh%2Fsdl2-cmake-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminosbh%2Fsdl2-cmake-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminosbh%2Fsdl2-cmake-modules/lists"}