# Get the name of the current directory but with no path:
get_filename_component(PATHNAME ${CMAKE_CURRENT_BINARY_DIR} ABSOLUTE)

message("")
message(STATUS "${BoldGreen}Start processing ${PATHNAME} dir.${ColourReset}")
message("")

set(TARGET tests)

########################################################
# Files

# We use the object file collection system of CMake (they call the library an
# "OBJECT" library type). The list of compiled object files from minexpert are
# stored in $<TARGET_OBJECTS:minexpert-objlib>. We use that identifier so as to
# avoid recompilation of the files for the testing purpose.

# But we also have the source files of the tests, these files are distributed
# among the various directories : src/libmass and src/minexpert at the moment.

file(GLOB ${TARGET}_libmassTest_SRCS
	src/libmass/*.cpp)

file(GLOB ${TARGET}_minexpertTest_SRCS
	src/minexpert/*.cpp)

set(SRCTEST
	src/testmain.cpp
	${${TARGET}_minexpertTest_SRCS}
	${${TARGET}_libmassTest_SRCS})

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

find_package(Qt5 COMPONENTS Widgets Xml Svg Sql Script)

qt5_wrap_ui(${TARGET}_UIS_H ${${TARGET}_UIS})

qt5_add_resources(${TARGET}QRC_CPP gui/application.qrc)

add_executable(${TARGET}
	${SRCTEST}
	$<TARGET_OBJECTS:minexpert-objlib>)

target_compile_definitions(${TARGET} PRIVATE TESTS) #add -DTESTS
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 14) # we want C++14

qt5_use_modules(${TARGET} Widgets)
qt5_use_modules(${TARGET} Xml)
qt5_use_modules(${TARGET} Svg)
qt5_use_modules(${TARGET} Sql)
qt5_use_modules(${TARGET} Script)
qt5_use_modules(${TARGET} PrintSupport)

include_directories(
	# For the config.h file generated from config.h.in	
	${CMAKE_BINARY_DIR}

	# For the globals/globals.hpp inclusion
	${CMAKE_SOURCE_DIR}

	${CMAKE_SOURCE_DIR}/libmass
	${CMAKE_SOURCE_DIR}/libmassgui
	${CMAKE_SOURCE_DIR}/minexpert/nongui
	${CMAKE_SOURCE_DIR}/minexpert/gui

	${CMAKE_BINARY_DIR}/libmass
	${CMAKE_BINARY_DIR}/libmassgui

	# For the ui_Xyyyyy.h files of both modules.
	${CMAKE_BINARY_DIR}/massxpert
	${CMAKE_BINARY_DIR}/minexpert

	${CMAKE_CURRENT_SOURCE_DIR}

	${Qt5Widgets_INCLUDE_DIRS}
	${Qt5Xml_INCLUDE_DIRS}
	${Qt5Svg_INCLUDE_DIRS}
	${Qt5Sql_INCLUDE_DIRS}
	${Qt5Script_INCLUDE_DIRS}
	${Qt5PrintSupport_INCLUDE_DIRS}
	/usr/include/proteowizard
	)

target_include_directories(${TARGET} PRIVATE
	${INCLUDE_DIRECTORIES}
	)


# Now handle the private libraries for non-gui stuff (libmass.a) and gui stuff
# (libmassgui.a)
set(MASSLIB -Wl,-whole-archive ${CMAKE_BINARY_DIR}/libmass/libmass.a -Wl,-no-whole-archive)
set(MASSGUILIB -Wl,-whole-archive ${CMAKE_BINARY_DIR}/libmassgui/libmassgui.a -Wl,-no-whole-archive)

set(required_target_link_libraries
	${MASSLIB}
	${MASSGUILIB}
	${OPENMP_LIBRARY}	
	Qt5::Widgets
	Qt5::Xml
	Qt5::Svg
	Qt5::Sql
	Qt5::Script
	Qt5::PrintSupport
	"qcustomplot"
	pwiz)

### Debugging stuff
#message(STATUS required_target_link_libraries: ${required_target_link_libraries})
#get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
#foreach(dir ${dirs})
#message(STATUS "included dir='${dir}'")
#endforeach()

target_link_libraries(${TARGET}
	${required_target_link_libraries})

# Add an explicit dependency to libmass and libmassgui so that when invoking
# make from inside the massxpert bin build dir, the dependencies get built.
add_dependencies(${TARGET} mass massgui)

message("")
message(STATUS "${BoldGreen}Finished processing ${PATHNAME} dir.${ColourReset}")
message("")



