Skip to content

Commit

Permalink
Merge pull request #1063 from AlexMax/cmake
Browse files Browse the repository at this point in the history
Get CMake working under MSYS2 + MinGW
  • Loading branch information
fragglet committed Jun 17, 2018
2 parents 1f987b3 + 4820b9d commit 5329fb5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
27 changes: 22 additions & 5 deletions cmake/FindSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions cmake/FindSDL2_mixer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindSDL2_net.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmake/Findsamplerate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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.