
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/Languages")
enable_language(ICPC OPTIONAL)
enable_language(IFORT OPTIONAL)

find_package(Common)

set(ICPC_FOUND True)
if (${CMAKE_ICPC_COMPILER} STREQUAL "CMAKE_ICPC_COMPILER-NOTFOUND")
  set(ICPC_FOUND False)
else()
  function(icpc_sources)
    get_sources_and_options(sources compile_flags "COMPILE_FLAGS" ${ARGN})
    set_source_files_properties(${sources} PROPERTIES LANGUAGE ICPC)
    foreach (file ${sources})
      set_property(SOURCE ${file} APPEND_STRING PROPERTY COMPILE_FLAGS " -I${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_CXX_FLAGS} ${compile_flags} ")
    endforeach()
  endfunction()
  function(icpc_add_executable icpc_target)
    get_sources_and_options(sources link_flags "LINK_FLAGS" ${ARGN})
    add_executable(${icpc_target} ${sources})
    set_target_properties(${icpc_target} PROPERTIES LINKER_LANGUAGE ICPC)
    set_property(TARGET ${icpc_target} APPEND_STRING PROPERTY LINK_FLAGS " ${link_flags} ")
  endfunction()
endif()

set(IFORT_FOUND True)
if (${CMAKE_IFORT_COMPILER} STREQUAL "CMAKE_IFORT_COMPILER-NOTFOUND")
  set(IFORT_FOUND False)
else()
  #function(ifort_sources)
  #set_source_files_properties(${ARGN} PROPERTIES LANGUAGE IFORT)
    #endfunction()
  #function(ifort_add_executable ifort_target)
  #add_executable(${ifort_target} ${ARGN})
    #set_target_properties(${ifort_target} PROPERTIES LINKER_LANGUAGE IFORT)
    #  endfunction()

  function(ifort_sources)
    get_sources_and_options(sources compile_flags "COMPILE_FLAGS" ${ARGN})
    set_source_files_properties(${sources} PROPERTIES LANGUAGE IFORT)
    foreach (file ${sources})
      set_property(SOURCE ${file} APPEND_STRING PROPERTY COMPILE_FLAGS " ${compile_flags} ")
    endforeach()
  endfunction()
  function(ifort_add_executable ifort_target)
    get_sources_and_options(sources link_flags "LINK_FLAGS" ${ARGN})
    add_executable(${ifort_target} ${sources})
    set_target_properties(${ifort_target} PROPERTIES LINKER_LANGUAGE IFORT)
    set_property(TARGET ${ifort_target} APPEND_STRING PROPERTY LINK_FLAGS " ${link_flags} ")
  endfunction()
endif()


