CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

FILE(GLOB FILES "*.cpp")

MACRO(CREATE_EXAMPLES BACKEND)
    STRING(TOUPPER ${BACKEND} DEF_NAME)
    FOREACH(FILE ${FILES})
        GET_FILENAME_COMPONENT(FNAME ${FILE} NAME_WE)
        SET(EXAMPLE_NAME ${FNAME}_${BACKEND})

        #ADD_EXAMPLE(Test_${EXAMPLE_NAME} ${EXAMPLE_NAME})
        ADD_EXECUTABLE(${EXAMPLE_NAME} ${FNAME}.cpp)
        TARGET_LINK_LIBRARIES(${EXAMPLE_NAME} af${BACKEND} ${THREAD_LIB_FLAG})
        SET_TARGET_PROPERTIES(${EXAMPLE_NAME} PROPERTIES COMPILE_FLAGS -DAF_${DEF_NAME})
        
#        INSTALL(TARGETS ${EXAMPLE_NAME} DESTINATION arrayfire/examples)
     ENDFOREACH()
ENDMACRO(CREATE_EXAMPLES)


IF(${BUILD_CPU})
  CREATE_EXAMPLES(cpu)
ENDIF()

IF(${BUILD_CUDA})
  CREATE_EXAMPLES(cuda)
ENDIF()

IF(${BUILD_OPENCL})
  CREATE_EXAMPLES(opencl)
ENDIF()

INCLUDE_DIRECTORIES(
    "${CMAKE_CURRENT_SOURCE_DIR}"
)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

FILE(GLOB FILES "*.cpp")

MACRO(CREATE_EXAMPLES BACKEND)
    STRING(TOUPPER ${BACKEND} DEF_NAME)
    FOREACH(FILE ${FILES})
        GET_FILENAME_COMPONENT(FNAME ${FILE} NAME_WE)
        SET(EXAMPLE_NAME example_${FNAME}_${BACKEND})

        #ADD_EXAMPLE(Test_${EXAMPLE_NAME} ${EXAMPLE_NAME})
        ADD_EXECUTABLE(${EXAMPLE_NAME} ${FNAME}.cpp)
        TARGET_LINK_LIBRARIES(${EXAMPLE_NAME} af${BACKEND} ${THREAD_LIB_FLAG})
        SET_TARGET_PROPERTIES(${EXAMPLE_NAME} PROPERTIES COMPILE_FLAGS -DAF_${DEF_NAME} OUTPUT_NAME ${FNAME}_${BACKEND})

#        INSTALL(TARGETS ${EXAMPLE_NAME} DESTINATION arrayfire/examples)
     ENDFOREACH()
ENDMACRO(CREATE_EXAMPLES)


IF(${BUILD_CPU})
  CREATE_EXAMPLES(cpu)
ENDIF()

IF(${BUILD_CUDA})
  CREATE_EXAMPLES(cuda)
ENDIF()

IF(${BUILD_OPENCL})
  CREATE_EXAMPLES(opencl)
ENDIF()

INCLUDE_DIRECTORIES(
    "${CMAKE_CURRENT_SOURCE_DIR}"
)

Fix cmake error caused by same filename in test and example
Fix cmake error caused by same filename in test and example
