cmake_minimum_required(VERSION 3.0)

project(par_gwas)

# Common compiler options among built types
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Specific compiler options for Debug or Release builds
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -ggdb -Wall -fopenmp -pedantic")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g -Wall -fopenmp -pedantic -O1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1 -fopenmp")

find_package(OpenMP REQUIRED)
find_package(MPI REQUIRED)
find_package(Boost REQUIRED mpi)
find_package(Palisade REQUIRED PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../Duality_Technologies/PALISADE/)

set( CMAKE_CXX_FLAGS ${PALISADE_CXX_FLAGS} )
set( CMAKE_EXE_LINKER_FLAGS ${PALISADE_EXE_LINKER_FLAGS} )

include_directories( ${PALISADE_INCLUDE} )
include_directories( ${PALISADE_INCLUDE}/core )
include_directories( ${PALISADE_INCLUDE}/pke )
include_directories(${Boost_INCLUDE_DIR})

include_directories("${CMAKE_SOURCE_DIR}/Duality_Technologies/GWAS/")
#include_directories("${CMAKE_SOURCE_DIR}/PLINK/libplinkio/")
#include_directories("${CMAKE_SOURCE_DIR}/PLINK/libplinkio/install/include/plinkio/")
#include_directories("${CMAKE_SOURCE_DIR}/PLINK/libplinkio/libs/cmockery/")
#include_directories("${CMAKE_SOURCE_DIR}/PLINK/libplinkio/libs/libcsv/inc/")

link_directories( ${PALISADE_LIBDIR} )

# Enable thread-level parallelization if OpenMP is found.
if(OpenMP_CXX_FOUND)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

if(MPI_CXX_FOUND)
	INCLUDE_DIRECTORIES(${MPI_CXX_INCLUDE_PATH})
	LIST(APPEND SCR_EXTERNAL_LIBS ${MPI_CXX_LIBRARIES})
	#set(CMAKE_CXX_COMPILER "mpic++")
endif()

file(GLOB gwas_src "${CMAKE_SOURCE_DIR}/Duality_Technologies/GWAS/demo-chi2.cpp" "${CMAKE_SOURCE_DIR}/Duality_Technologies/GWAS/demo-chi2.h")
#add_library(gwas "${CMAKE_SOURCE_DIR}/Duality_Technologies/GWAS/demo-chi2.cpp")

#file(GLOB libplink_src "${CMAKE_SOURCE_DIR}/PLINK/libplinkio/src/*.c" "${CMAKE_SOURCE_DIR}/PLINK/libplinkio/src/*.cpp")
#file(GLOB plinkio_src "${CMAKE_SOURCE_DIR}/PLINK/libplinkio/src/plinkio/*.c" "${CMAKE_SOURCE_DIR}/PLINK/libplinkio/src/plinkio/*.cpp")

add_executable(par_gwas "${CMAKE_SOURCE_DIR}/src/main.cpp" ${gwas_src})
target_link_libraries(par_gwas Boost::mpi ${MPI_CXX_LIBRARIES}) #libplinkio)

#				${gwas_src}) #${libplink_src}) #${plinkio_src})
				

