2016-05-22 22:12:37 +00:00
|
|
|
# Set a default build configuration if none is specified. 'MinSizeRel' produces the smallest binaries
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
message(STATUS "Setting build type to 'MinSizeRel' as none was specified.")
|
|
|
|
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Choose the type of build." FORCE)
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
|
|
|
"MinSizeRel" "RelWithDebInfo")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(PYBIND11_EXAMPLES
|
Rename examples files, as per #288
This renames example files from `exampleN` to `example-description`.
Specifically, the following renaming is applied:
example1 -> example-methods-and-attributes
example2 -> example-python-types
example3 -> example-operator-overloading
example4 -> example-constants-and-functions
example5 -> example-callbacks (*)
example6 -> example-sequence-and-iterators
example7 -> example-buffers
example8 -> example-custom-ref-counting
example9 -> example-modules
example10 -> example-numpy-vectorize
example11 -> example-arg-keywords-and-defaults
example12 -> example-virtual-functions
example13 -> example-keep-alive
example14 -> example-opaque-types
example15 -> example-pickling
example16 -> example-inheritance
example17 -> example-stl-binders
example18 -> example-eval
example19 -> example-custom-exceptions
* the inheritance parts of example5 are moved into example-inheritance
(previously example16), and the remainder is left as example-callbacks.
This commit also renames the internal variables ("Example1",
"Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
"ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
file renaming.
The order of tests is preserved, but this can easily be changed if
there is some more natural ordering by updating the list in
examples/CMakeLists.txt.
2016-07-18 20:43:18 +00:00
|
|
|
example-methods-and-attributes.cpp
|
|
|
|
example-python-types.cpp
|
|
|
|
example-operator-overloading.cpp
|
|
|
|
example-constants-and-functions.cpp
|
|
|
|
example-callbacks.cpp
|
|
|
|
example-sequences-and-iterators.cpp
|
|
|
|
example-buffers.cpp
|
|
|
|
example-smart-ptr.cpp
|
|
|
|
example-modules.cpp
|
|
|
|
example-numpy-vectorize.cpp
|
|
|
|
example-arg-keywords-and-defaults.cpp
|
|
|
|
example-virtual-functions.cpp
|
|
|
|
example-keep-alive.cpp
|
|
|
|
example-opaque-types.cpp
|
|
|
|
example-pickling.cpp
|
|
|
|
example-inheritance.cpp
|
|
|
|
example-stl-binder-vector.cpp
|
|
|
|
example-eval.cpp
|
|
|
|
example-custom-exceptions.cpp
|
2016-05-22 22:12:37 +00:00
|
|
|
issues.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
# Check if Eigen is available
|
|
|
|
find_package(Eigen3 QUIET)
|
|
|
|
|
|
|
|
if(EIGEN3_FOUND)
|
|
|
|
list(APPEND PYBIND11_EXAMPLES eigen.cpp)
|
2016-07-29 22:15:01 +00:00
|
|
|
message(STATUS "Building Eigen v${EIGEN3_VERSION} testcase")
|
2016-05-22 22:12:37 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "NOT Building Eigen testcase")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Create the binding library
|
|
|
|
pybind11_add_module(example example.cpp ${PYBIND11_EXAMPLES})
|
2016-05-29 10:35:16 +00:00
|
|
|
pybind11_enable_warnings(example)
|
2016-05-27 19:42:43 +00:00
|
|
|
|
2016-05-22 22:12:37 +00:00
|
|
|
if(EIGEN3_FOUND)
|
|
|
|
target_include_directories(example PRIVATE ${EIGEN3_INCLUDE_DIR})
|
|
|
|
target_compile_definitions(example PRIVATE -DPYBIND11_TEST_EIGEN)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Always write the output file directly into the 'example' directory (even on MSVC)
|
|
|
|
set(CompilerFlags
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_DIRECTORY_DEBUG
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_DIRECTORY_DEBUG
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO)
|
|
|
|
|
|
|
|
foreach(CompilerFlag ${CompilerFlags})
|
|
|
|
set_target_properties(example PROPERTIES ${CompilerFlag} ${PROJECT_SOURCE_DIR}/example)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(RUN_TEST ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_test.py)
|
|
|
|
|
|
|
|
foreach(VALUE ${PYBIND11_EXAMPLES})
|
|
|
|
string(REGEX REPLACE "^(.+).cpp$" "\\1" EXAMPLE_NAME "${VALUE}")
|
|
|
|
add_test(NAME ${EXAMPLE_NAME} COMMAND ${RUN_TEST} ${EXAMPLE_NAME})
|
|
|
|
endforeach()
|
2016-06-09 14:10:26 +00:00
|
|
|
|