CMakeLists.txt 1.6 KB

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