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