Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 1 | # Set a default build configuration if none is specified. 'MinSizeRel' produces the smallest binaries |
| 2 | if(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") |
| 7 | endif() |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 8 | |
| 9 | set(PYBIND11_EXAMPLES |
Jason Rhinelander | b3f3d79 | 2016-07-18 16:43:18 -0400 | [diff] [blame] | 10 | 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 Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 29 | issues.cpp |
| 30 | ) |
| 31 | |
| 32 | # Check if Eigen is available |
| 33 | find_package(Eigen3 QUIET) |
| 34 | |
| 35 | if(EIGEN3_FOUND) |
| 36 | list(APPEND PYBIND11_EXAMPLES eigen.cpp) |
Dean Moldovan | 3ac1275 | 2016-07-30 00:15:01 +0200 | [diff] [blame] | 37 | message(STATUS "Building Eigen v${EIGEN3_VERSION} testcase") |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 38 | else() |
| 39 | message(STATUS "NOT Building Eigen testcase") |
| 40 | endif() |
| 41 | |
| 42 | # Create the binding library |
| 43 | pybind11_add_module(example example.cpp ${PYBIND11_EXAMPLES}) |
Wenzel Jakob | 67a6392 | 2016-05-29 12:35:16 +0200 | [diff] [blame] | 44 | pybind11_enable_warnings(example) |
Dean Moldovan | 9fb50c5 | 2016-05-27 21:42:43 +0200 | [diff] [blame] | 45 | |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 46 | if(EIGEN3_FOUND) |
| 47 | target_include_directories(example PRIVATE ${EIGEN3_INCLUDE_DIR}) |
| 48 | target_compile_definitions(example PRIVATE -DPYBIND11_TEST_EIGEN) |
| 49 | endif() |
| 50 | |
| 51 | # Always write the output file directly into the 'example' directory (even on MSVC) |
| 52 | set(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 | |
| 58 | foreach(CompilerFlag ${CompilerFlags}) |
| 59 | set_target_properties(example PROPERTIES ${CompilerFlag} ${PROJECT_SOURCE_DIR}/example) |
| 60 | endforeach() |
| 61 | |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 62 | set(RUN_TEST ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_test.py) |
| 63 | if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") |
| 64 | set(RUN_TEST ${RUN_TEST} --relaxed) |
| 65 | endif() |
| 66 | |
| 67 | foreach(VALUE ${PYBIND11_EXAMPLES}) |
| 68 | string(REGEX REPLACE "^(.+).cpp$" "\\1" EXAMPLE_NAME "${VALUE}") |
| 69 | add_test(NAME ${EXAMPLE_NAME} COMMAND ${RUN_TEST} ${EXAMPLE_NAME}) |
| 70 | endforeach() |
Klemens Morgenstern | c6ad2c4 | 2016-06-09 16:10:26 +0200 | [diff] [blame] | 71 | |