Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 1 | file(GLOB snippets_SRCS "*.cpp") |
| 2 | |
| 3 | add_custom_target(all_snippets) |
| 4 | |
| 5 | foreach(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) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 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") |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 35 | endif() |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 36 | endforeach() |