# 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(IPIN2016)

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



INCLUDE_DIRECTORIES(
	../../
)


FILE(GLOB HEADERS
	./*.h
	./*/*.h
	./*/*/*.h
	./*/*/*/*.h
	./*/*/*/*/*.h
	./*/*/*/*/*/*.h
)

FILE(GLOB SOURCES
	./*.cpp
	./*/*.cpp
	./*/*/*.cpp
	./*/*/*/*.cpp
	../../KLib/inc/tinyxml/*.cpp
)


if(${CMAKE_GENERATOR} MATCHES "Visual Studio")

  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_X86_ /D_USE_MATH_DEFINES")
  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /Oi /GL /Ot /Ox /D_X86_ /D_USE_MATH_DEFINES")
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
  SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO")

  set(CMAKE_CONFIGURATION_TYPES Release Debug)

else()

# system specific compiler flags
ADD_DEFINITIONS(

    -std=gnu++11

	-Wall
	-Werror=return-type
	-Wextra
	-Wpedantic

	-fstack-protector-all

	-g
        -O2
	-DWITH_TESTS
	-DWITH_ASSERTIONS

)

endif()


# 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}
	gtest
	pthread
)

SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})

