cmake_minimum_required(VERSION 3.10)
project(brownan-solver C)

set(CMAKE_C_STANDARD 99)

if(MSVC)
    add_compile_options(/W4 /O2)
else()
    add_compile_options(-Wall -Wextra -O3)
endif()

set(SOURCES
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/cube.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/stack.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/common.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/cornertable.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/goal.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/edgetable.c
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/main.c
)

set(HEADERS
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/cube.h
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/stack.h
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/common.h
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/cornertable.h
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/goal.h
    ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/edgetable.h
)

add_executable(brownan-solver ${SOURCES} ${HEADERS})

# Copy tables next to executable after build
add_custom_command(TARGET brownan-solver POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/table_corner.rht
        ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/table_edge1.rht
        ${CMAKE_SOURCE_DIR}/../../.external/Rubiks-Cube-Solver/table_edge2.rht
        $<TARGET_FILE_DIR:brownan-solver>
    COMMENT "Copying solver tables"
)
