112391Sjason@lowepower.comadd_custom_target(test_cmake_build) 212391Sjason@lowepower.com 312391Sjason@lowepower.comif(CMAKE_VERSION VERSION_LESS 3.1) 412391Sjason@lowepower.com # 3.0 needed for interface library for subdirectory_target/installed_target 512391Sjason@lowepower.com # 3.1 needed for cmake -E env for testing 612391Sjason@lowepower.com return() 712391Sjason@lowepower.comendif() 812391Sjason@lowepower.com 912391Sjason@lowepower.cominclude(CMakeParseArguments) 1012391Sjason@lowepower.comfunction(pybind11_add_build_test name) 1112391Sjason@lowepower.com cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN}) 1212391Sjason@lowepower.com 1312391Sjason@lowepower.com set(build_options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/mock_install" 1412391Sjason@lowepower.com "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 1512391Sjason@lowepower.com "-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}" 1612391Sjason@lowepower.com "-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}") 1712391Sjason@lowepower.com if(NOT ARG_INSTALL) 1812391Sjason@lowepower.com list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${PROJECT_SOURCE_DIR}") 1912391Sjason@lowepower.com endif() 2012391Sjason@lowepower.com 2112391Sjason@lowepower.com add_custom_target(test_${name} ${CMAKE_CTEST_COMMAND} 2212391Sjason@lowepower.com --quiet --output-log ${name}.log 2312391Sjason@lowepower.com --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}/${name}" 2412391Sjason@lowepower.com "${CMAKE_CURRENT_BINARY_DIR}/${name}" 2512391Sjason@lowepower.com --build-config Release 2612391Sjason@lowepower.com --build-noclean 2712391Sjason@lowepower.com --build-generator ${CMAKE_GENERATOR} 2812391Sjason@lowepower.com $<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform> ${CMAKE_GENERATOR_PLATFORM} 2912391Sjason@lowepower.com --build-makeprogram ${CMAKE_MAKE_PROGRAM} 3012391Sjason@lowepower.com --build-target check 3112391Sjason@lowepower.com --build-options ${build_options} 3212391Sjason@lowepower.com ) 3312391Sjason@lowepower.com if(ARG_INSTALL) 3412391Sjason@lowepower.com add_dependencies(test_${name} mock_install) 3512391Sjason@lowepower.com endif() 3612391Sjason@lowepower.com add_dependencies(test_cmake_build test_${name}) 3712391Sjason@lowepower.comendfunction() 3812391Sjason@lowepower.com 3912391Sjason@lowepower.compybind11_add_build_test(subdirectory_function) 4012391Sjason@lowepower.compybind11_add_build_test(subdirectory_target) 4112391Sjason@lowepower.comif(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy") 4212391Sjason@lowepower.com pybind11_add_build_test(subdirectory_embed) 4312391Sjason@lowepower.comendif() 4412391Sjason@lowepower.com 4512391Sjason@lowepower.comif(PYBIND11_INSTALL) 4612391Sjason@lowepower.com add_custom_target(mock_install ${CMAKE_COMMAND} 4712391Sjason@lowepower.com "-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/mock_install" 4812391Sjason@lowepower.com -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" 4912391Sjason@lowepower.com ) 5012391Sjason@lowepower.com 5112391Sjason@lowepower.com pybind11_add_build_test(installed_function INSTALL) 5212391Sjason@lowepower.com pybind11_add_build_test(installed_target INSTALL) 5312391Sjason@lowepower.com if(NOT ${PYTHON_MODULE_EXTENSION} MATCHES "pypy") 5412391Sjason@lowepower.com pybind11_add_build_test(installed_embed INSTALL) 5512391Sjason@lowepower.com endif() 5612391Sjason@lowepower.comendif() 5712391Sjason@lowepower.com 5812391Sjason@lowepower.comadd_dependencies(check test_cmake_build) 59