blob: 93e4d452530d397b67f428e53869a98c17a83283 [file] [log] [blame]
Dean Moldovan8c6b0b82016-05-23 00:12:37 +02001# Set a default build configuration if none is specified. 'MinSizeRel' produces the smallest binaries
2if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3 message(STATUS "Setting build type to 'MinSizeRel' as none was specified.")
4 set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Choose the type of build." FORCE)
5 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
6 "MinSizeRel" "RelWithDebInfo")
7endif()
Dean Moldovan8c6b0b82016-05-23 00:12:37 +02008
9set(PYBIND11_EXAMPLES
Jason Rhinelanderb3f3d792016-07-18 16:43:18 -040010 example-methods-and-attributes.cpp
11 example-python-types.cpp
12 example-operator-overloading.cpp
13 example-constants-and-functions.cpp
14 example-callbacks.cpp
15 example-sequences-and-iterators.cpp
16 example-buffers.cpp
17 example-smart-ptr.cpp
18 example-modules.cpp
19 example-numpy-vectorize.cpp
20 example-arg-keywords-and-defaults.cpp
21 example-virtual-functions.cpp
22 example-keep-alive.cpp
23 example-opaque-types.cpp
24 example-pickling.cpp
25 example-inheritance.cpp
26 example-stl-binder-vector.cpp
27 example-eval.cpp
28 example-custom-exceptions.cpp
Dean Moldovan8c6b0b82016-05-23 00:12:37 +020029 issues.cpp
30)
31
32# Check if Eigen is available
33find_package(Eigen3 QUIET)
34
35if(EIGEN3_FOUND)
36 list(APPEND PYBIND11_EXAMPLES eigen.cpp)
Dean Moldovan3ac12752016-07-30 00:15:01 +020037 message(STATUS "Building Eigen v${EIGEN3_VERSION} testcase")
Dean Moldovan8c6b0b82016-05-23 00:12:37 +020038else()
39 message(STATUS "NOT Building Eigen testcase")
40endif()
41
42# Create the binding library
43pybind11_add_module(example example.cpp ${PYBIND11_EXAMPLES})
Wenzel Jakob67a63922016-05-29 12:35:16 +020044pybind11_enable_warnings(example)
Dean Moldovan9fb50c52016-05-27 21:42:43 +020045
Dean Moldovan8c6b0b82016-05-23 00:12:37 +020046if(EIGEN3_FOUND)
47 target_include_directories(example PRIVATE ${EIGEN3_INCLUDE_DIR})
48 target_compile_definitions(example PRIVATE -DPYBIND11_TEST_EIGEN)
49endif()
50
51# Always write the output file directly into the 'example' directory (even on MSVC)
52set(CompilerFlags
53 LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_DIRECTORY_DEBUG
54 LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO
55 RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_DIRECTORY_DEBUG
56 RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO)
57
58foreach(CompilerFlag ${CompilerFlags})
59 set_target_properties(example PROPERTIES ${CompilerFlag} ${PROJECT_SOURCE_DIR}/example)
60endforeach()
61
Dean Moldovan8c6b0b82016-05-23 00:12:37 +020062set(RUN_TEST ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_test.py)
63if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
64 set(RUN_TEST ${RUN_TEST} --relaxed)
65endif()
66
67foreach(VALUE ${PYBIND11_EXAMPLES})
68 string(REGEX REPLACE "^(.+).cpp$" "\\1" EXAMPLE_NAME "${VALUE}")
69 add_test(NAME ${EXAMPLE_NAME} COMMAND ${RUN_TEST} ${EXAMPLE_NAME})
70endforeach()
Klemens Morgensternc6ad2c42016-06-09 16:10:26 +020071