11# This CMake build file is intended for use with the llvm-mingw toolchain:
22# https://github.com/mstorsjo/llvm-mingw
33#
4+ # It also works for building natively on Linux, or cross-building from Linux
5+ # for running on Windows with a mingw-w64 toolchain.
6+ #
47# It most probably doesn't work with MSVC.
58
69cmake_minimum_required (VERSION 3.16 )
@@ -16,8 +19,10 @@ if(CPPWINRT_BUILD_VERSION STREQUAL "2.3.4.5" OR CPPWINRT_BUILD_VERSION STREQUAL
1619endif ()
1720message (STATUS "Using version string: ${CPPWINRT_BUILD_VERSION} " )
1821
19- # WinMD uses CreateFile2 which requires Windows 8.
20- add_compile_definitions (_WIN32_WINNT=0x0602 )
22+ if (WIN32 )
23+ # WinMD uses CreateFile2 which requires Windows 8.
24+ add_compile_definitions (_WIN32_WINNT=0x0602 )
25+ endif ()
2126
2227
2328# === prebuild: Generator tool for strings.cpp, strings.h, version.rc ===
@@ -77,32 +82,37 @@ set(CPPWINRT_HEADERS
7782 cppwinrt/type_writers.h
7883)
7984
80- add_custom_command (
81- OUTPUT
82- "${PROJECT_BINARY_DIR} /app.manifest"
83- COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR} /cppwinrt/app.manifest" "${PROJECT_BINARY_DIR} /app.manifest"
84- DEPENDS "${PROJECT_SOURCE_DIR} /cppwinrt/app.manifest"
85- VERBATIM
86- )
87- # Do the configure_file dance so that app.manifest.rc don't get modified every
88- # single time the project is reconfigured and trigger a rebuild.
89- file (WRITE "${PROJECT_BINARY_DIR} /app.manifest.rc.in" "1 24 \" app.manifest\"\n " )
90- configure_file (
91- "${PROJECT_BINARY_DIR} /app.manifest.rc.in"
92- "${PROJECT_BINARY_DIR} /app.manifest.rc"
93- COPYONLY
94- )
85+ if (WIN32 )
86+ add_custom_command (
87+ OUTPUT
88+ "${PROJECT_BINARY_DIR} /app.manifest"
89+ COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR} /cppwinrt/app.manifest" "${PROJECT_BINARY_DIR} /app.manifest"
90+ DEPENDS "${PROJECT_SOURCE_DIR} /cppwinrt/app.manifest"
91+ VERBATIM
92+ )
93+ # Do the configure_file dance so that app.manifest.rc don't get modified every
94+ # single time the project is reconfigured and trigger a rebuild.
95+ file (WRITE "${PROJECT_BINARY_DIR} /app.manifest.rc.in" "1 24 \" app.manifest\"\n " )
96+ configure_file (
97+ "${PROJECT_BINARY_DIR} /app.manifest.rc.in"
98+ "${PROJECT_BINARY_DIR} /app.manifest.rc"
99+ COPYONLY
100+ )
95101
96- set (CPPWINRT_RESOURCES
97- "${PROJECT_BINARY_DIR} /app.manifest"
98- "${PROJECT_BINARY_DIR} /app.manifest.rc"
99- "${PROJECT_BINARY_DIR} /version.rc"
100- )
102+ set (CPPWINRT_RESOURCES
103+ "${PROJECT_BINARY_DIR} /app.manifest"
104+ "${PROJECT_BINARY_DIR} /app.manifest.rc"
105+ "${PROJECT_BINARY_DIR} /version.rc"
106+ )
107+ endif ()
101108
102109add_executable (cppwinrt ${CPPWINRT_SRCS} ${CPPWINRT_RESOURCES} ${CPPWINRT_HEADERS} )
103110target_compile_definitions (cppwinrt PRIVATE CPPWINRT_VERSION_STRING= "${CPPWINRT_BUILD_VERSION} " )
104111target_include_directories (cppwinrt PRIVATE ${PROJECT_BINARY_DIR} )
105- target_link_libraries (cppwinrt shlwapi )
112+
113+ if (WIN32 )
114+ target_link_libraries (cppwinrt shlwapi )
115+ endif ()
106116
107117install (TARGETS cppwinrt)
108118
@@ -158,26 +168,28 @@ int main() {}
158168 add_dependencies (cppwinrt gen-libxmllite )
159169 endif ()
160170endif ()
161- target_link_libraries (cppwinrt "${XMLLITE_LIBRARY} " )
171+ if (WIN32 )
172+ target_link_libraries (cppwinrt "${XMLLITE_LIBRARY} " )
173+ endif ()
162174
163175
164176# === winmd: External header-only library for reading winmd files ===
165177
166178include (ExternalProject )
167179ExternalProject_Add (winmd
168- URL https://github.com/microsoft/winmd/releases/download/1.0.210629.2/Microsoft.Windows.WinMD.1.0.210629.2.nupkg
169- URL_HASH SHA256=4c5f29d948f5b3d724d229664c8f8e4823250d3c9f23ad8067b732fc7076d8c7
180+ GIT_REPOSITORY https://github.com/microsoft/winmd.git
181+ GIT_TAG 0f1eae3bfa63fa2ba3c2912cbfe72a01db94cc5a
170182 CONFIGURE_COMMAND ""
171183 BUILD_COMMAND ""
172184 INSTALL_COMMAND ""
173185)
174186add_dependencies (cppwinrt winmd )
175187ExternalProject_Get_Property (winmd SOURCE_DIR )
176188set (winmd_SOURCE_DIR "${SOURCE_DIR} " )
177- target_include_directories (cppwinrt PRIVATE "${winmd_SOURCE_DIR} " )
189+ target_include_directories (cppwinrt PRIVATE "${winmd_SOURCE_DIR} /src " )
178190
179191
180- if (NOT CMAKE_CROSSCOMPILING )
192+ if (WIN32 AND NOT CMAKE_CROSSCOMPILING )
181193 include (CTest )
182194 if (BUILD_TESTING)
183195 add_subdirectory (test )
0 commit comments