# Usage:
#  Create build folder, like RC-build next to RobotControl and WifiScan folder
#  CD into build folder and execute 'cmake -DCMAKE_BUILD_TYPE=Debug ../RobotControl'
#  make

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

# select build type
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" )

PROJECT(ProLogic)

IF(NOT CMAKE_BUILD_TYPE)
	MESSAGE(STATUS "No build type selected. Default to Debug")
	SET(CMAKE_BUILD_TYPE "Debug")
ENDIF()



INCLUDE_DIRECTORIES(
    ../
    ../../
    ../../../
    ../../../../
	
	../../eigen3
)


FILE(GLOB HEADERS
    filter.h
	mesh.h
	meshPlotter.h
    Plotti.h
    Plotty.h
    Settings.h
    FtmKalman.h
    main.h
    trilateration.h
    Plotta.h
    misc.h
    Eval.h
)


FILE(GLOB SOURCES
    ../../Indoor/lib/tinyxml/tinyxml2.cpp
    ../../Indoor/lib/Recast/*.cpp
    main.cpp
    mainTrilat.cpp
    mainProb.cpp
    Eval.cpp
    FtmKalman.cpp
	trilateration.cpp	
)


if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
    add_definitions(
		-D_USE_MATH_DEFINES
		-DUNICODE
		-D_UNICODE
		-DNOGDI
	)
	
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")  # multi processor compilation
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:twoPhase-") # disable two-phase name lookup due to OpenMP
	
else()	
	# system specific compiler flags
	ADD_DEFINITIONS(

                -std=gnu++17

                #-lstdc++fs
		
		-Wall
		-Werror=return-type
		-Wextra
		-Wpedantic

		-fstack-protector-all

		-g3
                #-O2
		-march=native

	)	
endif()

add_definitions(
#	-DWITH_TESTS
	-DWITH_ASSERTIONS
        -DWITH_DEBUG_LOG
#	-DWITH_DEBUG_PLOT
#	-D_GLIBCXX_DEBUG
)

# allow OMP
find_package(OpenMP)
if (OPENMP_FOUND)
        set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()


# build a binary file
ADD_EXECUTABLE(
	${PROJECT_NAME}
	${HEADERS}
	${SOURCES}
)

# needed external libraries
TARGET_LINK_LIBRARIES(
	${PROJECT_NAME}
#        stdc++fs
#	gtest
#	pthread
)

if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
    get_filename_component(smartCmdArgJsonFile "ftmprologic.args.json" ABSOLUTE)
    MESSAGE(STATUS "Path to json file: " ${smartCmdArgJsonFile})

    set_property(TARGET ProLogic PROPERTY VS_GLOBAL_SmartCmdArgJsonFile ${smartCmdArgJsonFile})
endif()

SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})

