Skip to content

Commit

Permalink
MSYS: Configuration and build fixes
Browse files Browse the repository at this point in the history
The MSYS build is almost fully working except for one strange issue:
sometimes getcwd() returns an invalid path. This seems to always
happen when running via Explorer.

Running via command line, especially if \msys64\usr\bin is on the
PATH, seems to work great.
  • Loading branch information
skyjake committed Feb 24, 2020
1 parent ea5696a commit 3c0beb0
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 26 deletions.
12 changes: 8 additions & 4 deletions doomsday/build/scripts/build_deps.py
Expand Up @@ -8,11 +8,14 @@ def print_config(cfg):


IS_CYGWIN = platform.system().startswith('CYGWIN_NT')
IS_MSYS = os.getenv('MSYSTEM') == 'MSYS'
IS_MINGW = os.getenv('MSYSTEM') == 'MINGW64'

PATCH_DIR = os.path.abspath(os.path.dirname(__file__))

if IS_MINGW:
if IS_MSYS:
UNISTRING_DIR = '-DUNISTRING_DIR=' + os.getenv('MSYSTEM_PREFIX')
elif IS_MINGW:
UNISTRING_DIR = '-DUNISTRING_DIR=' + os.getenv('MINGW_PREFIX')
elif platform.system() == 'Darwin':
UNISTRING_DIR = '-DUNISTRING_DIR=/usr/local'
Expand Down Expand Up @@ -54,7 +57,8 @@ def print_config(cfg):
['-Wno-dev',
'-DOPTION_BUILD_EXAMPLES=NO',
'-DOPTION_BUILD_TOOLS=NO',
'-DOPTION_BUILD_TESTS=NO']
'-DOPTION_BUILD_TESTS=NO',
'-DCMAKE_CXX_FLAGS=-Wno-deprecated-copy' if IS_MSYS else '']
)
]

Expand All @@ -72,7 +76,7 @@ def print_config(cfg):
os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', 'deps'
)
),
'generator': 'Unix Makefiles' if IS_MINGW or IS_CYGWIN else 'Ninja'
'generator': 'Unix Makefiles' if (IS_MSYS or IS_MINGW or IS_CYGWIN) else 'Ninja'
}
if os.path.exists(CFG_PATH):
cfg = json.load(open(CFG_PATH, 'rt'))
Expand Down Expand Up @@ -147,7 +151,7 @@ def print_config(cfg):
else:
os.chdir(src_dir)
subprocess.check_call(['git', 'fetch', '--tags'])
print(os.getcwd())
print('Current directory:', os.getcwd())
subprocess.check_call(['git', 'reset', '--hard'])
subprocess.check_call(['git', 'checkout', git_tag])
if patch_file:
Expand Down
34 changes: 34 additions & 0 deletions doomsday/build/scripts/msys_deps.py
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# This script goes through an MSYS2 deployment and copies all the required
# dependencies from the system directory. All executables (EXE, DLL) are
# checked.

import sys, os, shutil, subprocess, re, platform
if not platform.system().startswith('MSYS_'):
raise Exception('Please run under MSYS')
system_bin = '/usr/bin'
objdump_cmd = '/usr/bin/objdump'
root = os.path.abspath(sys.argv[1])
if root.startswith('/usr'):
print('msys_deps.py will not copy system libraries to a destination under /usr')
binaries = set(filter(lambda n: os.path.splitext(n)[1].lower() in ['.exe', '.dll'],
os.listdir(root)))
while binaries:
binary = binaries.pop()
if binary.startswith('lib'):
# Not an MSYS library.
continue
print('--', binary)
bin_path = os.path.join(root, binary)
deps = subprocess.check_output([objdump_cmd, '-p', bin_path]).decode()
for deps_line in deps.split('\n'):
found = re.search('DLL Name: (.*)', deps_line)
if found:
dll_name = found.group(1).strip()
dll_path = os.path.join(system_bin, dll_name)
dest_path = os.path.join(root, dll_name)
if os.path.exists(dll_path) and not os.path.exists(dest_path):
# Copy this dependency.
print(dll_path)
shutil.copy(dll_path, dest_path)
binaries.add(dest_path)
2 changes: 1 addition & 1 deletion doomsday/cmake/Arch.cmake
Expand Up @@ -4,7 +4,7 @@ set (_bits)

if (ARCH_BITS EQUAL 64)
add_definitions (-DDE_64BIT_HOST=1 -D__64BIT__=1)
if (WIN32 OR CYGWIN)
if (WIN32 OR MSYS OR CYGWIN)
set (DE_ARCH x64)
else ()
set (DE_ARCH x86_64)
Expand Down
4 changes: 3 additions & 1 deletion doomsday/cmake/Config.cmake
Expand Up @@ -36,7 +36,9 @@ list (APPEND CMAKE_MODULE_PATH "${DE_DEPENDS_DIR}/products/lib/cmake/assimp-4.1"

# Platform-Specific Configuration --------------------------------------------

if (CYGWIN)
if (MSYS)
include (PlatformMsys)
elseif (CYGWIN)
include (PlatformCygwin)
elseif (IOS)
include (PlatformiOS)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/cmake/Directories.cmake
Expand Up @@ -28,7 +28,7 @@ else ()
set (DE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
endif ()

if (UNIX AND NOT (APPLE OR CYGWIN))
if (UNIX AND NOT (APPLE OR MSYS OR CYGWIN))
set (UNIX_LINUX YES)
include (GNUInstallDirs)
else ()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/cmake/FindFMOD.cmake
Expand Up @@ -43,7 +43,7 @@ if (FMOD_FMOD_H AND NOT TARGET fmodex)
elseif (APPLE)
set (fmodLib "${fmodApi}/lib/libfmod.dylib")
set (fmodInstLib ${fmodLib})
elseif (WIN32 OR CYGWIN)
elseif (WIN32 OR CYGWIN OR MSYS)
if (ARCH_BITS EQUAL 64)
set (fmodLib "${fmodApi}/lib/fmod64_vc.lib")
set (fmodInstLib "${fmodApi}/lib/fmod64.dll")
Expand Down
15 changes: 7 additions & 8 deletions doomsday/cmake/FindSDL2Libs.cmake
Expand Up @@ -16,26 +16,25 @@ if (TARGET SDL2)
return ()
endif ()

if (PKG_CONFIG_FOUND AND (NOT CYGWIN OR IOS))
if (PKG_CONFIG_FOUND AND (NOT MSYS OR CYGWIN OR IOS))
# The Unix Way: use pkg-config to find the SDL2 libs installed on system.
if (NOT TARGET SDL2)
add_pkgconfig_interface_library (SDL2 OPTIONAL sdl2)
add_pkgconfig_interface_library (SDL2_mixer OPTIONAL SDL2_mixer)
endif ()

elseif (WIN32 OR CYGWIN)
elseif (WIN32 OR CYGWIN OR MSYS)
deng_clean_path (sdlRoot ${SDL2_DIR})
# This is Windows, so we'll use the Windows SDL2 libraries that the user has
# installed in FMOD_DIR. Note that Cygwin also uses the native SDL2 libraries
# installed in SDL2_DIR. Note that Cygwin also uses the native SDL2 libraries
# and *not* the Cygwin ones, which would presumably have an X11 dependency.
set (_oldPath ${SDL2_LIBRARY})
if (CYGWIN)
if (CYGWIN OR MSYS)
if (SDL2_DIR STREQUAL "")
message (FATAL_ERROR "SDL2_DIR must be set in Cygwin")
message (FATAL_ERROR "SDL2_DIR must be set in MSYS/Cygwin")
endif ()
# Assume it has been set manually.
set (SDL2_LIBRARY ${sdlRoot}/lib/${DE_ARCH}/SDL2.lib)
message (STATUS ${SDL2_LIBRARY})
else ()
file (GLOB _hints ${sdlRoot}/SDL2* $ENV{DENG_DEPEND_PATH}/SDL2*)
find_library (SDL2_LIBRARY SDL2
Expand Down Expand Up @@ -69,9 +68,9 @@ elseif (WIN32 OR CYGWIN)
# Also attempt to locate SLD2_mixer.
deng_clean_path (sdlMixerDir ${SDL2_MIXER_DIR})
set (_oldPath ${SDL_MIXER_LIBRARY})
if (CYGWIN)
if (MSYS OR CYGWIN)
if (SDL2_MIXER_DIR STREQUAL "")
message (FATAL_ERROR "SDL2_MIXER_DIR must be set in Cygwin")
message (FATAL_ERROR "SDL2_MIXER_DIR must be set in MSYS/Cygwin")
endif ()
set (SDL2_MIXER_LIBRARY ${sdlMixerDir}/lib/${DE_ARCH}/SDL2_mixer.lib)
else ()
Expand Down
8 changes: 4 additions & 4 deletions doomsday/cmake/Macros.cmake
Expand Up @@ -135,7 +135,7 @@ macro (deng_target_defaults target)
if (APPLE)
deng_xcode_attribs (${target})
# macOS version numbers come from the Info.plist, we don't need version symlinks.
elseif (CYGWIN)
elseif (MSYS OR CYGWIN)
#set_target_properties (${target} PROPERTIES
# VERSION ${DE_VERSION}
#)
Expand Down Expand Up @@ -173,7 +173,7 @@ function (deng_filter_platform_sources outName)
set (filtered YES)
elseif ("${fn}" MATCHES ".*_windows\\..*" OR
"${fn}" MATCHES ".*/windows/.*") # Windows-specific
if (NOT WIN32 AND NOT CYGWIN)
if (NOT (WIN32 OR CYGWIN OR MSYS))
set (filtered YES)
endif ()
elseif ("${fn}" MATCHES ".*_macx\\..*") # macOS specific
Expand All @@ -186,7 +186,7 @@ function (deng_filter_platform_sources outName)
set (filtered YES)
endif ()
elseif ("${fn}" MATCHES ".*_x11\\..*") # X11 specific files
if (APPLE OR CYGWIN OR NOT UNIX)
if (APPLE OR MSYS OR CYGWIN OR NOT UNIX)
set (filtered YES)
endif ()
endif ()
Expand Down Expand Up @@ -797,7 +797,7 @@ macro (deng_install_library library)
DESTINATION ${DE_INSTALL_PLUGIN_DIR}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
)
elseif (CYGWIN OR MINGW)
elseif (MSYS OR CYGWIN OR MINGW)
message (STATUS "Library will be installed: ${library}")
install (PROGRAMS ${library} DESTINATION bin)
elseif (MSVC)
Expand Down
1 change: 1 addition & 0 deletions doomsday/cmake/PlatformCygwin.cmake
Expand Up @@ -14,6 +14,7 @@ add_definitions (
-D_GNU_SOURCE=1
-DDE_PLATFORM_ID="win-${DE_ARCH}"
-DDE_WINDOWS=1
-DDE_CYGWIN=1
)

if (CMAKE_COMPILER_IS_GNUCXX)
Expand Down
27 changes: 27 additions & 0 deletions doomsday/cmake/PlatformMsys.cmake
@@ -0,0 +1,27 @@
include (PlatformGenericUnix)

set (DE_PLATFORM_SUFFIX windows)
set (DE_AMETHYST_PLATFORM WIN32)

set (DE_INSTALL_DATA_DIR "data")
set (DE_INSTALL_DOC_DIR "doc")
#set (DE_INSTALL_LIB_DIR "bin")

add_definitions (
-D__USE_BSD
-DWINVER=0x0601
-D_WIN32_WINNT=0x0601
-D_GNU_SOURCE=1
-DDE_PLATFORM_ID="win-${DE_ARCH}"
-DDE_WINDOWS=1
-DDE_MSYS=1
)

if (CMAKE_COMPILER_IS_GNUCXX)
append_unique (CMAKE_CXX_FLAGS -Werror=return-type)
append_unique (CMAKE_CXX_FLAGS -fdiagnostics-color)
endif ()

# All symbols are hidden by default.
append_unique (CMAKE_C_FLAGS "-fvisibility=hidden")
append_unique (CMAKE_CXX_FLAGS "-fvisibility=hidden")
4 changes: 4 additions & 0 deletions doomsday/libs/core/CMakeLists.txt
Expand Up @@ -95,6 +95,10 @@ if (WIN32)
install (PROGRAMS ${the_Foundation_DIR}/../../lib_Foundation.dll
DESTINATION bin)
endif ()
if (MSYS)
install (PROGRAMS ${the_Foundation_DIR}/../../msys-Foundation.dll
DESTINATION bin)
endif ()
if (CYGWIN)
install (PROGRAMS ${the_Foundation_DIR}/../../cyg_Foundation.dll
DESTINATION bin)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/core/commandline.cpp
Expand Up @@ -159,7 +159,7 @@ CommandLine::CommandLine(const StringList &args) : d(new Impl(*this))
d->appendArg(args.at(i));
}
}
#if defined (__CYGWIN__)
#if defined (DE_CYGWIN)
makeAbsolutePath(0); // convert to a Windows path
#endif
}
Expand Down Expand Up @@ -332,7 +332,7 @@ void CommandLine::makeAbsolutePath(dsize pos)
{
bool converted = false;

#if defined (__CYGWIN__)
#if defined (DE_CYGWIN)
// Cygwin gives us UNIX-like paths on the command line, so let's convert
// to our expected Windows paths.
arg = String::take(unixToWindows_Path(arg));
Expand Down
12 changes: 11 additions & 1 deletion doomsday/libs/gui/CMakeLists.txt
Expand Up @@ -66,8 +66,9 @@ if (WIN32)
# Direct2D was used for DPI information.
# target_link_libraries (libgui PRIVATE d2d1.lib)
endif ()
if (CYGWIN)
if (MSYS OR CYGWIN)
target_compile_options (libgui PUBLIC -mwindows)
target_link_options (libgui PUBLIC -mwindows)
target_link_libraries (libgui PUBLIC ole32)
endif ()
if (IOS)
Expand All @@ -88,6 +89,15 @@ if (WIN32)
COMPONENT client
)
endif ()
if (MSYS)
install (
PROGRAMS ${ASSIMP_ROOT_DIR}/bin/msys-assimp-4.dll
${glbinding_DIR}/msys-glbinding-3.dll
${glbinding_DIR}/msys-glbinding-aux-3.dll
DESTINATION bin
COMPONENT client
)
endif ()
if (CYGWIN)
install (
PROGRAMS ${ASSIMP_ROOT_DIR}/bin/cygassimp-4.dll
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tools/dshell/CMakeLists.txt
Expand Up @@ -42,7 +42,7 @@ target_link_libraries (dshell PRIVATE ${CURSES_LIBRARIES})

deng_install_tool (dshell)

if (CYGWIN)
if (CYGWIN OR MSYS)
# Curses requires terminfo to be available.
install (FILES /usr/share/terminfo/63/cygwin DESTINATION share/terminfo/63)
endif ()
4 changes: 2 additions & 2 deletions doomsday/tools/dshell/src/main.cpp
Expand Up @@ -20,14 +20,14 @@
#include <de/Counted>
#include "shellapp.h"

#if defined (__CYGWIN__)
#if defined (DE_CYGWIN) || defined (DE_MSYS)
# include <the_Foundation/path.h>
#endif

int main(int argc, char *argv[])
{
init_Foundation();
#if defined (__CYGWIN__)
#if defined (DE_CYGWIN) || defined (DE_MSYS)
{
// Curses needs to have terminfo.
de::NativePath exePath(de::String::take(unixToWindows_Path(argv[0])));
Expand Down

0 comments on commit 3c0beb0

Please sign in to comment.