From 47c2b29395c1dd6582167ea63ec6ab4afea3b17d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 16 May 2020 13:10:31 +1000 Subject: [PATCH] Build: Use bin directory for cmake, fix Windows/cmake build --- CMakeLists.txt | 11 +++++++++++ appimage/generate-appimages.sh | 4 ++-- dep/msvc/qt | 2 +- src/duckstation-qt/CMakeLists.txt | 23 +++++++++++++++++++++++ src/duckstation-qt/qt.conf.win | 2 ++ src/duckstation-sdl/CMakeLists.txt | 5 +++++ src/frontend-common/CMakeLists.txt | 11 +++++++++++ src/scmversion/CMakeLists.txt | 7 +++++-- 8 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/duckstation-qt/qt.conf.win diff --git a/CMakeLists.txt b/CMakeLists.txt index 99bbc91df..a95ad255d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,10 +19,12 @@ if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib64/SDL2.lib") set(SDL2MAIN_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib64/SDL2main.lib") + set(SDL2_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/bin64/SDL2.dll") set(Qt5_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/qt/5.14.0/msvc2017_64/lib/cmake/Qt5") else() set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib32/SDL2.lib") set(SDL2MAIN_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib32/SDL2main.lib") + set(SDL2_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/bin32/SDL2.dll") set(Qt5_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/qt/5.14.0/msvc2017_32/lib/cmake/Qt5") endif() endif() @@ -111,6 +113,15 @@ else() endif() +# Write binaries to a seperate directory. +if(WIN32) + # For Windows, use the source directory. + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/${CPU_ARCH}") +else() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") +endif() + + # Enable threads everywhere. set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) diff --git a/appimage/generate-appimages.sh b/appimage/generate-appimages.sh index 8c0e92a39..9474fb66c 100755 --- a/appimage/generate-appimages.sh +++ b/appimage/generate-appimages.sh @@ -46,7 +46,7 @@ done ${BUILD_DIR}/linuxdeploy-x86_64.AppImage \ --appdir=${BUILD_DIR}/AppDir-duckstation-qt \ - --executable=${BUILD_DIR}/src/duckstation-qt/duckstation-qt \ + --executable=${BUILD_DIR}/bin/duckstation-qt \ --desktop-file=${APPIMAGE_RESOURCES_DIR}/duckstation-qt.desktop \ ${ICONS_QT[@]/#/--icon-file=} \ --plugin=qt \ @@ -55,7 +55,7 @@ ${BUILD_DIR}/linuxdeploy-x86_64.AppImage \ ${BUILD_DIR}/linuxdeploy-x86_64.AppImage \ --appdir=${BUILD_DIR}/AppDir-duckstation-sdl \ - --executable=${BUILD_DIR}/src/duckstation-sdl/duckstation-sdl \ + --executable=${BUILD_DIR}/bin/duckstation-sdl \ --desktop-file=${APPIMAGE_RESOURCES_DIR}/duckstation-sdl.desktop \ ${ICONS_SDL[@]/#/--icon-file=} \ --output=appimage \ diff --git a/dep/msvc/qt b/dep/msvc/qt index c61fdc2a0..6afb5f4a3 160000 --- a/dep/msvc/qt +++ b/dep/msvc/qt @@ -1 +1 @@ -Subproject commit c61fdc2a064825b39be394c6f2b7808df35f3398 +Subproject commit 6afb5f4a3e77dcb1b09059adc839a2813d0ea1dc diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index 973316ee1..a7879fa1b 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -61,6 +61,29 @@ if(WIN32) d3d11hostdisplay.h ) target_link_libraries(duckstation-qt PRIVATE d3d11.lib dxgi.lib) + + # We want a Windows subsystem application not console. + set_target_properties(duckstation-qt PROPERTIES + WIN32_EXECUTABLE TRUE + DEBUG_POSTFIX "-debug") + + # Copy in Qt DLLs. Borrowed from Dolphin. + get_target_property(MOC_EXECUTABLE_LOCATION Qt5::moc IMPORTED_LOCATION) + get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY) + find_program(WINDEPLOYQT_EXE windeployqt HINTS "${QT_BINARY_DIRECTORY}") + add_custom_command(TARGET duckstation-qt POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E env PATH="${QT_BINARY_DIRECTORY}" + "${WINDEPLOYQT_EXE}" --libdir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + --plugindir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/QtPlugins" + $,--debug,--release> + --no-translations + --no-compiler-runtime + --no-angle + "$" + ) + add_custom_command(TARGET duckstation-qt POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.win" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf" + ) else() if(OpenGL_GLX_FOUND) target_compile_definitions(duckstation-qt PRIVATE "HAS_GLX") diff --git a/src/duckstation-qt/qt.conf.win b/src/duckstation-qt/qt.conf.win new file mode 100644 index 000000000..4931bd100 --- /dev/null +++ b/src/duckstation-qt/qt.conf.win @@ -0,0 +1,2 @@ +[Paths] +Plugins = ./QtPlugins diff --git a/src/duckstation-sdl/CMakeLists.txt b/src/duckstation-sdl/CMakeLists.txt index 8d7120851..4c5d5f29f 100644 --- a/src/duckstation-sdl/CMakeLists.txt +++ b/src/duckstation-sdl/CMakeLists.txt @@ -19,5 +19,10 @@ if(WIN32) duckstation-sdl.manifest ) target_link_libraries(duckstation-sdl PRIVATE d3d11.lib dxgi.lib ${SDL2MAIN_LIBRARIES}) + + # We want a Windows subsystem application not console. + set_target_properties(duckstation-sdl PROPERTIES + WIN32_EXECUTABLE TRUE + DEBUG_POSTFIX "-debug") endif() diff --git a/src/frontend-common/CMakeLists.txt b/src/frontend-common/CMakeLists.txt index d31915019..ecfa220bd 100644 --- a/src/frontend-common/CMakeLists.txt +++ b/src/frontend-common/CMakeLists.txt @@ -27,9 +27,20 @@ if(SDL2_FOUND) target_compile_definitions(frontend-common PRIVATE "WITH_SDL2=1") target_include_directories(frontend-common PRIVATE ${SDL2_INCLUDE_DIRS}) target_link_libraries(frontend-common PRIVATE ${SDL2_LIBRARIES}) + + # Copy bundled SDL2 to output on Windows. + if(WIN32) + add_custom_command(TARGET frontend-common POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SDL2_DLL_PATH}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/SDL2.dll") + endif() endif() if(ENABLE_DISCORD_PRESENCE) target_compile_definitions(frontend-common PUBLIC -DWITH_DISCORD_PRESENCE=1) target_link_libraries(frontend-common PRIVATE discord-rpc) endif() + +# Copy the provided data directory to the output directory. +add_custom_command(TARGET frontend-common POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/data" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" +) \ No newline at end of file diff --git a/src/scmversion/CMakeLists.txt b/src/scmversion/CMakeLists.txt index 1d4121ea5..cc3a234d4 100644 --- a/src/scmversion/CMakeLists.txt +++ b/src/scmversion/CMakeLists.txt @@ -1,7 +1,10 @@ if(WIN32) - add_custom_command(OUTPUT scmversion.cpp COMMAND "cmd /k gen_scmversion.bat" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_custom_command(OUTPUT scmversion.cpp + COMMAND cmd /k "${CMAKE_CURRENT_SOURCE_DIR}/gen_scmversion.bat" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") else() - add_custom_command(OUTPUT scmversion.cpp COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/gen_scmversion.sh") + add_custom_command(OUTPUT scmversion.cpp + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/gen_scmversion.sh") endif() add_library(scmversion