cmake_minimum_required(VERSION 3.5)


# set the project name and version
project(Proto-suff VERSION 0.1)

add_custom_target(clean-cmake-files
   COMMAND ${CMAKE_COMMAND} -P clean-all.cmake
)


set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_BUILD_TYPE Release)

include_directories(.)

file(GLOB cmake_generated ${CMAKE_SOURCE_DIR}/src/*~)

foreach(file ${cmake_generated})

  if (EXISTS ${file})
     file(REMOVE_RECURSE ${file})
  endif()

endforeach(file)


# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# source/include files
file(GLOB_RECURSE SOURCES ./src/**.cpp)
file(GLOB_RECURSE INCLUDES ./src/**.hpp)

set(SRCS ${SOURCES})
set(HEADERS ${INCLUDES})

# Find python and Boost - both are required dependencies
find_package(PythonLibs 3 REQUIRED)
find_package(Boost COMPONENTS python3 REQUIRED)

# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")

# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files

if (NOT DEFINED BUILD_MODE)
   set(BUILD_MODE 1)
endif()

add_library(proto_suff MODULE ${SRCS} ${HEADERS})

# flags
if(${BUILD_MODE} EQUAL 1)   
   message("Debug mode activated")   
   set(CMAKE_BUILD_TYPE Debug)   

   # Set up the libraries and header search paths for this target
   target_link_libraries(proto_suff ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
   target_include_directories(proto_suff PRIVATE ${PYTHON_INCLUDE_DIRS})
elseif(${BUILD_MODE} EQUAL 2)
   message("Release mode activated")
   set(CMAKE_BUILD_TYPE Release)
   
   # Set up the libraries and header search paths for this target   
   target_link_libraries(proto_suff ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
   target_include_directories(proto_suff PRIVATE ${PYTHON_INCLUDE_DIRS})
else()  
   message("Classical mode activated")
   # Set up the libraries and header search paths for this target   
   target_link_libraries(proto_suff ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
   target_include_directories(proto_suff PRIVATE ${PYTHON_INCLUDE_DIRS})
endif()
