-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build the entire project from the root CMakeLists.txt (#304)
- Loading branch information
1 parent
f8ece3d
commit ae379aa
Showing
15 changed files
with
191 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
add_subdirectory(Extensions) | ||
|
||
file(GLOB_RECURSE SOURCES *.swift) | ||
add_executable(SwiftWinRT ${SOURCES}) | ||
|
||
file(GLOB RESOURCES Extensions/*_swift) | ||
set(PACKAGERESOURCES_SWIFT ${CMAKE_CURRENT_BINARY_DIR}/PackageResources.swift) | ||
file(WRITE ${PACKAGERESOURCES_SWIFT} "enum PackageResources {\n") | ||
foreach(RESOURCE ${RESOURCES}) | ||
get_filename_component(RESOURCE_NAME ${RESOURCE} NAME) | ||
file(READ ${RESOURCE} RESOURCE_HEX HEX) | ||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," RESOURCE_HEX ${RESOURCE_HEX}) | ||
file(APPEND ${PACKAGERESOURCES_SWIFT} " static let ${RESOURCE_NAME}: [UInt8] = [ ${RESOURCE_HEX} ]\n") | ||
endforeach() | ||
file(APPEND ${PACKAGERESOURCES_SWIFT} "}\n") | ||
target_sources(SwiftWinRT PRIVATE ${PACKAGERESOURCES_SWIFT}) | ||
|
||
target_sources(SwiftWinRT PRIVATE "${PACKAGERESOURCES_SWIFT_FILE}") | ||
target_link_libraries(SwiftWinRT PRIVATE | ||
ArgumentParser Collections DotNetMetadata DotNetMetadataFormat WindowsMetadata | ||
CodeWriters ProjectionModel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Build the resource embedding code | ||
set(PACKAGERESOURCES_CODE "enum PackageResources {\n") | ||
file(GLOB RESOURCES "*_swift") | ||
foreach(RESOURCE ${RESOURCES}) | ||
get_filename_component(RESOURCE_NAME ${RESOURCE} NAME) | ||
file(READ ${RESOURCE} RESOURCE_HEX HEX) | ||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," RESOURCE_HEX ${RESOURCE_HEX}) | ||
string(APPEND PACKAGERESOURCES_CODE " static let ${RESOURCE_NAME}: [UInt8] = [ ${RESOURCE_HEX} ]\n") | ||
endforeach() | ||
string(APPEND PACKAGERESOURCES_CODE "}\n") | ||
|
||
# Update the file if the code has changed | ||
set(PACKAGERESOURCES_SWIFT_FILE "${CMAKE_CURRENT_BINARY_DIR}/PackageResources.swift") | ||
set(PACKAGERESOURCES_OLD_CODE "") | ||
if(EXISTS "${PACKAGERESOURCES_SWIFT_FILE}") | ||
file(READ "${PACKAGERESOURCES_SWIFT_FILE}" PACKAGERESOURCES_OLD_CODE) | ||
endif() | ||
if(NOT "${PACKAGERESOURCES_CODE}" STREQUAL "${PACKAGERESOURCES_OLD_CODE}") | ||
file(WRITE "${PACKAGERESOURCES_SWIFT_FILE}" "${PACKAGERESOURCES_CODE}") | ||
endif() | ||
|
||
# Return the path | ||
set(PACKAGERESOURCES_SWIFT_FILE "${PACKAGERESOURCES_SWIFT_FILE}" PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
cmake_minimum_required(VERSION 3.21.0) | ||
|
||
project(WinRTComponent LANGUAGES CXX) | ||
|
||
# Generate the WinMDs from the idl files | ||
message(STATUS "Generating WinRTComponent.winmd...") | ||
set(MIDLRT.EXE_PATH_NATIVE "$ENV{WindowsSdkVerBinPath}$ENV{VSCMD_ARG_HOST_ARCH}\\midlrt.exe") | ||
cmake_path(CONVERT "$ENV{WindowsSdkDir}References\\$ENV{WindowsSDKVersion}" TO_CMAKE_PATH_LIST WINSDK_REFERENCES_DIR NORMALIZE) | ||
set(FOUNDATIONCONTRACT_DIR "${WINSDK_REFERENCES_DIR}/Windows.Foundation.FoundationContract/4.0.0.0") | ||
cmake_path(CONVERT "${FOUNDATIONCONTRACT_DIR}" TO_NATIVE_PATH_LIST METADATA_DIR_NATIVE) | ||
cmake_path(CONVERT "${FOUNDATIONCONTRACT_DIR}/Windows.Foundation.FoundationContract.winmd" TO_NATIVE_PATH_LIST FOUNDATIONCONTRACT_WINMD_NATIVE) | ||
cmake_path(CONVERT "${WINSDK_REFERENCES_DIR}/Windows.Foundation.UniversalApiContract/15.0.0.0/Windows.Foundation.UniversalApiContract.winmd" TO_NATIVE_PATH_LIST UNIVERSALAPICONTRACT_WINMD_NATIVE) | ||
cmake_path(CONVERT "${CMAKE_CURRENT_BINARY_DIR}/WinRTComponent.winmd" TO_NATIVE_PATH_LIST WINRTCOMPONENT_WINMD_PATH_NATIVE) | ||
cmake_path(CONVERT "${CMAKE_CURRENT_BINARY_DIR}/WinRTComponent.h" TO_NATIVE_PATH_LIST WINRTCOMPONENT_H_PATH_NATIVE) | ||
cmake_path(CONVERT "${CMAKE_CURRENT_SOURCE_DIR}/WinRTComponent.idl" TO_NATIVE_PATH_LIST IDL_PATH_NATIVE) | ||
execute_process( | ||
COMMAND "${MIDLRT.EXE_PATH_NATIVE}" | ||
/W1 /nologo /nomidl | ||
/metadata_dir "${METADATA_DIR_NATIVE}" | ||
/reference "${FOUNDATIONCONTRACT_WINMD_NATIVE}" | ||
/reference "${UNIVERSALAPICONTRACT_WINMD_NATIVE}" | ||
/winmd "${WINRTCOMPONENT_WINMD_PATH_NATIVE}" | ||
/header "${WINRTCOMPONENT_H_PATH_NATIVE}" | ||
"${IDL_PATH_NATIVE}" | ||
COMMAND_ERROR_IS_FATAL ANY) | ||
|
||
# Generate the C++/WinRT boilerplate | ||
message(STATUS "Generating C++/WinRT boilerplate for WinRTComponent...") | ||
set(CPPWINRT.EXE_PATH_NATIVE "$ENV{WindowsSdkVerBinPath}$ENV{VSCMD_ARG_HOST_ARCH}\\cppwinrt.exe") | ||
string(REPLACE "\\" "" WINSDK_VERSION "$ENV{WindowsSDKVersion}") | ||
set(CPPWINRT_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/CppWinRT") | ||
cmake_path(CONVERT "${CPPWINRT_GENERATED_DIR}" TO_NATIVE_PATH_LIST CPPWINRT_GENERATED_DIR_NATIVE) | ||
execute_process( | ||
COMMAND "${CPPWINRT.EXE_PATH_NATIVE}" | ||
-input "${WINRTCOMPONENT_WINMD_PATH_NATIVE}" | ||
-reference "${WINSDK_VERSION}" | ||
-component "${CPPWINRT_GENERATED_DIR_NATIVE}" -overwrite -optimize | ||
-output "${CPPWINRT_GENERATED_DIR_NATIVE}" | ||
COMMAND_ERROR_IS_FATAL ANY) | ||
|
||
# Build WinRTComponent.dll | ||
file(GLOB SOURCES "*.cpp") | ||
add_library(WinRTComponent SHARED | ||
${SOURCES} | ||
"${CPPWINRT_GENERATED_DIR}/module.g.cpp" # Other .g.cpp files are #included by our .cpp files | ||
WinRTComponent.def) | ||
target_include_directories(WinRTComponent PRIVATE | ||
"${CMAKE_CURRENT_SOURCES_DIR}" | ||
"${CPPWINRT_GENERATED_DIR}") | ||
target_precompile_headers(WinRTComponent PRIVATE pch.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"version": 3, | ||
"cmakeMinimumRequired": { | ||
"major": 3, | ||
"minor": 21, | ||
"patch": 0 | ||
}, | ||
"configurePresets": [ | ||
{ | ||
"name": "debug", | ||
"displayName": "Debug", | ||
"generator": "Ninja", | ||
"binaryDir": "${sourceDir}/build/debug", | ||
"cacheVariables": { | ||
"CMAKE_BUILD_TYPE": "Debug", | ||
"CMAKE_CXX_COMPILER": "cl", | ||
"CMAKE_CXX_FLAGS": "/std:c++latest /W4 /EHsc" | ||
} | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "debug", | ||
"displayName": "Debug", | ||
"configurePreset": "debug" | ||
} | ||
] | ||
} |
54 changes: 27 additions & 27 deletions
54
InteropTests/WinRTComponent/All.idl → ...opTests/WinRTComponent/WinRTComponent.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
// Includes all .idl files so we have a single <Midl Include="All.idl"> entry in the vcxproj. | ||
// This speeds up the build by avoiding multiple midlrt calls followed by an mdmerge step. | ||
#include "Arrays.idl" | ||
#include "ByteBuffers.idl" | ||
#include "Collections.idl" | ||
#include "DateTimes.idl" | ||
#include "Enums.idl" | ||
#include "Errors.idl" | ||
#include "Events.idl" | ||
#include "ForCustomActivationFactoryResolution.idl" | ||
#include "InspectableBoxing.idl" | ||
#include "Int32Wrapper.idl" | ||
#include "InterfaceCasting.idl" | ||
#include "ManualAsyncOperation.idl" | ||
#include "MinimalTypes.idl" | ||
#include "MinimalUnsealedClasses.idl" | ||
#include "NullValues.idl" | ||
#include "Numbers.idl" | ||
#include "ObjectReferencer.idl" | ||
#include "OutputArgument.idl" | ||
#include "OverloadedSum.idl" | ||
#include "ReferenceBoxing.idl" | ||
#include "ReturnArgument.idl" | ||
#include "Strings.idl" | ||
#include "Structs.idl" | ||
#include "SwiftAttributes.idl" | ||
#include "SwiftEnum.idl" | ||
// Includes all .idl files so we have a single <Midl Include="All.idl"> entry in the vcxproj. | ||
// This speeds up the build by avoiding multiple midlrt calls followed by an mdmerge step. | ||
#include "Arrays.idl" | ||
#include "ByteBuffers.idl" | ||
#include "Collections.idl" | ||
#include "DateTimes.idl" | ||
#include "Enums.idl" | ||
#include "Errors.idl" | ||
#include "Events.idl" | ||
#include "ForCustomActivationFactoryResolution.idl" | ||
#include "InspectableBoxing.idl" | ||
#include "Int32Wrapper.idl" | ||
#include "InterfaceCasting.idl" | ||
#include "ManualAsyncOperation.idl" | ||
#include "MinimalTypes.idl" | ||
#include "MinimalUnsealedClasses.idl" | ||
#include "NullValues.idl" | ||
#include "Numbers.idl" | ||
#include "ObjectReferencer.idl" | ||
#include "OutputArgument.idl" | ||
#include "OverloadedSum.idl" | ||
#include "ReferenceBoxing.idl" | ||
#include "ReturnArgument.idl" | ||
#include "Strings.idl" | ||
#include "Structs.idl" | ||
#include "SwiftAttributes.idl" | ||
#include "SwiftEnum.idl" | ||
#include "WeakReferencer.idl" |
Oops, something went wrong.