Permalink
Browse files

Merge pull request #1063 from AlexMax/cmake

Get CMake working under MSYS2 + MinGW
  • Loading branch information...
fragglet committed Jun 17, 2018
2 parents 1f987b3 + 4820b9d commit 5329fb5d75971138b20abf940ed63635bd2861e0
Showing with 32 additions and 15 deletions.
  1. +22 −5 cmake/FindSDL2.cmake
  2. +2 −2 cmake/FindSDL2_mixer.cmake
  3. +2 −2 cmake/FindSDL2_net.cmake
  4. +2 −2 cmake/Findsamplerate.cmake
  5. +4 −4 src/CMakeLists.txt
View
@@ -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 @@ if(SDL2_FOUND)
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()
@@ -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
View
@@ -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
@@ -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.
View
@@ -105,7 +105,7 @@ set(DEHACKED_SOURCE_FILES
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 @@ endif()
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 @@ endif()
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)

0 comments on commit 5329fb5

Please sign in to comment.