cmake_minimum_required(VERSION 3.0)
project(ex1
  VERSION 0.1
  LANGUAGES CXX)

###########
# Debug or Release
###########
if (NOT CMAKE_BUILD_TYPE)
  ## set default to Debug
  set(CMAKE_BUILD_TYPE RelWithDebInfo)  # override with -DCMAKE_BUILD_TYPE=Release
  message("==> CMAKE_BUILD_TYPE empty. Changing it to Debug.")
else()
  message("==> CMAKE_BUILD_TYPE == ${CMAKE_BUILD_TYPE}.")
endif()

## set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -DGLIBCXX_FORCE_NEW")

## https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
## During Debug, use debug version of libstdc++ (asserts on access to invalid iterators, etc!)
## set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

# Conan Setup
add_definitions("-std=c++11")
set(Boost_USE_STATIC_LIBS        ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

##############
# C++ Standard
##############
# set(CMAKE_CXX_STANDARD   14)
# C++17 gives me transform
set(CMAKE_CXX_STANDARD   17)
set(CMAKE_CXX_EXTENSIONS ON)

# ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

# We only need the one header file.
# if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/json)
#   message("***")
#   message("*** ERROR/MISSING *** please run: git clone https://github.com/nlohmann/json.git --depth 1")
#   message("***")
# endif()
# add_subdirectory(json)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
  message("***")
  message("*** ERROR/MISSING *** please run: git clone https://github.com/google/googletest.git --depth 1")
  message("***")
endif()

add_subdirectory(googletest)

option(gtest_build_samples "Build gtest's sample programs." OFF)
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)

### TESTS
add_executable(test-galaxy test-galaxy.cpp galaxy.cpp config.cpp utils.cpp buysell.cpp)
add_dependencies(test-galaxy gtest)
target_link_libraries(test-galaxy gtest_main ${CONAN_LIBS})

add_executable(test-director test-director.cpp galaxy.cpp utils.cpp buysell.cpp director.cpp dispatchers.cpp boxes.cpp scripts.cpp config.cpp ansicolor.cpp)
add_dependencies(test-director gtest)
target_link_libraries(test-director gtest_main ${CONAN_LIBS})

enable_testing()
add_test(NAME test-galaxy
  COMMAND test-galaxy)
add_test(NAME test-director
  COMMAND test-director)

# dispatchers.cpp 
ADD_EXECUTABLE( twproxy twproxy.cpp utils.cpp session.cpp boxes.cpp director.cpp galaxy.cpp dispatchers.cpp scripts.cpp buysell.cpp config.cpp ansicolor.cpp)
TARGET_LINK_LIBRARIES( twproxy ${CONAN_LIBS} pthread)

# Remove precompile headers, that also doesn't work.
# target_precompile_headers(twproxy PRIVATE pch.hpp)