cmake_minimum_required(VERSION 3.28.0)
project(2pac)

# Make produced makefile show full commands.
set(CMAKE_VERBOSE_MAKEFILE ON)
# Set details for release and debug mode. Use release by default.
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()
# set(CMAKE_DEBUG_POSTFIX _debug)
# Specify flags
set(CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -flto")
set(CMAKE_CXX_FLAGS_DEBUG "-D_LIBCPP_ENABLE_ASSERTIONS=1 -g")
# Build variant for vector-matrices
option(VECTORS "Build with sorted vectors as spase matrix implementatiton")
if(VECTORS)
   message("Building with vectors")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DARRAY_MATRICES")
endif()

set(SRC_FILES
    minimize.cpp factor.cpp chunk.cpp reductions.cpp bireductions.cpp 
    lw.cpp complexes.cpp matrices.cpp ArrayColumn.cpp HeapColumn.cpp 
    time_measurement.cpp block_column_matrix.cpp Cone.cpp 
    relative_cohomology.cpp computation.cpp CliqueComplex.cpp
)


add_executable(2pac 2pac.cpp ${SRC_FILES})
# set_target_properties(2pac PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR_RELEASE})
target_link_libraries(2pac ${Boost_PROGRAM_OPTIONS_LIBRARY})

find_package(OpenMP COMPONENTS CXX)
if(OpenMP_CXX_FOUND)
    message("Will compile with multiprocessing.")
    target_compile_options(2pac PRIVATE ${OpenMP_CXX_FLAGS})
    target_link_libraries(2pac ${OpenMP_CXX_FLAGS})
else()
    message("Will compile WITHOUT multiprocessing.")
endif()

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11)
if(pybind11_FOUND)
    message("Will build python bindings.")
    pybind11_add_module(2pacpy bindings.cpp ${SRC_FILES})
    if(OpenMP_XXX_FOUND)
        target_compile_options(2pacpy PRIVATE ${OpenMP_CXX_FLAGS})
        target_link_libraries(2pacpy ${OpenMP_CXX_FLAGS})
    endif()
    set_target_properties(2pacpy PROPERTIES OUTPUT_NAME twopac)
    # set_target_properties(2pacpy PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
else()
	message(WARNING "Could not find pybind11; will compile without python bindings.")
endif()
