ref: 5329fb5d75971138b20abf940ed63635bd2861e0
parent: 1f987b323d6bc31e3d44e29727a86fb5eb08ae6b
parent: 4820b9d5815aae50abe0626ca6615030fc6f8b85
author: Simon Howard <[email protected]>
date: Sat Jun 16 16:31:31 EDT 2018
Merge pull request #1063 from AlexMax/cmake Get CMake working under MSYS2 + MinGW
--- a/cmake/FindSDL2.cmake
+++ b/cmake/FindSDL2.cmake
@@ -26,8 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
@@ -91,7 +91,24 @@
IMPORTED_LOCATION "${SDL2_LIBRARY}")
# SDL2main imported target.
- add_library(SDL2::SDL2main UNKNOWN IMPORTED)
- set_target_properties(SDL2::SDL2main PROPERTIES
- IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+ if(MINGW)
+ # Gross hack to get mingw32 first in the linker order.
+ add_library(SDL2::_SDL2main_detail UNKNOWN IMPORTED)
+ set_target_properties(SDL2::_SDL2main_detail PROPERTIES
+ IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+
+ # Ensure that SDL2main comes before SDL2 in the linker order. CMake
+ # isn't smart enough to keep proper ordering for indirect dependencies
+ # so we have to spell it out here.
+ target_link_libraries(SDL2::_SDL2main_detail INTERFACE SDL2::SDL2)
+
+ add_library(SDL2::SDL2main INTERFACE IMPORTED)
+ set_target_properties(SDL2::SDL2main PROPERTIES
+ IMPORTED_LIBNAME mingw32)
+ target_link_libraries(SDL2::SDL2main INTERFACE SDL2::_SDL2main_detail)
+ else()
+ add_library(SDL2::SDL2main UNKNOWN IMPORTED)
+ set_target_properties(SDL2::SDL2main PROPERTIES
+ IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}")
+ endif()
endif()
--- a/cmake/FindSDL2_mixer.cmake
+++ b/cmake/FindSDL2_mixer.cmake
@@ -26,8 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
--- a/cmake/FindSDL2_net.cmake
+++ b/cmake/FindSDL2_net.cmake
@@ -26,8 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
--- a/cmake/Findsamplerate.cmake
+++ b/cmake/Findsamplerate.cmake
@@ -26,8 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
-# - Unix Makefiles
-# - Ninja
+# - Unix Makefiles (Linux, MSYS2)
+# - Ninja (Linux, MSYS2)
# - Visual Studio
# Use pkg-config to find library locations in *NIX environments.
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -105,7 +105,7 @@
set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES})
set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES})
-set(EXTRA_LIBS textscreen pcsound opl SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net)
+set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net textscreen pcsound opl)
if(SAMPLERATE_FOUND)
list(APPEND EXTRA_LIBS samplerate::samplerate)
endif()
@@ -197,7 +197,7 @@
target_include_directories("${PROGRAM_PREFIX}setup"
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}setup" setup textscreen SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net setup textscreen)
if(MSVC)
set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES
@@ -207,9 +207,9 @@
add_executable(midiread midifile.c z_native.c i_system.c m_argv.c m_misc.c)
target_compile_definitions(midiread PRIVATE "-DTEST")
target_include_directories(midiread PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(midiread PRIVATE SDL2::SDL2)
+target_link_libraries(midiread SDL2::SDL2main SDL2::SDL2)
add_executable(mus2mid mus2mid.c memio.c z_native.c i_system.c m_argv.c m_misc.c)
target_compile_definitions(mus2mid PRIVATE "-DSTANDALONE")
target_include_directories(mus2mid PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(mus2mid PRIVATE SDL2::SDL2)
+target_link_libraries(mus2mid SDL2::SDL2main SDL2::SDL2)