diff --git a/CMakeLists.txt b/CMakeLists.txt index 6692f6e7..5178eedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,10 @@ if(COMMAND cmake_policy) if(POLICY CMP0012) cmake_policy(SET CMP0012 NEW) # Saner if() behavior. endif() + + if(POLICY CMP0060) + cmake_policy(SET CMP0060 NEW) # Full lib paths. + endif() endif() set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -184,7 +188,7 @@ macro(check_ffmpeg_component_versions) endif() endmacro() -if(((NOT DEFINED ENABLE_FFMPEG) AND (NOT (WIN32 AND X86))) OR ENABLE_FFMPEG) +if(NOT DEFINED ENABLE_FFMPEG OR ENABLE_FFMPEG) set(FFMPEG_DEFAULT ON) find_package(FFmpeg COMPONENTS ${FFMPEG_COMPONENTS}) @@ -337,6 +341,20 @@ if(WIN32 AND CMAKE_GENERATOR STREQUAL Ninja AND NOT "$ENV{MSYSTEM_PREFIX}" STREQ set(MSYS ON) endif() +include(VbamFunctions) + +if(MSYS AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) + if($ENV{MSYSTEM} STREQUAL CLANG64) + cygpath(prefix "$ENV{MSYSTEM_PREFIX}/x86_64-w64-mingw32") + list(APPEND CMAKE_PREFIX_PATH "${prefix}") + elseif($ENV{MSYSTEM} STREQUAL CLANG32) + cygpath(prefix "$ENV{MSYSTEM_PREFIX}/i686-w64-mingw32") + list(APPEND CMAKE_PREFIX_PATH "${prefix}") + endif() + + set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE INTERNAL "prefix search path for find_XXXX" FORCE) +endif() + # Add support for Homebrew, MacPorts and Fink on OS X if(APPLE) include(MacPackageManagers) @@ -402,6 +420,16 @@ if(ENABLE_FFMPEG) if(APPLE) set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} -framework CoreText -framework ApplicationServices) + elseif(WIN32) + list(APPEND FFMPEG_LIBRARIES secur32 bcrypt ${WIN32_MEDIA_FOUNDATION_LIBS}) + + if(MSYS AND VBAM_STATIC) + foreach(lib tiff jbig lzma) + cygpath(lib "$ENV{MSYSTEM_PREFIX}/lib/lib${lib}.a") + + list(APPEND FFMPEG_LIBRARIES "${lib}") + endforeach() + endif() endif() else() add_definitions(-DNO_FFMPEG) @@ -566,23 +594,20 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) endif() # Common flags. - set(MY_C_FLAGS -pipe -Wformat -Wformat-security -feliminate-unused-debug-types) + set(MY_C_FLAGS -pipe -Wno-unused-command-line-argument -Wformat -Wformat-security -feliminate-unused-debug-types) - # Enable some optimizations for our upstream binary builds. - if(UPSTREAM_RELEASE) - # Optimize for Core2 and tune for Rocketlake on macOS and Zen3 for the rest - # on X86_64. - if(X86_64) - set(MY_C_FLAGS ${MY_C_FLAGS} -march=core2) - if(APPLE) - set(MY_C_FLAGS ${MY_C_FLAGS} -mtune=rocketlake) - else() - set(MY_C_FLAGS ${MY_C_FLAGS} -mtune=znver3) - endif() - # Optimize for pentium-mmx and tune for Core2 on X86_32. - elseif(X86_32) - set(MY_C_FLAGS ${MY_C_FLAGS} -march=pentium-mmx -mtune=core2) + # Optimize for Core2 and tune for Rocketlake on macOS and Zen3 for the rest + # on X86_64. + if(X86_64) + set(MY_C_FLAGS ${MY_C_FLAGS} -march=core2) + if(APPLE) + set(MY_C_FLAGS ${MY_C_FLAGS} -mtune=rocketlake) + else() + set(MY_C_FLAGS ${MY_C_FLAGS} -mtune=znver3) endif() + # Optimize for pentium-mmx and tune for Core2 on X86_32. + elseif(X86_32) + set(MY_C_FLAGS ${MY_C_FLAGS} -march=pentium-mmx -mtune=core2) endif() # common debug flags diff --git a/cmake/VbamFunctions.cmake b/cmake/VbamFunctions.cmake index 0bae5068..e048787d 100644 --- a/cmake/VbamFunctions.cmake +++ b/cmake/VbamFunctions.cmake @@ -68,7 +68,7 @@ function(check_clean_exit var) endfunction() function(find_wx_util var util) - if(WIN32 OR EXISTS /etc/gentoo-release) + if(EXISTS /etc/gentoo-release) # On win32, including cross builds we prefer the plain utility name # first from PATH. # @@ -78,6 +78,12 @@ function(find_wx_util var util) # This makes a one element of empty string list. set(conf_suffixes ";") set(major_versions ";") + elseif(WIN32) + set(major_versions ";") + endif() + + if(VBAM_STATIC) + list(APPEND conf_suffixes static) endif() list(APPEND conf_suffixes gtk4u gtk4 gtk3u gtk3 gtk2u gtk2 "") diff --git a/installdeps b/installdeps index 45561b84..1c8af93b 100755 --- a/installdeps +++ b/installdeps @@ -81,23 +81,16 @@ quit() { usage() { cat <<'EOF' Usage: ./installdeps [TARGET] -Try to install the dependencies needed for this project appropriately on the -host OS. + +Try to install the dependencies needed for this project appropriately on the host OS. This program may require sudo. -A cross-compile target may be specified as the only parameter, of either -m32 which targets the host in 32 bit mode (e.g. x86 on an amd64 -host) or win32, MinGW-w64-i686 or -MinGW-w64-x86_64. win32 is an alias for -MinGW-w64-i686 to target Windows via MinGW. Cross compiling for -Windows is only supported on Debian/Ubuntu, Fedora, Arch Linux and MSYS2. +A cross-compile target may be specified as the only parameter, of either m32 which targets the host in 32 bit mode (e.g. x86 on an amd64 host) or win32, MinGW-w64-i686 or MinGW-w64-x86_64. win32 is an alias for MinGW-w64-i686 to target Windows via MinGW. Cross compiling for Windows is only supported on Debian/Ubuntu, Fedora, Arch Linux and MSYS2. -On MSYS2 dependencies are installed for 32 or 64 bit native Windows targets -based on which shell you started (the value of $MSYSTEM) unless you specify one -or the other. You can specify a cross target of m32 or -m64 as aliases for the 32 bit or 64 bit targets respectively. -MSYS2 POSIX layer builds are not supported. +On MSYS2 the MinGW-w64-clang-x86_64 target for CLANG64 and the MinGW-w64-clang-i686 target for CLANG32 are also supported. + +On MSYS2 dependencies are installed for 32 or 64 bit native Windows targets based on which shell you started (the value of $MSYSTEM) unless you specify one or the other. You can specify a cross target of m32 or m64 as aliases for the 32 bit or 64 bit MinGW gcc targets respectively. MSYS2 POSIX layer builds are not supported. -h, --help, --usage Show this help screen and exit. --no-openal Do not install OpenAL dependencies. @@ -254,6 +247,12 @@ check_cross() { MINGW64) target='mingw-w64-x86_64' ;; + CLANG32) + target='mingw-w64-clang-i686' + ;; + CLANG64) + target='mingw-w64-clang-x86_64' + ;; MSYS) error 'host builds in MSYS mode are not supported, supply a target or start a MINGW shell' ;; @@ -279,12 +278,10 @@ check_cross() { win64) target='mingw-w64-x86_64' ;; - mingw-w64-i686) - ;; - mingw-w64-x86_64) + mingw-w64-x86_64|mingw-w64-i686|mingw-w64-clang-x86_64|mingw-w64-clang-i686) ;; *) - error "target must be one of 'm32', 'win32', 'MinGW-w64-i686', 'win64' or 'MinGW-w64-x86_64'" + error "target must be one of 'm32', 'win32', 'win64', or one of the MinGW/clang targets supported by MSYS2: mingw-w64-[clang-](x86_64|i686)." ;; esac ;; @@ -1087,7 +1084,24 @@ windows_installdeps() { # update catalogs check pacman -Sy - pkgs="SDL2 sfml wxWidgets zlib binutils cmake crt-git extra-cmake-modules gcc gcc-libs gcc-libgfortran gdb headers-git make pkg-config tools-git windows-default-manifest libmangle-git nasm ninja" + pkgs= + + case "$target" in + *clang*) + pkgs="lldb" + ;; + *) + pkgs="$pkgs gcc gcc-libs gcc-libgfortran" + ;; + esac + + case "$target" in + *i686*) + pkgs="$pkgs nasm" + ;; + esac + + pkgs="$pkgs SDL2 sfml wxWidgets zlib binutils cmake crt-git extra-cmake-modules headers-git make pkgconf tools-git windows-default-manifest libmangle-git ninja gdb" [ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs openal" [ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg" diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 2990b73d..41e40ae7 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -422,7 +422,7 @@ int main(int argc, char** argv) if(WX_ABI_FOUND_MATCH) # add C++ flags if(CMAKE_COMPILER_IS_GNUCXX) - string(REGEX REPLACE "" " -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT}) + string(REGEX REPLACE "" " -fabi-version=${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -fabi-version=${WX_ABI_VERSION}") elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) string(REGEX REPLACE "" " -D__GXX_ABI_VERSION=10${WX_ABI_VERSION} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT}) @@ -939,6 +939,27 @@ if(NOT TRANSLATIONS_ONLY) TARGET_LINK_LIBRARIES(visualboyadvance-m ${SPARKLE_FRAMEWORK}) endif() + # On MSYS2 transform wx lib paths to native paths for Ninja. + if(MSYS) + set(libs "") + + foreach(lib ${wxWidgets_LIBRARIES}) + if(NOT lib MATCHES "^(-Wl,|-mwindows$|-pipe$)") + if(lib MATCHES "^/") + cygpath(lib "${lib}") + endif() + + if(VBAM_STATIC AND lib MATCHES "^-l(wx.*|jpeg|tiff|jbig|lzma|expat)$") + cygpath(lib "$ENV{MSYSTEM_PREFIX}/lib/lib${CMAKE_MATCH_1}.a") + endif() + + list(APPEND libs "${lib}") + endif() + endforeach() + + set(wxWidgets_LIBRARIES "${libs}") + endif() + target_link_libraries( visualboyadvance-m ${wxWidgets_LIBRARIES} @@ -948,10 +969,6 @@ if(NOT TRANSLATIONS_ONLY) set(WIN32_MEDIA_FOUNDATION_LIBS dxva2 evr mf mfplat mfplay mfreadwrite mfuuid amstrmid) if(ENABLE_FFMPEG) - if(WIN32) - list(APPEND FFMPEG_LIBRARIES secur32 bcrypt ${WIN32_MEDIA_FOUNDATION_LIBS}) - endif() - target_link_libraries( visualboyadvance-m ${FFMPEG_LIBRARIES} diff --git a/src/wx/tests/CMakeLists.txt b/src/wx/tests/CMakeLists.txt index 27a80eea..412d8980 100644 --- a/src/wx/tests/CMakeLists.txt +++ b/src/wx/tests/CMakeLists.txt @@ -1,3 +1,8 @@ +# TODO: Does not link on CLANG64. +if(MSYS AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) + return() +endif() + include(doctest) include_directories("${CMAKE_SOURCE_DIR}/third_party/include/doctest")