# Include the embedded library headers
if (BUILD_QC_MYSQLEMBEDDED)
  find_package(MySQL)

  subdirs(MYSQL_INCLUDE_DIR_ALL ${MYSQL_EMBEDDED_INCLUDE_DIR})
  foreach(DIR ${MYSQL_INCLUDE_DIR_ALL})
    include_directories(${DIR})
  endforeach()
  include_directories(${MYSQL_EMBEDDED_INCLUDE_DIR}/..)

  if(${ERRMSG} MATCHES "ERRMSG-NOTFOUND")
    message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=<path>")
  else()
    if(${CMAKE_VERSION} VERSION_LESS 2.8)
	  execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${ERRMSG} ${CMAKE_CURRENT_BINARY_DIR})
    else()
	  file(COPY ${ERRMSG} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
    endif()
  endif()

  add_executable(classify classify.c)
  target_link_libraries(classify maxscale-common)

  add_executable(compare compare.cc testreader.cc)
  target_link_libraries(compare maxscale-common)

  add_executable(version_sensitivity version_sensitivity.cc)
  target_link_libraries(version_sensitivity maxscale-common)

  add_executable(crash_qc_sqlite crash_qc_sqlite.c)
  target_link_libraries(crash_qc_sqlite maxscale-common)

  add_test(TestQC_Crash_qcsqlite crash_qc_sqlite)

  # TestQC_MySQLEmbedded excluded, classify is now solely used for verifying the
  # functionality of qc_sqlite.
  #add_test(TestQC_MySQLEmbedded classify qc_mysqlembedded ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql)
  add_test(TestQC_SqLite classify qc_sqlite ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql)

  add_test(TestQC_CompareCreate compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/create.test)
  add_test(TestQC_CompareDelete compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/delete.test)
  add_test(TestQC_CompareInsert compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/insert.test)
  add_test(TestQC_CompareJoin compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/join.test)
  add_test(TestQC_CompareSelect compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/select.test)
  add_test(TestQC_CompareSet compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/set.test)
  add_test(TestQC_CompareUpdate compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/update.test)
  add_test(TestQC_CompareMaxScale compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/maxscale.test)
  add_test(TestQC_CompareWhiteSpace compare -v 2 -S -s "select user from mysql.user; ")

  add_test(TestQC_version_sensitivity version_sensitivity)

  if(NOT (MYSQL_EMBEDDED_VERSION VERSION_LESS 10.2))
    add_test(TestQC_cte_simple       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/cte_simple.test)
    add_test(TestQC_cte_grant        compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/cte_grant.test)
    add_test(TestQC_cte_nonrecursive compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/cte_nonrecursive.test)
    add_test(TestQC_cte_recursive    compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/cte_recursive.test)

    add_test(TestQC_win                  compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win.test)
    add_test(TestQC_win_avg              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_avg.test)
    add_test(TestQC_win_big-mdev-10092   compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_big-mdev-10092.test)
    add_test(TestQC_win_big-mdev-11697   compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_big-mdev-11697.test)
    add_test(TestQC_win_big              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_big.test)
    add_test(TestQC_win_bit              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_bit.test)
    add_test(TestQC_win_empty_over       compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_empty_over.test)
    add_test(TestQC_win_first_last_value compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_first_last_value.test)
    add_test(TestQC_win_i_s              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_i_s.test)
    add_test(TestQC_win_lead_lag         compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_lead_lag.test)
    add_test(TestQC_win_min_max          compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_min_max.test)
    add_test(TestQC_win_nth_value        compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_nth_value.test)
    add_test(TestQC_win_ntile            compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_ntile.test)
    add_test(TestQC_win_orderby          compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_orderby.test)
    add_test(TestQC_win_percent_cume     compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_percent_cume.test)
    add_test(TestQC_win_rank             compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_rank.test)
    add_test(TestQC_win_std              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_std.test)
    add_test(TestQC_win_sum              compare -v2 ${CMAKE_CURRENT_SOURCE_DIR}/win_sum.test)
  endif()

  if(NOT (MYSQL_EMBEDDED_VERSION VERSION_LESS 10.3))
    add_test(TestQC_Oracle-binlog_stm_ps     compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/binlog_stm_ps.test)
    add_test(TestQC_Oracle-binlog_stm_sp     compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/binlog_stm_sp.test)
    add_test(TestQC_Oracle-exception         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/exception.test)
    add_test(TestQC_Oracle-func_case         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/func_case.test)
    add_test(TestQC_Oracle-func_concat       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/func_concat.test)
    add_test(TestQC_Oracle-func_decode       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/func_decode.test)
    add_test(TestQC_Oracle-func_length       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/func_length.test)
    add_test(TestQC_Oracle-func_misc         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/func_misc.test)
    add_test(TestQC_Oracle-misc              compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/misc.test)
    add_test(TestQC_Oracle-ps                compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/ps.test)
    add_test(TestQC_Oracle-sequence          compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sequence.test)
    add_test(TestQC_Oracle-sp-anonymous      compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-anonymous.test)
    add_test(TestQC_Oracle-sp-code           compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-code.test)
    add_test(TestQC_Oracle-sp-cursor-decl    compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-cursor-decl.test)
    add_test(TestQC_Oracle-sp-cursor-rowtype compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-cursor-rowtype.test)
    add_test(TestQC_Oracle-sp-cursor         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-cursor.test)
    add_test(TestQC_Oracle-sp-goto           compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-goto.test)
    add_test(TestQC_Oracle-sp-param_inc      compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-param.inc)
    add_test(TestQC_Oracle-sp-param          compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-param.test)
    add_test(TestQC_Oracle-sp-row            compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-row.test)
    add_test(TestQC_Oracle-sp-row-vs-var_inc compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-row-vs-var.inc)
    add_test(TestQC_Oracle-sp-security       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp-security.test)
    add_test(TestQC_Oracle-sp                compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/sp.test)
    add_test(TestQC_Oracle-trigger           compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/trigger.test)
    add_test(TestQC_Oracle-truncate          compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/truncate.test)
    add_test(TestQC_Oracle-type_blob         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_blob.test)
    add_test(TestQC_Oracle-type_clob         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_clob.test)
    add_test(TestQC_Oracle-type_date         compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_date.test)
    add_test(TestQC_Oracle-type_number       compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_number.test)
    add_test(TestQC_Oracle-type_raw          compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_raw.test)
    add_test(TestQC_Oracle-type_varchar      compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_varchar.test)
    add_test(TestQC_Oracle-type_varchar2     compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/type_varchar2.test)
    add_test(TestQC_Oracle-type_variables    compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/oracle/variables.test)
  endif()
endif()

add_subdirectory(canonical_tests)
