From d67e95fd96f1534cf4fbba485652e0e75d8de1fb Mon Sep 17 00:00:00 2001 From: baconpaul Date: Tue, 14 Apr 2020 08:53:01 -0400 Subject: [PATCH] CMake for Windows Move windows to CMake. Confirmed this builds a VST2 and 3 which loads in reaper (if you have VSt2 set up obviously) Addresse #1206 --- CMakeLists.txt | 109 ++++++++++++++++++++++++++++++++------ azure-pipelines.yml | 22 ++++---- buildtask.xml | 2 +- scripts/win/build-win.ps1 | 6 --- 4 files changed, 107 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9faefa34938..234fa6fe9db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -357,21 +357,65 @@ elseif( UNIX AND NOT APPLE ) COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/linux/emit-vector-piggy.py ${CMAKE_CURRENT_SOURCE_DIR} ) -elseif( WINDOWS ) +elseif( WIN32 ) - set(WINDOWS_COMPILE_DEFINITIONS + set(SURGE_OS_SOURCES + src/windows/UserInteractionsWin.cpp + ) + + set(SURGE_OS_GUI_SOURCES + src/windows/DisplayInfoWin.cpp + src/windows/RuntimeFontWin.cpp + src/windows/surge.rc + vstgui.surge/vstgui/vstgui_win32.cpp + vstgui.surge/vstgui/vstgui_uidescription_win32.cpp + ) + + set(OS_COMPILE_DEFINITIONS WINDOWS=1 NOMINMAX=1 - ) + WIN32 + _WIN32_WINNT=0x0601 + _USRDLL + VA_SUBTRACTIVE_EXPORTS + TIXML_USE_STL + USE_LIBPNG + _CRT_SECURE_NO_WARNINGS=1 + ) + + if( ${CMAKE_SIZEOF_VOID_P} EQUAL 4 ) + set( WIN_DLL_BASENAME "Surge_x86" ) + list( APPEND OS_COMPILE_DEFINITIONS WIN_X86=1 ) + else() + set( WIN_DLL_BASENAME "Surge" ) + endif() + - set(WINDOWS_COMPILE_OPTIONS + set(OS_COMPILE_OPTIONS /arch:SSE2 - "/FI precompiled.h" + /FIprecompiled.h /Zc:alignedNew /bigobj ) + + set(OS_INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} + src/windows + libs/wtl + ) + + set(OS_LINK_LIBRARIES + Winmm + gdi32 + gdiplus + ComDlg32 + ComCtl32 + shell32 + user32 + ../libs/libpng/win/x64/lib/libpng16_static + ) else() - message( "UNKNOWN OS. Please use lin mac or win" ) + message(FATAL_ERROR "UNKNOWN OS. Please use lin mac or win" ) endif() @@ -455,7 +499,12 @@ if( BUILD_VST3 ) src/linux/LinuxVST3Helpers.cpp) endif() - + + if( WIN32 ) + target_sources(surge-vst3 PUBLIC vst3sdk/public.sdk/source/main/dllmain.cpp) + target_link_options( surge-vst3 PUBLIC "/DEF:..\\resources\\windows-vst3\\surge.def" ) + endif() + target_compile_definitions(surge-vst3 PRIVATE ${OS_COMPILE_DEFINITIONS} @@ -467,6 +516,7 @@ if( BUILD_VST3 ) ${OS_COMPILE_OPTIONS} ) + message( "ADDING OS INCLUDE " ${OS_INCLUDE_DIRECTORIES}) target_include_directories(surge-vst3 PRIVATE ${SURGE_COMMON_INCLUDES} @@ -501,6 +551,17 @@ if( BUILD_VST3 ) COMMAND pwd COMMAND ./scripts/linux/package-vst3.sh ) + elseif( WIN32 ) + add_custom_target( surgev3-dll ALL ) + add_dependencies( surgev3-dll surge-vst3 ) + add_custom_command( + TARGET surgev3-dll + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/target/vst3/Release + + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/Release/surge-vst3.dll + ${CMAKE_CURRENT_SOURCE_DIR}/target/vst3/Release/${WIN_DLL_BASENAME}.vst3 + ) endif() endif() @@ -528,6 +589,9 @@ if( BUILD_VST2 ) # change is this diff plus this comment. target_compile_definitions( surge-vst2 PRIVATE "__cdecl=" ) endif() + if( WIN32 ) + target_link_options( surge-vst2 PUBLIC "/DEF:..\\resources\\windows-vst2\\surge.def" ) + endif() target_compile_features(surge-vst2 PRIVATE cxx_std_17 ) @@ -557,14 +621,29 @@ if( BUILD_VST2 ) ${OS_LINK_LIBRARIES} ) - add_custom_target( Surge.vst2 ALL ) - add_dependencies( Surge.vst2 surge-vst2 ) - add_custom_command( - TARGET Surge.vst2 - POST_BUILD - COMMAND echo "Packaging up VST2 component" - COMMAND (cd .. && ./scripts/macOS/package-vst.sh ) - ) + if( APPLE ) + add_custom_target( Surge.vst2 ALL ) + add_dependencies( Surge.vst2 surge-vst2 ) + add_custom_command( + TARGET Surge.vst2 + POST_BUILD + COMMAND echo "Packaging up VST2 component" + COMMAND (cd .. && ./scripts/macOS/package-vst.sh ) + ) + endif() + + if( WIN32 ) + add_custom_target( surgev2-dll ALL ) + add_dependencies( surgev2-dll surge-vst2 ) + add_custom_command( + TARGET surgev2-dll + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/target/vst2/Release + + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/Release/surge-vst2.dll + ${CMAKE_CURRENT_SOURCE_DIR}/target/vst2/Release/${WIN_DLL_BASENAME}.dll + ) + endif() endif() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 89bc405a0b5..606b2f845e5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -80,18 +80,20 @@ jobs: displayName: macOS - run unit tests - bash: | - pushd $AGENT_TEMPDIRECTORY - export PREMAKE_WINDOWS=https://github.com/premake/premake-core/releases/download/v5.0.0-alpha13/premake-5.0.0-alpha13-windows.zip - curl -L $PREMAKE_WINDOWS --output premake5.zip - unzip premake5.zip - popd + mkdir -p build + cmake -Bbuild + ls -alFh build - export PATH=$AGENT_TEMPDIRECTORY:$PATH - premake5 vs2017 - ls -alFh + condition: and(variables.isWindows, variables.is64bit) + displayName: windows - run cmake for x64 + + - bash: | + mkdir -p build + cmake -Bbuild -A Win32 + ls -alFh build - condition: variables.isWindows - displayName: windows - setup premake for plugins + condition: and(variables.isWindows, variables.is32bit) + displayName: windows - setup cmake for Win32 - task: MSBuild@1 inputs: diff --git a/buildtask.xml b/buildtask.xml index 39d7f1f2826..0ee58740590 100644 --- a/buildtask.xml +++ b/buildtask.xml @@ -1,6 +1,6 @@ - + Configuration=Release diff --git a/scripts/win/build-win.ps1 b/scripts/win/build-win.ps1 index 4570430c46a..23a22a4aeac 100644 --- a/scripts/win/build-win.ps1 +++ b/scripts/win/build-win.ps1 @@ -57,12 +57,6 @@ if( $w32 ) } -If( -Not ( Test-Path .\Surge.sln ) ) -{ - Write-Host "Please run premake" - return -} - function Build-Surge { Write-Host "Building"