cmake_minimum_required(VERSION 3.9)
project(search)

set(CMAKE_CXX_STANDARD 20)


if (CMAKE_CONFIGURATION_TYPES)
    set(CMAKE_CONFIGURATION_TYPES Debug Release)
endif ()

find_package(Boost COMPONENTS program_options REQUIRED)
if (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    add_definitions( "-DHAS_BOOST" )
endif()

# get CPM
set(CPM_DOWNLOAD_VERSION 0.34.0)

if(CPM_SOURCE_CACHE)
    set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
    set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
    set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
    message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
    file(DOWNLOAD
            https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
            ${CPM_DOWNLOAD_LOCATION}
            )
endif()

include(${CPM_DOWNLOAD_LOCATION})

# get Magic Enum

CPMAddPackage(
        NAME magic_enum
        GITHUB_REPOSITORY Neargye/magic_enum
        GIT_TAG v0.8.2
)

set(CMAKE_CXX_FLAGS "-Wnon-virtual-dtor")

# Release
set(CMAKE_CXX_FLAGS_RELEASE
        "-O3 -g -DNDEBUG -fomit-frame-pointer ")

# Debug and Profile
set(CMAKE_CXX_FLAGS_DEBUG
        "${CMAKE_CXX_FLAGS_DEBUG} -O0 \
        -fsanitize=undefined -fno-omit-frame-pointer")

# -pg not supported on OS X 10.9 and later
if (NOT APPLE)
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
endif()

add_executable(search
        main.cc
        task.cc task.h
        predicate.cc predicate.h
        object.h
        states/state.cc states/state.h
        parser.cc parser.h
        goal_condition.h
        atom.h
        action_schema.cc action_schema.h
        structures.h
        search_engines/search_factory.cc search_engines/search_factory.h
        search_engines/search.cc search_engines/search.h
        search_engines/breadth_first_search.cc search_engines/breadth_first_search.h
        search_engines/greedy_best_first_search.cc search_engines/greedy_best_first_search.h
        search_engines/nodes.cc search_engines/nodes.h
        search_engines/utils.cc search_engines/utils.h
        search_engines/search_space.cc search_engines/search_space.h
        search_engines/initial_adds.h
        search_engines/initial_adds.tpp
        action.cc action.h
        successor_generators/successor_generator.h
        database/table.cc database/table.h
        database/join.cc database/join.h
        database/utils.cc database/utils.h
        heuristics/goalcount.cc  heuristics/goalcount.h
        heuristics/heuristic.h
        heuristics/heuristic_factory.cc heuristics/heuristic_factory.h
        heuristics/blind_heuristic.h
        successor_generators/successor_generator_factory.cc successor_generators/successor_generator_factory.h
        successor_generators/naive_successor.h
        successor_generators/ordered_join_successor.cc successor_generators/ordered_join_successor.h
        successor_generators/generic_join_successor.cc successor_generators/generic_join_successor.h
        successor_generators/full_reducer_successor_generator.cc successor_generators/full_reducer_successor_generator.h
        database/semi_join.h database/semi_join.cc
        database/hash_join.cc database/hash_join.h
        hash_structures.cc hash_structures.h
        database/hash_semi_join.cc database/hash_semi_join.h
        utils.cc utils.h
        successor_generators/random_successor.h successor_generators/random_successor.cc
        successor_generators/yannakakis.cc successor_generators/yannakakis.h
        database/project.cc database/project.h
        utils/segmented_vector.h
        states/extensional_states.cc states/extensional_states.h
        states/sparse_states.cc states/sparse_states.h
        utils/hash.h
        algorithms/cartesian_iterator.h
        utils/collections.h
        utils/language.h
        utils/system.cc utils/system.h
        utils/system_unix.cc utils/system_unix.h
        utils/system_windows.cc utils/system_windows.h
        utils/logging.cc utils/logging.h
        utils/timer.cc utils/timer.h
        algorithms/int_hash_set.h
        algorithms/dynamic_bitset.h
        search_statistics.cc search_statistics.h
        options.h open_lists/greedy_open_list.h
        search_engines/breadth_first_width_search.cc search_engines/breadth_first_width_search.h
        novelty/standard_novelty.cc novelty/standard_novelty.h
        open_lists/tiebreaking_open_list.h
        novelty/achieved_ground_atoms.h
        novelty/atom_counter.h
        search_engines/dual_queue_bfws.cc search_engines/dual_queue_bfws.h
        novelty/node_novelty.h
        search_engines/alternated_bfws.cc search_engines/alternated_bfws.h
        search_engines/lazy_search.cc search_engines/lazy_search.h
        search_engines/lazy_search.cc search_engines/lazy_search.h
        search_engines/astar_search.cc search_engines/astar_search.h
        datalog/datalog.cc datalog/datalog.h
        datalog/arguments.h
        datalog/datalog_atom.cc datalog/datalog_atom.h
        datalog/datalog_fact.cc datalog/datalog_fact.h
        datalog/term.h
        datalog/object.cc datalog/object.h
        datalog/rules/rule_base.cc datalog/rules/rule_base.h
        delete_relaxation_heuristics/delete_relaxation_heuristic.h
        datalog/rules/generic_rule.h
        datalog/rules/join.h
        datalog/rules/product.h
        datalog/rules/project.h
        heuristics/ff_heuristic.h
        datalog/annotations/annotation.h
        datalog/ground_rule.h
        heuristics/ff_heuristic.cc
        heuristics/rff_heuristic.cc
        heuristics/rff_heuristic.h
        heuristics/datalog_transformation_options.h
        datalog/achievers.h
        datalog/transformations/action_predicate_removal.h
        datalog/transformations/normal_form.h
        datalog/transformations/greedy_join.h
        datalog/transformations/goal_rule.h
        datalog/transformations/generate_edb.h datalog/rules/variable_source.h
        datalog/grounder/grounder.h
        datalog/grounder/weighted_grounder.cc datalog/grounder/weighted_grounder.h
        datalog/rule_matcher.cc datalog/rule_matcher.h heuristics/add_heuristic.cc
        heuristics/add_heuristic.h heuristics/utils.h heuristics/utils.cc
        datalog/transformations/remove_equivalent_rules.h datalog/transformations/connected_components.h
        datalog/transformations/variable_projection.h datalog/transformations/variable_renaming.h heuristics/hmax_heuristic.cc heuristics/hmax_heuristic.h
        parallel_hashmap/phmap.h search_engines/initial_h.h search_engines/initial_h.tpp

        #TODO: just ask HeLP-CMakeList for this
        HeLP-core/src/utils/type_defs.h
        HeLP-core/src/task_formulations/lifted_strips_task.h
        HeLP-core/src/task_formulations/lifted_strips_task.cpp

        HeLP-core/src/input_handling/input_handler.h
        HeLP-core/src/input_handling/input_handler.cpp

        HeLP-core/src/input_handling/parser/parser.h
        HeLP-core/src/input_handling/parser/parser.tpp

        HeLP-core/src/input_handling/lexer/token.h
        HeLP-core/src/input_handling/lexer/token.cpp
        HeLP-core/src/input_handling/lexer/lexer.h
        HeLP-core/src/input_handling/lexer/lexer.cpp

        HeLP-core/src/input_handling/parser/parser.h
        HeLP-core/src/input_handling/parser/parser.tpp

        HeLP-core/src/input_handling/parser/argparser/arg_parser.h
        HeLP-core/src/input_handling/parser/argparser/arg_parser.cpp

        HeLP-core/src/input_handling/parser/datalog/datalog_parser.h
        HeLP-core/src/input_handling/parser/datalog/datalog_parser.cpp

        HeLP-core/src/logging/logger.h

        HeLP-core/src/cmd_opts/lex.h
        HeLP-core/src/cmd_opts/cmd_opt.h
        HeLP-core/src/cmd_opts/cmd_opt.cpp

        HeLP-core/src/input_handling/parser/datalog/datalog_parser.h
        HeLP-core/src/input_handling/parser/datalog/datalog_parser.cpp

        HeLP-core/src/conj_query_eval/join_and_project.cpp
        HeLP-core/src/conj_query_eval/join_and_project.h

        HeLP-core/src/conj_query_eval/table_representation/table.cpp
        HeLP-core/src/conj_query_eval/table_representation/table.h

        HeLP-core/src/conj_query_eval/join_order_generator/criterion_join_list.h
        HeLP-core/src/conj_query_eval/join_order_generator/join_by_criterion.tpp
        HeLP-core/src/conj_query_eval/join_order_generator/join_by_criterion.h
        HeLP-core/src/conj_query_eval/join_order_generator/join_order_generator.cpp
        HeLP-core/src/conj_query_eval/join_order_generator/join_order_generator.h

        HeLP-core/src/conj_query_eval/join_order_generator/join_criteria/random.tpp
        HeLP-core/src/conj_query_eval/join_order_generator/join_criteria/random.h
        HeLP-core/src/conj_query_eval/join_order_generator/join_criteria/yannakakis.tpp
        HeLP-core/src/conj_query_eval/join_order_generator/join_criteria/yannakakis.h

        HeLP-core/src/conj_query_eval/join_realizer/init_nodes.h
        HeLP-core/src/conj_query_eval/join_realizer/init_nodes.cpp
        HeLP-core/src/conj_query_eval/join_realizer/nodes.cpp
        HeLP-core/src/conj_query_eval/join_realizer/nodes.h
        HeLP-core/src/conj_query_eval/join_realizer/join_order_graph.h
        HeLP-core/src/conj_query_eval/join_realizer/join_order_graph.cpp

        HeLP-core/src/conj_query_eval/table_representation/table_cache.h
        HeLP-core/src/conj_query_eval/table_representation/table_cache.cpp
        HeLP-core/src/conj_query_eval/table_representation/table.h
        HeLP-core/src/conj_query_eval/table_representation/table.cpp

        HeLP-core/src/conj_query_eval/query_sort.h
        HeLP-core/src/conj_query_eval/join_realizer/join_order_graph.tpp
        HeLP-core/src/heuristics/heuristic.h
        HeLP-core/src/heuristics/regr_add.cpp
        HeLP-core/src/conj_query_eval/join_realizer/start_node_manager.h
        HeLP-core/src/conj_query_eval/join_realizer/start_node_manager.tpp
        heuristics/help_heuristic.cpp
        HeLP-core/src/utils/hashes.h HeLP-core/src/utils/common_func.h)


target_link_libraries(search magic_enum)
target_link_libraries(search ${Boost_LIBRARIES})
