| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  | # Built-in in CMake 3.5+
 | 
					
						
							|  |  |  | include(CMakeParseArguments)
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  | add_custom_target(test_cmake_build)
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function(pybind11_add_build_test name)
 | 
					
						
							|  |  |  |   cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |   set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if(PYBIND11_FINDPYTHON)
 | 
					
						
							|  |  |  |     list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(DEFINED Python_ROOT_DIR)
 | 
					
						
							|  |  |  |       list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}")
 | 
					
						
							|  |  |  |     endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     list(APPEND build_options "-DPython_EXECUTABLE=${Python_EXECUTABLE}")
 | 
					
						
							|  |  |  |   else()
 | 
					
						
							|  |  |  |     list(APPEND build_options "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if(DEFINED CMAKE_CXX_STANDARD)
 | 
					
						
							|  |  |  |     list(APPEND build_options "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |   if(NOT ARG_INSTALL)
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |     list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${pybind11_SOURCE_DIR}")
 | 
					
						
							|  |  |  |   else()
 | 
					
						
							|  |  |  |     list(APPEND build_options "-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install")
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |   endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |   add_custom_target( | 
					
						
							|  |  |  |     test_build_${name}
 | 
					
						
							|  |  |  |     ${CMAKE_CTEST_COMMAND}
 | 
					
						
							|  |  |  |     --build-and-test
 | 
					
						
							|  |  |  |     "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
 | 
					
						
							|  |  |  |     "${CMAKE_CURRENT_BINARY_DIR}/${name}"
 | 
					
						
							|  |  |  |     --build-config
 | 
					
						
							|  |  |  |     Release
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |     --build-noclean
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |     --build-generator
 | 
					
						
							|  |  |  |     ${CMAKE_GENERATOR}
 | 
					
						
							|  |  |  |     $<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform>
 | 
					
						
							|  |  |  |     ${CMAKE_GENERATOR_PLATFORM}
 | 
					
						
							|  |  |  |     --build-makeprogram
 | 
					
						
							|  |  |  |     ${CMAKE_MAKE_PROGRAM}
 | 
					
						
							|  |  |  |     --build-target
 | 
					
						
							|  |  |  |     check_${name}
 | 
					
						
							|  |  |  |     --build-options
 | 
					
						
							|  |  |  |     ${build_options})
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |   if(ARG_INSTALL)
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |     add_dependencies(test_build_${name} mock_install)
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |   endif()
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |   add_dependencies(test_cmake_build test_build_${name})
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  | endfunction()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pybind11_add_build_test(subdirectory_function)
 | 
					
						
							|  |  |  | pybind11_add_build_test(subdirectory_target)
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  | if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
 | 
					
						
							|  |  |  |   message(STATUS "Skipping embed test on PyPy")
 | 
					
						
							|  |  |  | else()
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |   pybind11_add_build_test(subdirectory_embed)
 | 
					
						
							|  |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(PYBIND11_INSTALL)
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |   add_custom_target( | 
					
						
							|  |  |  |     mock_install ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=${pybind11_BINARY_DIR}/mock_install" -P
 | 
					
						
							|  |  |  |                  "${pybind11_BINARY_DIR}/cmake_install.cmake")
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   pybind11_add_build_test(installed_function INSTALL)
 | 
					
						
							|  |  |  |   pybind11_add_build_test(installed_target INSTALL)
 | 
					
						
							| 
									
										
										
										
											2020-09-17 06:03:25 +08:00
										 |  |  |   if(NOT ("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy" | 
					
						
							|  |  |  |          ))
 | 
					
						
							| 
									
										
										
										
											2020-08-18 02:44:43 +08:00
										 |  |  |     pybind11_add_build_test(installed_embed INSTALL)
 | 
					
						
							|  |  |  |   endif()
 | 
					
						
							|  |  |  | endif()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | add_dependencies(check test_cmake_build)
 |