Skip to content

Commit

Permalink
Merge pull request dolphin-emu#8087 from spycrab/cmake_win2019
Browse files Browse the repository at this point in the history
Support CMake on Windows
  • Loading branch information
spycrab authored May 14, 2019
2 parents d5535a8 + ba83cec commit ec73406
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 33 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ endif()
# as defined above.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)

if (MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

endif()

# setup CCache
include(CCache)

Expand Down Expand Up @@ -361,6 +369,11 @@ if(ENABLE_VTUNE)
)
endif()

if(WIN32)
message(STATUS "Building for Windows, disabling NoGUI frontend.")
set(ENABLE_NOGUI OFF)
endif()

if(ANDROID)
message(STATUS "Building for Android")
if(NOT ENABLE_HEADLESS)
Expand Down Expand Up @@ -596,7 +609,7 @@ endif()
message(STATUS "Using static FreeSurround from Externals")
add_subdirectory(Externals/FreeSurround)

if (APPLE)
if (APPLE OR WIN32)
message(STATUS "Using ed25519 from Externals")
add_subdirectory(Externals/ed25519)
endif()
Expand Down
42 changes: 30 additions & 12 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
{
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "Debug",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"name": "Release",
"configurationType": "Release",
"generator": "Visual Studio 16 2019 Win64",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildCommandArgs": "-m -p:PreferredToolArchitecture=x64",
"buildRoot": "${workspaceRoot}\\build",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -p:PreferredToolArchitecture=x64"
"variables": [
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.11.1\\5.11.1\\msvc2017_64\\lib\\cmake\\Qt5"
}
]
},
{
"name": "x64-Release",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "Release",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"name": "Debug",
"generator": "Visual Studio 16 2019 Win64",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildCommandArgs": "-m -p:PreferredToolArchitecture=x64",
"buildRoot": "${workspaceRoot}\\build",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -p:PreferredToolArchitecture=x64"
"variables": [
{
"name": "CMAKE_BUILD_TYPE",
"value": "Debug"
},
{
"name": "Qt5_DIR",
"value": "${workspaceRoot}\\Externals\\Qt\\Qt5.11.1\\5.11.1\\msvc2017_64\\lib\\cmake\\Qt5"
}
]
}
]
}
}
2 changes: 2 additions & 0 deletions Externals/libpng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(png PUBLIC z)

if(NOT MSVC)
target_compile_options(png
PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions Externals/minizip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ endif()
add_library(minizip STATIC ${SRCS})
target_include_directories(minizip PUBLIC .)

target_link_libraries(minizip PUBLIC z)

add_library(MiniZip::minizip ALIAS minizip)
35 changes: 35 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (MSVC)
# Set warning level to 4
add_compile_options(/W4)

# Disable some warnings
add_compile_options(
/wd4201 # nonstandard extension used : nameless struct/union
/wd4127 # conditional expression is constant
/wd4100 # 'identifier' : unreferenced formal parameter
/wd4200 # InputCommon fix temp.
/wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
/wd4121 # 'symbol' : alignment of a member was sensitive to packing
/wd4324 # Padding was added at the end of a structure because you specified a __declspec(align) value.
/wd4714 # function 'function' marked as __forceinline not inlined
/wd4351 # new behavior: elements of array 'array' will be default initialized
# TODO: Enable this warning once possible
/wd4245 # conversion from 'type1' to 'type2', signed/unsigned mismatch
# Currently jits use some annoying code patterns which makes this common
)

# Additional warnings
add_compile_options(
/w44263 # Non-virtual member function hides base class virtual function
/w44265 # Class has virtual functions, but destructor is not virtual
)

# Treat all warnings as errors
add_compile_options(/WX)

# All files are encoded as UTF-8
add_compile_options(/utf-8)

endif()

# These aren't actually needed for C11/C++11
# but some dependencies require them (LLVM, libav).
add_definitions(-D__STDC_LIMIT_MACROS)
Expand Down
10 changes: 1 addition & 9 deletions Source/Core/AudioCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,8 @@ if(WIN32)
)
target_link_libraries(audiocommon PRIVATE audiocommon_xaudio27)

set(ENV{OPENALDIR} ${PROJECT_SOURCE_DIR}/Externals/OpenAL)
# Dolphin loads openal32.dll at runtime
find_package(OpenAL)
if(OPENAL_FOUND)
message(STATUS "OpenAL found, enabling OpenAL sound backend")
target_sources(audiocommon PRIVATE OpenALStream.cpp)
target_link_libraries(audiocommon PRIVATE OpenAL::OpenAL)
else()
message(STATUS "OpenAL NOT found in Externals")
endif()
target_sources(audiocommon PRIVATE OpenALStream.cpp)
endif()

target_link_libraries(audiocommon PRIVATE cubeb SoundTouch FreeSurround)
10 changes: 9 additions & 1 deletion Source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ if(ENABLE_QT)
add_subdirectory(DolphinQt)
endif()

if (APPLE)
if (APPLE OR WIN32)
add_subdirectory(UpdaterCommon)
endif()

if (APPLE)
add_subdirectory(MacUpdater)
endif()


if (WIN32)
add_subdirectory(WinUpdater)
endif()
9 changes: 9 additions & 0 deletions Source/Core/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ if (APPLE)
${COREFOUNDATION_LIBRARY}
${IOK_LIBRARY}
)
elseif(WIN32)
target_link_libraries(common
PRIVATE
kernel32.lib
shlwapi.lib
opengl32.lib
winmm.lib
)
endif()

if(ANDROID)
Expand All @@ -78,6 +86,7 @@ if(ANDROID)
)
elseif(WIN32)
target_sources(common PRIVATE
LdrWatcher.cpp
Logging/ConsoleListenerWin.cpp
)
else()
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ if(WIN32)
setupapi.lib
iphlpapi.lib
)
target_compile_definitions(core PRIVATE "-D_WINSOCK_DEPRECATED_NO_WARNINGS")
elseif(APPLE)
target_sources(core PRIVATE
HW/EXI/BBA-TAP/TAP_Apple.cpp
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/IOS/FS/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <string>
#include <vector>

#ifdef _WIN32
// TODO: Horrible hack, remove ASAP!
#include <Windows.h>
#endif

#include "Common/CommonTypes.h"
#include "Common/Result.h"

Expand Down
92 changes: 84 additions & 8 deletions Source/Core/DolphinQt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (NOT Qt5_DIR AND MSVC)
set(Qt5_DIR "${CMAKE_SOURCE_DIR}/Externals/Qt5.11.1/5.11.1/msvc2017_64/lib/cmake/Qt5")
endif()

find_package(Qt5 5.9 REQUIRED COMPONENTS Gui Widgets)

set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES "")
Expand Down Expand Up @@ -107,7 +111,6 @@ add_executable(dolphin-emu
QtUtils/FlowLayout.cpp
QtUtils/ModalMessageBox.cpp
QtUtils/ImageConverter.cpp
QtUtils/SignalDaemon.cpp
QtUtils/WindowActivationEventFilter.cpp
QtUtils/WinIconHelper.cpp
QtUtils/WrapInScrollArea.cpp
Expand All @@ -130,6 +133,10 @@ add_executable(dolphin-emu
Updater.cpp
)

if (NOT WIN32)
target_sources(dolphin-emu PRIVATE QtUtils/SignalDaemon.cpp)
endif()

target_compile_definitions(dolphin-emu
PRIVATE
-DQT_USE_QSTRINGBUILDER
Expand All @@ -152,11 +159,71 @@ PRIVATE
)

if(WIN32)
target_sources(dolphin-emu PRIVATE DolphinQt.manifest)
target_sources(dolphin-emu PRIVATE DolphinQt.manifest DolphinQt.rc)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(Dolphin_NAME "DolphinD")
else()
set(Dolphin_NAME "Dolphin")
endif()

set_target_properties(dolphin-emu PROPERTIES
WIN32_EXECUTABLE TRUE
OUTPUT_NAME ${Dolphin_NAME}
)

target_compile_options(dolphin-emu PRIVATE "-D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING")

# Copy Sys dir
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/Data/Sys")
file(GLOB_RECURSE resources RELATIVE "${CMAKE_SOURCE_DIR}/Data" "${CMAKE_SOURCE_DIR}/Data/Sys/*")

foreach(res ${resources})
configure_file("${CMAKE_SOURCE_DIR}/Data/${res}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${res}" COPYONLY)
endforeach()

# Copy qt.conf
configure_file(qt.conf.win "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf" COPYONLY)

# Copy plugins
set (Qt5_PLUGINS_DIR "${Qt5_DIR}/../../../plugins")
file(GLOB_RECURSE plugins RELATIVE "${Qt5_PLUGINS_DIR}" "${Qt5_PLUGINS_DIR}/*.dll")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(FILTER plugins INCLUDE REGEX ".*d.dll")
else()
list(FILTER plugins EXCLUDE REGEX ".*d.dll")
endif()

foreach(plugin ${plugins})
configure_file("${Qt5_PLUGINS_DIR}/${plugin}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/QtPlugins/${plugin}" COPYONLY)
endforeach()

# Copy DLLs
set (Qt5_DLL_DIR "${Qt5_DIR}/../../../bin")

file(GLOB_RECURSE dlls RELATIVE "${Qt5_DLL_DIR}" "${Qt5_DLL_DIR}/*.dll")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(FILTER dlls INCLUDE REGEX ".*d.dll")
else()
list(FILTER dlls EXCLUDE REGEX ".*d.dll")
endif()

foreach(dll ${dlls})
configure_file("${Qt5_DLL_DIR}/${dll}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${dll}" COPYONLY)
endforeach()

endif()

# Handle localization
find_package(Gettext)

if(WIN32 AND NOT Gettext_FOUND)
message(STATUS "Using Gettext from Externals")
set(GETTEXT_MSGFMT_EXECUTABLE "${CMAKE_SOURCE_DIR}/Externals/gettext/msgfmt.exe")
endif()

if(GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
set(pot_file "${CMAKE_SOURCE_DIR}/Languages/po/dolphin-emu.pot")
file(GLOB LINGUAS ${CMAKE_SOURCE_DIR}/Languages/po/*.po)
Expand All @@ -179,12 +246,21 @@ if(GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
install(FILES ${mo} DESTINATION share/locale/${lang}/LC_MESSAGES)
endif()

add_custom_command(OUTPUT ${mo}
COMMAND cmake -E make_directory ${mo_dir}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${po} ${pot_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
DEPENDS ${po}
)
if(WIN32)
add_custom_command(OUTPUT ${mo}
COMMAND ${CMAKE_COMMAND} -E make_directory ${mo_dir}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
COMMAND ${CMAKE_COMMAND} -E copy ${mo} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Languages/${lang}/dolphin-emu.mo
DEPENDS ${po}
)
else()
add_custom_command(OUTPUT ${mo}
COMMAND ${CMAKE_COMMAND} -E make_directory ${mo_dir}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${po} ${pot_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
DEPENDS ${po}
)
endif()
endforeach()
endif()

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/qt.conf.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Paths]
Plugins = ./QtPlugins
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <windows.h>
#include <list>
#include <string>

#include "InputCommon/ControllerInterface/DInput/DInput8.h"

Expand Down
1 change: 1 addition & 0 deletions Source/Core/InputCommon/ControllerInterface/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "InputCommon/ControllerInterface/Device.h"

#include <algorithm>
#include <cmath>
#include <memory>
#include <sstream>
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/UICommon/VideoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "Common/Assert.h"
#include "VideoCommon/VideoConfig.h"

#ifdef _WIN32
#include <Windows.h>
#endif

#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include "UICommon/X11Utils.h"
#endif
Expand Down
Loading

0 comments on commit ec73406

Please sign in to comment.