Skip to content

Commit

Permalink
Windows SA: Total refactor (#280)
Browse files Browse the repository at this point in the history
* Windows SA: Total refactor

* Remove designated initializers, they are C++ 20

* Remove logging for WINDOWPOS
  • Loading branch information
mthierman authored Aug 17, 2024
1 parent ec2f09c commit d247d4d
Show file tree
Hide file tree
Showing 18 changed files with 1,883 additions and 554 deletions.
31 changes: 31 additions & 0 deletions cmake/base_sdks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,34 @@ function(guarantee_rtmidi)
add_library(base-sdk-rtmidi INTERFACE)
target_link_libraries(base-sdk-rtmidi INTERFACE rtmidi)
endfunction(guarantee_rtmidi)

function(guarantee_wil)
if (TARGET base-sdk-wil)
return()
endif()

if (NOT "${WIL_SDK_ROOT}" STREQUAL "")
# Use the provided root
elseif (${CLAP_WRAPPER_DOWNLOAD_DEPENDENCIES})
guarantee_cpm()
CPMAddPackage(
NAME "wil"
GITHUB_REPOSITORY "microsoft/wil"
GIT_TAG "v1.0.240803.1"
EXCLUDE_FROM_ALL TRUE
DOWNLOAD_ONLY TRUE
SOURCE_DIR cpm/wil
)
set(WIL_SDK_ROOT "${CMAKE_CURRENT_BINARY_DIR}/cpm/wil")
else()
search_for_sdk_source(SDKDIR wil RESULT WIL_SDK_ROOT)
endif()

cmake_path(CONVERT "${WIL_SDK_ROOT}" TO_CMAKE_PATH_LIST WIL_SDK_ROOT)
if(NOT EXISTS "${WIL_SDK_ROOT}/include/wil/common.h")
message(FATAL_ERROR "There is no wil at ${WIL_SDK_ROOT}. Please set WIL_SDK_ROOT appropriately ")
endif()

add_library(base-sdk-wil INTERFACE)
target_include_directories(base-sdk-wil INTERFACE "${WIL_SDK_ROOT}/include")
endfunction(guarantee_wil)
63 changes: 52 additions & 11 deletions cmake/wrap_standalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function(target_add_standalone_wrapper)
STATICALLY_LINKED_CLAP_ENTRY
HOSTED_CLAP_NAME

WIN32_ICON

MACOS_EMBEDDED_CLAP_LOCATION
)
cmake_parse_arguments(SA "" "${oneValueArgs}" "" ${ARGN} )
Expand All @@ -35,6 +37,10 @@ function(target_add_standalone_wrapper)
set(SA_OUTPUT_NAME ${SA_TARGET})
endif()

if (NOT DEFINED SA_WIN32_ICON)
set(SA_WIN32_ICON "")
endif()

guarantee_rtaudio()
guarantee_rtmidi()

Expand Down Expand Up @@ -95,20 +101,55 @@ function(target_add_standalone_wrapper)
macos_include_clap_in_bundle(TARGET ${SA_TARGET}
MACOS_EMBEDDED_CLAP_LOCATION ${SA_MACOS_EMBEDDED_CLAP_LOCATION})

elseif(WIN32 AND (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
elseif(WIN32 AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
if(NOT "${SA_WIN32_ICON}" STREQUAL "")
message(STATUS "Win32 icon found: ${SA_WIN32_ICON}")
file(WRITE "${CMAKE_BINARY_DIR}/standalone_win32.rc" "1 ICON \"standalone_win32.ico\"")
file(COPY_FILE ${SA_WIN32_ICON} "${CMAKE_BINARY_DIR}/standalone_win32.ico")
else()
message(STATUS "Win32 icon not found, using default")
endif()

set_target_properties(${SA_TARGET} PROPERTIES
WIN32_EXECUTABLE TRUE
)
WIN32_EXECUTABLE TRUE
)

target_compile_definitions(${salib} PUBLIC
NOMINMAX
WIN32_LEAN_AND_MEAN
CLAP_WRAPPER_HAS_WIN32
)

target_sources(${SA_TARGET} PRIVATE
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/winutils.cpp
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/win32.manifest
)
"${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/wrapasstandalone_win32.cpp"
"${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/host_window.cpp"
# "${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/settings_window.cpp"
"${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/helpers.cpp"
"${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/standalone/windows/standalone.manifest"
)

target_compile_definitions(${salib} PUBLIC
CLAP_WRAPPER_HAS_WIN32
WIN32_NAME="${SA_OUTPUT_NAME}"
)
guarantee_wil()
target_link_libraries(${SA_TARGET} PRIVATE base-sdk-wil)

if(NOT "${SA_WIN32_ICON}" STREQUAL "")
target_sources(${SA_TARGET} PRIVATE
"${CMAKE_BINARY_DIR}/standalone_win32.rc"
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_options(
${SA_TARGET}
PRIVATE
/entry:mainCRTStartup
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_options(
${SA_TARGET}
PRIVATE
-Wl,/entry:mainCRTStartup
)
endif()

elseif(UNIX)
target_sources(${SA_TARGET} PRIVATE
Expand Down Expand Up @@ -140,7 +181,7 @@ function(target_add_standalone_wrapper)
PLUGIN_INDEX=${SA_PLUGIN_INDEX}
$<$<BOOL:${SA_STATICALLY_LINKED_CLAP_ENTRY}>:STATICALLY_LINKED_CLAP_ENTRY=1>
$<$<BOOL:${hasclapname}>:HOSTED_CLAP_NAME="${SA_HOSTED_CLAP_NAME}">
OUTPUT_NAME="${OUTPUT_NAME}"
OUTPUT_NAME="${SA_OUTPUT_NAME}"
)

target_link_libraries(${SA_TARGET} PRIVATE
Expand Down
Loading

0 comments on commit d247d4d

Please sign in to comment.