From ca80e4cf7be86180ca55c58e70c20d1337ec4512 Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 3 Feb 2019 23:13:07 +0100 Subject: [PATCH 1/6] Adapt SDL2 modules for usage outside CMake repo --- FindSDL2.cmake | 2 +- FindSDL2_gfx.cmake | 2 +- FindSDL2_image.cmake | 2 +- FindSDL2_mixer.cmake | 2 +- FindSDL2_net.cmake | 2 +- FindSDL2_ttf.cmake | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FindSDL2.cmake b/FindSDL2.cmake index 657918d..31205b8 100644 --- a/FindSDL2.cmake +++ b/FindSDL2.cmake @@ -276,7 +276,7 @@ if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") unset(SDL2_VERSION_PATCH) endif() -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIRS diff --git a/FindSDL2_gfx.cmake b/FindSDL2_gfx.cmake index 05963f4..5fd6ab2 100644 --- a/FindSDL2_gfx.cmake +++ b/FindSDL2_gfx.cmake @@ -165,7 +165,7 @@ endif() set(SDL2_GFX_LIBRARIES ${SDL2_GFX_LIBRARY}) set(SDL2_GFX_INCLUDE_DIRS ${SDL2_GFX_INCLUDE_DIR}) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_gfx REQUIRED_VARS SDL2_GFX_LIBRARIES SDL2_GFX_INCLUDE_DIRS diff --git a/FindSDL2_image.cmake b/FindSDL2_image.cmake index 7e4f010..f702e0d 100644 --- a/FindSDL2_image.cmake +++ b/FindSDL2_image.cmake @@ -165,7 +165,7 @@ endif() set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS diff --git a/FindSDL2_mixer.cmake b/FindSDL2_mixer.cmake index 5f58319..14a27df 100644 --- a/FindSDL2_mixer.cmake +++ b/FindSDL2_mixer.cmake @@ -163,7 +163,7 @@ endif() set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS diff --git a/FindSDL2_net.cmake b/FindSDL2_net.cmake index 2a8ce78..41cbf66 100644 --- a/FindSDL2_net.cmake +++ b/FindSDL2_net.cmake @@ -165,7 +165,7 @@ endif() set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY}) set(SDL2_NET_INCLUDE_DIRS ${SDL2_NET_INCLUDE_DIR}) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_net REQUIRED_VARS SDL2_NET_LIBRARIES SDL2_NET_INCLUDE_DIRS diff --git a/FindSDL2_ttf.cmake b/FindSDL2_ttf.cmake index 02db0df..64ecb97 100644 --- a/FindSDL2_ttf.cmake +++ b/FindSDL2_ttf.cmake @@ -165,7 +165,7 @@ endif() set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS From 4ea07174ad6034f9c2ae3c9529f90ccbc2fce5db Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 3 Feb 2019 23:14:33 +0100 Subject: [PATCH 2/6] Update 'Usage' section in README.md --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7db431a..b634231 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,33 @@ The improvements made to these modules are as follows: ## Usage -There is two approaches that can be adopted: A legacy approach and a modern -approach. Both of them are supported. +In order to use the SDL2 CMake modules, we have to clone this repository in a +sud-directory `cmake/sdl2` in our project as follows: + +```sh +cd +git clone https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2 +rm -rf cmake/sdl2/.git +``` + +Or if we are using git for our project, we can add this repository as a +submodule as follows: + +```sh +cd +git submodule add https://gitlab.com/aminosbh/sdl2-cmake-modules.git cmake/sdl2 +git commit -m "Add SDL2 CMake modules" +``` + +Then we should specify the modules path in the main CMakeLists.txt file like +the following: + +```cmake +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) +``` + +Finally, we can use the SDL2 modules. There is two approaches that can be +adopted: A legacy approach and a modern approach. Both of them are supported. ### Modern CMake From f3223e2b723d7984ee722c27c949b42e5bef3204 Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 3 Feb 2019 23:16:22 +0100 Subject: [PATCH 3/6] Add license in modules files --- FindSDL2.cmake | 31 +++++++++++++++++++++++++++++++ FindSDL2_gfx.cmake | 31 +++++++++++++++++++++++++++++++ FindSDL2_image.cmake | 31 +++++++++++++++++++++++++++++++ FindSDL2_mixer.cmake | 31 +++++++++++++++++++++++++++++++ FindSDL2_net.cmake | 31 +++++++++++++++++++++++++++++++ FindSDL2_ttf.cmake | 31 +++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+) diff --git a/FindSDL2.cmake b/FindSDL2.cmake index 31205b8..42c4ffb 100644 --- a/FindSDL2.cmake +++ b/FindSDL2.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2 -------- diff --git a/FindSDL2_gfx.cmake b/FindSDL2_gfx.cmake index 5fd6ab2..970a92d 100644 --- a/FindSDL2_gfx.cmake +++ b/FindSDL2_gfx.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2_gfx -------------- diff --git a/FindSDL2_image.cmake b/FindSDL2_image.cmake index f702e0d..624e915 100644 --- a/FindSDL2_image.cmake +++ b/FindSDL2_image.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2_image -------------- diff --git a/FindSDL2_mixer.cmake b/FindSDL2_mixer.cmake index 14a27df..a71f26a 100644 --- a/FindSDL2_mixer.cmake +++ b/FindSDL2_mixer.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2_mixer -------------- diff --git a/FindSDL2_net.cmake b/FindSDL2_net.cmake index 41cbf66..74c765b 100644 --- a/FindSDL2_net.cmake +++ b/FindSDL2_net.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2_net ------------ diff --git a/FindSDL2_ttf.cmake b/FindSDL2_ttf.cmake index 64ecb97..2ab9a76 100644 --- a/FindSDL2_ttf.cmake +++ b/FindSDL2_ttf.cmake @@ -1,6 +1,37 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #[=======================================================================[.rst: FindSDL2_ttf ------------ From 43f32e49aab5b1afa2353fc55c6e40cd3aca3275 Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 3 Feb 2019 23:22:19 +0100 Subject: [PATCH 4/6] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b634231..9c53490 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ the modules find the appropriate libraries: - `SDL2_PATH` and `SDL2__PATH`:
Can be specified to set the root search path for the `SDL2` and `SDL2_` - `SDL2_NO_DEFAULT_PATH` and `SDL2__NO_DEFAULT_PATH`:
- Disable search `SDL2/SDL2` library in default path:
+ Disable search `SDL2/SDL2_` library in default path:
If `SDL2[_]_PATH` is set, defaults to ON
Else defaults to OFF - `SDL2_INCLUDE_DIR` and `SDL2__INCLUDE_DIR`:
From 63c852d1688582409b2e0a8839ac55ee4997e833 Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 10 Feb 2019 21:16:03 +0100 Subject: [PATCH 5/6] Separate SDL2main check --- FindSDL2.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FindSDL2.cmake b/FindSDL2.cmake index 42c4ffb..281412b 100644 --- a/FindSDL2.cmake +++ b/FindSDL2.cmake @@ -59,6 +59,7 @@ This module will set the following variables in your project: SDL2_LIBRARIES, the name of the library to link against SDL2_INCLUDE_DIRS, where to find SDL.h SDL2_FOUND, if false, do not try to link to SDL2 + SDL2MAIN_FOUND, if false, do not try to link to SDL2main SDL2_VERSION_STRING, human-readable string containing the version of SDL2 @@ -310,9 +311,15 @@ endif() include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 - REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIRS + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR VERSION_VAR SDL2_VERSION_STRING) +if(SDL2MAIN_LIBRARY) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2main + REQUIRED_VARS SDL2MAIN_LIBRARY SDL2_INCLUDE_DIR + VERSION_VAR SDL2_VERSION_STRING) +endif() + mark_as_advanced(SDL2_PATH SDL2_NO_DEFAULT_PATH From 48fa6e27bdc3f9074f92c651ab6bae6f7a01d061 Mon Sep 17 00:00:00 2001 From: "Amine B. Hassouna" Date: Sun, 10 Feb 2019 21:22:08 +0100 Subject: [PATCH 6/6] Fix SDL2 CMake module for MinGW builds --- FindSDL2.cmake | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/FindSDL2.cmake b/FindSDL2.cmake index 281412b..c20d809 100644 --- a/FindSDL2.cmake +++ b/FindSDL2.cmake @@ -350,16 +350,6 @@ if(SDL2_FOUND) set_property(TARGET SDL2::Core APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads) endif() - - # MinGW needs an additional link flag, -mwindows - # and link to mingw32 - if(MINGW) - set_property(TARGET SDL2::Core APPEND PROPERTY - INTERFACE_LINK_LIBRARIES mingw32) - set_property(TARGET SDL2::Core APPEND PROPERTY - INTERFACE_LINK_OPTIONS "-mwindows") - endif() - endif() # SDL2::Main target @@ -367,20 +357,31 @@ if(SDL2_FOUND) # For more details, please see above. if(NOT SDL2_BUILDING_LIBRARY AND NOT TARGET SDL2::Main) - if(SDL2_INCLUDE_DIR MATCHES ".framework" ) + if(SDL2_INCLUDE_DIR MATCHES ".framework" OR NOT SDL2MAIN_LIBRARY) add_library(SDL2::Main INTERFACE IMPORTED) - elseif(SDL2MAIN_LIBRARY) - add_library(SDL2::Main UNKNOWN IMPORTED) - set_property(TARGET SDL2::Main PROPERTY - IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}") - elseif(UNIX) - add_library(SDL2::Main INTERFACE IMPORTED) - endif() - - # Add SDL2::Core as a dependency - if(TARGET SDL2::Main) set_property(TARGET SDL2::Main PROPERTY INTERFACE_LINK_LIBRARIES SDL2::Core) + elseif(SDL2MAIN_LIBRARY) + # MinGW requires that the mingw32 library is specified before the + # libSDL2main.a static library when linking. + # The SDL2::MainInternal target is used internally to make sure that + # CMake respects this condition. + add_library(SDL2::MainInternal UNKNOWN IMPORTED) + set_property(TARGET SDL2::MainInternal PROPERTY + IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}") + set_property(TARGET SDL2::MainInternal PROPERTY + INTERFACE_LINK_LIBRARIES SDL2::Core) + + add_library(SDL2::Main INTERFACE IMPORTED) + + if(MINGW) + # MinGW needs an additional link flag '-mwindows' and link to mingw32 + set_property(TARGET SDL2::Main PROPERTY + INTERFACE_LINK_LIBRARIES "mingw32" "-mwindows") + endif() + + set_property(TARGET SDL2::Main APPEND PROPERTY + INTERFACE_LINK_LIBRARIES SDL2::MainInternal) endif() endif()