xref: /aosp_15_r20/external/eigen/doc/snippets/CMakeLists.txt (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1file(GLOB snippets_SRCS "*.cpp")
2
3add_custom_target(all_snippets)
4
5foreach(snippet_src ${snippets_SRCS})
6  get_filename_component(snippet ${snippet_src} NAME_WE)
7  set(compile_snippet_target compile_${snippet})
8  set(compile_snippet_src ${compile_snippet_target}.cpp)
9  if((NOT ${snippet_src} MATCHES "cxx11") OR EIGEN_COMPILER_SUPPORT_CPP11)
10    file(READ ${snippet_src} snippet_source_code)
11    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in
12                  ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
13    add_executable(${compile_snippet_target}
14                  ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
15    if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
16      target_link_libraries(${compile_snippet_target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
17    endif()
18    if(${snippet_src} MATCHES "cxx11")
19      set_target_properties(${compile_snippet_target} PROPERTIES COMPILE_FLAGS "-std=c++11")
20    endif()
21    if(${snippet_src} MATCHES "deprecated")
22      set_target_properties(${compile_snippet_target} PROPERTIES COMPILE_FLAGS "-DEIGEN_NO_DEPRECATED_WARNING")
23    endif()
24    add_custom_command(
25      TARGET ${compile_snippet_target}
26      POST_BUILD
27      COMMAND ${compile_snippet_target}
28      ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out
29    )
30    add_dependencies(all_snippets ${compile_snippet_target})
31    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}
32                                PROPERTIES OBJECT_DEPENDS ${snippet_src})
33  else()
34    message("skip snippet ${snippet_src} because compiler does not support C++11")
35  endif()
36endforeach()
37