Skip to content

Commit c654a05

Browse files
committed
Improve ext/com_dotnet extension configuration
The <mscoree.h> is part of the .NET Framework (.NET Framework versions 4 and earlier). The current .NET implementations (version 5 don't have this header and API anymore). This at least errors out to make the user aware of this and what needs to be installed.
1 parent 357c8d3 commit c654a05

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

cmake/cmake/platforms/Windows.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
109109
set(HAVE_MMAP FALSE)
110110
set(HAVE_MPROTECT FALSE)
111111
set(HAVE_MREMAP FALSE)
112-
set(HAVE_MSCOREE_H TRUE)
113112
set(HAVE_NET_IF_H FALSE)
114113
set(HAVE_NETDB_H FALSE)
115114
set(HAVE_NETINET_IN_H FALSE)

cmake/ext/com_dotnet/CMakeLists.txt

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,46 @@ This extension provides the Component Object Model (COM) and .NET support.
88
> [!NOTE]
99
> This extension is available only when the target system is Windows.
1010
11-
## PHP_EXT_COM_DOTNET
11+
## Requirements
12+
13+
To build this extension, Windows SDK needs to be installed, which includes
14+
the COM support.
15+
16+
To enable also the .NET support in this extension (e.g., the `dotnet` PHP
17+
class), the .NET framework needs to be installed, which provides the
18+
`<mscoree.h>` header. This can be done in several ways:
19+
20+
* in Visual Studio by installing the .NET desktop development workload
21+
* in Visual Studio by installing the .NET framework 4.x component only
22+
* Download and install
23+
[.NET framework](https://dotnet.microsoft.com/en-us/download/dotnet-framework)
24+
manually.
25+
26+
The .NET version 5 and later are not supported as they have removed the
27+
`<mscoree.h>` API.
28+
29+
## Configuration options
30+
31+
### PHP_EXT_COM_DOTNET
1232
1333
* Default: `ON`
1434
* Values: `ON|OFF`
1535
16-
Enable the extension.
36+
Enables the extension.
1737
18-
## PHP_EXT_COM_DOTNET_SHARED
38+
### PHP_EXT_COM_DOTNET_SHARED
1939
2040
* Default: `OFF`
2141
* Values: `ON|OFF`
2242
23-
Build extension as shared.
43+
Builds extension as shared.
44+
45+
### PHP_EXT_COM_DOTNET_ENABLE_DOTNET
46+
47+
* Default: `ON`
48+
* Values: `ON|OFF`
49+
50+
Enables the .NET Framework support.
2451
#]=============================================================================]
2552

2653
cmake_minimum_required(VERSION 3.29...4.0)
@@ -54,6 +81,14 @@ cmake_dependent_option(
5481
OFF
5582
)
5683

84+
cmake_dependent_option(
85+
PHP_EXT_COM_DOTNET_ENABLE_DOTNET
86+
"Enable .NET support"
87+
ON
88+
PHP_EXT_COM_DOTNET
89+
OFF
90+
)
91+
5792
if(NOT PHP_EXT_COM_DOTNET)
5893
return()
5994
endif()
@@ -91,7 +126,20 @@ target_compile_definitions(
91126

92127
target_link_libraries(php_ext_com_dotnet PRIVATE oleaut32)
93128

94-
check_include_files(mscoree.h HAVE_MSCOREE_H)
129+
if(PHP_EXT_COM_DOTNET_ENABLE_DOTNET)
130+
check_include_files(mscoree.h PHP_EXT_COM_DOTNET_HAS_MSCOREE_H)
131+
132+
if(NOT PHP_EXT_COM_DOTNET_HAS_MSCOREE_H)
133+
message(
134+
FATAL_ERROR
135+
"<mscoree.h> not found. Please install the .NET Framework or disable the "
136+
".NET support with by setting 'PHP_EXT_COM_DOTNET_ENABLE_DOTNET' to "
137+
"'OFF'."
138+
)
139+
endif()
140+
141+
set(HAVE_MSCOREE_H TRUE)
142+
endif()
95143

96144
set(HAVE_COM_DOTNET TRUE)
97145

0 commit comments

Comments
 (0)