CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. find_package(Qt4)
  2. set(SAFE_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
  3. set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  4. set(CMAKE_REQUIRED_INCLUDES "${QT_INCLUDES}")
  5. set(CMAKE_REQUIRED_LIBRARIES "${QT_QTCORE_LIBRARY}")
  6. CHECK_CXX_SOURCE_COMPILES("#include <QObject>
  7. int main() { QObject o; return 0;}" QT4_USABLE)
  8. mark_as_advanced(QT4_USABLE)
  9. set(CMAKE_REQUIRED_INCLUDES "${SAFE_CMAKE_REQUIRED_INCLUDES}")
  10. set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")
  11. add_custom_target(Examples COMMENT "build all examples" VERBATIM)
  12. AddCompilerFlag(-ftemplate-depth=1024 CXX_FLAGS CMAKE_CXX_FLAGS MIC_CXX_FLAGS CMAKE_MIC_CXX_FLAGS)
  13. macro(vc_add_run_target _target)
  14. if("${_target}" MATCHES "_mic$")
  15. if(MIC_NATIVELOAD)
  16. get_target_property(_exe "${_target}" OUTPUT_NAME)
  17. add_custom_target(run_${_target}
  18. ${MIC_NATIVELOAD} "${_exe}"
  19. DEPENDS ${_target}
  20. COMMENT "Execute ${_target} example"
  21. VERBATIM
  22. )
  23. endif()
  24. else()
  25. add_custom_target(run_${_target}
  26. ${_target}
  27. DEPENDS ${_target}
  28. COMMENT "Execute ${_target} example"
  29. VERBATIM
  30. )
  31. endif()
  32. endmacro()
  33. macro(_build_one_example_target _name _impl)
  34. set(_target "example_${_name}_${_impl}")
  35. string(TOLOWER "${_target}" _target)
  36. list(FIND _disabled_impl "${_impl}" _index1)
  37. list(FIND disabled_targets "${_target}" _index2)
  38. if(_index1 EQUAL -1 AND USE_${_impl} AND _index2 EQUAL -1)
  39. add_executable(${_target} ${ARGN})
  40. add_target_property(${_target} COMPILE_DEFINITIONS "Vc_IMPL=${_impl}")
  41. set_property(TARGET ${_target} APPEND PROPERTY COMPILE_OPTIONS ${Vc_ARCHITECTURE_FLAGS})
  42. add_target_property(${_target} LABELS "${_impl}")
  43. add_dependencies(${_impl} ${_target})
  44. add_dependencies(Examples ${_target})
  45. target_link_libraries(${_target} Vc ${_LIBS})
  46. vc_add_run_target(${_target})
  47. endif()
  48. endmacro()
  49. function(build_example name)
  50. set(_SRCS)
  51. set(_LIBS)
  52. set(_disabled_impl)
  53. set(_state 1)
  54. set(USE_Scalar TRUE)
  55. set(USE_SSE ${USE_SSE2})
  56. foreach(ARG ${ARGN})
  57. if(ARG STREQUAL "LIBS")
  58. set(_state 2)
  59. elseif(ARG STREQUAL "DISABLE")
  60. set(_state 3)
  61. elseif(_state EQUAL 1)
  62. set(_SRCS ${_SRCS} ${ARG})
  63. elseif(_state EQUAL 2)
  64. set(_LIBS ${_LIBS} ${ARG})
  65. elseif(_state EQUAL 3)
  66. list(APPEND _disabled_impl ${ARG})
  67. endif()
  68. endforeach()
  69. _build_one_example_target("${name}" Scalar ${_SRCS})
  70. _build_one_example_target("${name}" SSE ${_SRCS})
  71. _build_one_example_target("${name}" AVX ${_SRCS})
  72. _build_one_example_target("${name}" AVX2 ${_SRCS})
  73. set(_target "example_${name}_mic")
  74. list(FIND _disabled_impl "MIC" _index1)
  75. list(FIND disabled_targets "${_target}" _index2)
  76. if(MIC_NATIVE_FOUND AND "${_LIBS}" STREQUAL "" AND _index1 EQUAL -1 AND _index2 EQUAL -1)
  77. mic_add_executable(${_target}
  78. SOURCES ${_SRCS}
  79. LINK_LIBRARIES Vc_MIC
  80. )
  81. add_target_property(${_target} LABELS "MIC")
  82. add_dependencies(MIC ${_target})
  83. vc_add_run_target(${_target})
  84. endif()
  85. endfunction(build_example)
  86. file(GLOB examples RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt")
  87. foreach(example ${examples})
  88. string(REPLACE "/CMakeLists.txt" "" example "${example}")
  89. list(FIND disabled_targets "example_${example}" _disabled)
  90. if(_disabled EQUAL -1)
  91. add_subdirectory(${example})
  92. endif()
  93. endforeach()