Initial Commit
This commit is contained in:
		
							parent
							
								
									01bba10af9
								
							
						
					
					
						commit
						ba0857832c
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| build/ | ||||
							
								
								
									
										24
									
								
								CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| cmake_minimum_required(VERSION 3.11) | ||||
| FIND_PACKAGE(SWIG 3.0.11 REQUIRED) | ||||
| INCLUDE(${SWIG_USE_FILE}) | ||||
| 
 | ||||
| if(WIN32) | ||||
| add_definitions(/D_WIN32 /D_WINDOWS /DWINDOWS=1 /DZEND_WIN32=1 /DPHP_WIN32=1 /DWIN32 /DNDebug /DNDEBUG /DZEND_DEBUG=0 /DZTS=1) | ||||
| if(NOT CMAKE_CL_64) | ||||
| add_definitions(-D_USE_32BIT_TIME_T) | ||||
| endif(NOT CMAKE_CL_64) | ||||
| ENDIF(WIN32) | ||||
| 
 | ||||
| include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src) | ||||
| include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/main) | ||||
| include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/Zend) | ||||
| include_directories (C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/TSRM) | ||||
| include_directories (${CMAKE_CURRENT_SOURCE_DIR}) | ||||
| 
 | ||||
| add_library(example STATIC example.c) | ||||
| swig_add_library(php_example TYPE MODULE LANGUAGE php7 SOURCES example.i) | ||||
| target_compile_options(php_example PRIVATE /D_WIN32 /D_WINDOWS /DWINDOWS=1 /DZEND_WIN32=1 /DPHP_WIN32=1 /DWIN32 /DNDebug /DNDEBUG /DZEND_DEBUG=0 /DZTS=1) | ||||
| 
 | ||||
| string(SUBSTRING $ENV{VSCMD_VER} 0 2 VSCMD_VER) | ||||
| target_link_libraries(php_example "C:/php-sdk/phpmaster/vc${VSCMD_VER}/$ENV{VSCMD_ARG_TGT_ARCH}/php-src/x64/Release_TS/php7ts.lib") | ||||
| target_link_libraries(php_example example) | ||||
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							| @ -1,2 +1,20 @@ | ||||
| # SWIGCmakePHPExampleWindows | ||||
| Example on how to build a SWIG Extension for PHP with CMake on Windows | ||||
| Example on how to build a SWIG Extension for PHP with CMake on Windows. | ||||
| Couldn't find any working example for Windows so i created this one ;) | ||||
| Hope it helps you. | ||||
| 
 | ||||
| To build this Example, build PHP as descriped here: https://github.com/Microsoft/php-sdk-binary-tools | ||||
| You need SWIG to make this work. | ||||
| Current SWIG (3.0.12) has a Problem with building Extensions on Windows with Thread-Safe PHP. | ||||
| So until SWIG 4.0.0 is released, you need to build SWIG, too. | ||||
| I have a fork of swig in my github account which enables you to build it with cmake: https://github.com/AlexanderGabriel/swig | ||||
| Build it and change the path SWIG_EXECUTABLE and SWIG_DIR to your environment. | ||||
| 
 | ||||
| You can stay inside PHP-SDK-Shell if you want, change directory back to where you checked out this and then execute the following commands. | ||||
| 
 | ||||
| mkdir build | ||||
| cd build | ||||
| cmake ..  -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DSWIG_EXECUTABLE=C:\dev\work\swig\swig.exe -DSWIG_DIR=C:\dev\work\swig | ||||
| cmake --build . | ||||
| 
 | ||||
| Thats it. | ||||
|  | ||||
							
								
								
									
										14
									
								
								example.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								example.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| /* File : example.c */ | ||||
| 
 | ||||
| double  My_variable  = 3.0; | ||||
| 
 | ||||
| /* Compute factorial of n */ | ||||
| int  fact(int n) { | ||||
|     if (n <= 1) return 1; | ||||
|     else return n*fact(n-1); | ||||
| } | ||||
| 
 | ||||
| /* Compute n mod m */ | ||||
| int my_mod(int n, int m) { | ||||
|     return(n % m); | ||||
| } | ||||
							
								
								
									
										12
									
								
								example.i
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								example.i
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| /* File : example.i */ | ||||
| %module example | ||||
| %{ | ||||
| /* Put headers and other declarations here */ | ||||
| extern double My_variable; | ||||
| extern int    fact(int); | ||||
| extern int    my_mod(int n, int m); | ||||
| %} | ||||
| 
 | ||||
| extern double My_variable; | ||||
| extern int    fact(int); | ||||
| extern int    my_mod(int n, int m); | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user