166 lines
5.1 KiB
CMake
166 lines
5.1 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(sudoku_demo CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Add the main project as a subdirectory to get the nd-wfc library
|
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../src ${CMAKE_CURRENT_BINARY_DIR}/nd-wfc)
|
|
|
|
# Enable testing
|
|
enable_testing()
|
|
|
|
# Add compiler warnings
|
|
if(MSVC)
|
|
add_compile_options(/W4)
|
|
else()
|
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
|
endif()
|
|
|
|
# Find Google Test (optional)
|
|
find_package(GTest)
|
|
if(GTest_FOUND)
|
|
set(HAS_GTEST TRUE)
|
|
else()
|
|
set(HAS_GTEST FALSE)
|
|
message(WARNING "Google Test not found. Tests will not be built.")
|
|
endif()
|
|
|
|
# Find Google Benchmark (optional)
|
|
find_package(benchmark)
|
|
if(benchmark_FOUND)
|
|
set(HAS_BENCHMARK TRUE)
|
|
else()
|
|
set(HAS_BENCHMARK FALSE)
|
|
message(WARNING "Google Benchmark not found. Benchmarks will not be built.")
|
|
endif()
|
|
|
|
# Create the main executable
|
|
add_executable(sudoku_demo
|
|
main.cpp
|
|
sudoku.cpp
|
|
)
|
|
|
|
# Create WFC demo executable
|
|
add_executable(sudoku_wfc_demo
|
|
sudoku_wfc.cpp
|
|
sudoku.cpp
|
|
)
|
|
|
|
# Create failing puzzles analyzer executable
|
|
add_executable(analyze_failing_puzzles
|
|
analyze_failing_puzzles.cpp
|
|
sudoku.cpp
|
|
)
|
|
|
|
# Create debug failing puzzles executable
|
|
add_executable(debug_failing_puzzles
|
|
debug_failing_puzzles.cpp
|
|
sudoku.cpp
|
|
)
|
|
|
|
# Link all executables to the nd-wfc library
|
|
target_link_libraries(sudoku_demo PRIVATE nd-wfc)
|
|
target_link_libraries(sudoku_wfc_demo PRIVATE nd-wfc)
|
|
target_link_libraries(analyze_failing_puzzles PRIVATE nd-wfc)
|
|
target_link_libraries(debug_failing_puzzles PRIVATE nd-wfc)
|
|
|
|
# Set output directory for sudoku_demo
|
|
set_target_properties(sudoku_demo PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
)
|
|
|
|
# Set output directory and properties for sudoku_wfc_demo
|
|
set_target_properties(sudoku_wfc_demo PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
CXX_STANDARD 20
|
|
CXX_STANDARD_REQUIRED ON
|
|
)
|
|
|
|
# Set output directory and properties for analyze_failing_puzzles
|
|
set_target_properties(analyze_failing_puzzles PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
CXX_STANDARD 20
|
|
CXX_STANDARD_REQUIRED ON
|
|
)
|
|
|
|
# Set output directory and properties for debug_failing_puzzles
|
|
set_target_properties(debug_failing_puzzles PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
CXX_STANDARD 20
|
|
CXX_STANDARD_REQUIRED ON
|
|
)
|
|
|
|
# Include directories (current source directory for local headers)
|
|
target_include_directories(sudoku_demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_include_directories(sudoku_wfc_demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_include_directories(analyze_failing_puzzles PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_include_directories(debug_failing_puzzles PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
# Optional: Enable optimizations for release builds
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
if(MSVC)
|
|
target_compile_options(sudoku_demo PRIVATE /O2)
|
|
target_compile_options(sudoku_wfc_demo PRIVATE /O2)
|
|
target_compile_options(analyze_failing_puzzles PRIVATE /O2)
|
|
target_compile_options(debug_failing_puzzles PRIVATE /O2)
|
|
else()
|
|
target_compile_options(sudoku_demo PRIVATE -O3 -march=native)
|
|
target_compile_options(sudoku_wfc_demo PRIVATE -O3 -march=native)
|
|
target_compile_options(analyze_failing_puzzles PRIVATE -O3 -march=native)
|
|
target_compile_options(debug_failing_puzzles PRIVATE -O3 -march=native)
|
|
endif()
|
|
endif()
|
|
|
|
# Create test executable (if GTest is available)
|
|
if(HAS_GTEST)
|
|
add_executable(sudoku_tests
|
|
sudoku.cpp
|
|
test_sudoku.cpp
|
|
)
|
|
|
|
target_link_libraries(sudoku_tests GTest::gtest GTest::gtest_main nd-wfc pthread)
|
|
|
|
# Set test output directory
|
|
set_target_properties(sudoku_tests PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
CXX_STANDARD 20
|
|
CXX_STANDARD_REQUIRED ON
|
|
)
|
|
|
|
# Include directories for tests
|
|
target_include_directories(sudoku_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
# Add test to CTest
|
|
add_test(NAME sudoku_tests COMMAND sudoku_tests)
|
|
endif()
|
|
|
|
# Create benchmark executable (if Google Benchmark is available)
|
|
if(HAS_BENCHMARK)
|
|
add_executable(sudoku_benchmarks
|
|
sudoku.cpp
|
|
benchmark_sudoku.cpp
|
|
)
|
|
|
|
target_link_libraries(sudoku_benchmarks benchmark::benchmark nd-wfc pthread)
|
|
|
|
# Set benchmark output directory
|
|
set_target_properties(sudoku_benchmarks PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
|
CXX_STANDARD 20
|
|
CXX_STANDARD_REQUIRED ON
|
|
)
|
|
|
|
# Include directories for benchmarks
|
|
target_include_directories(sudoku_benchmarks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
endif()
|
|
|
|
# Installation (optional)
|
|
if(HAS_GTEST AND HAS_BENCHMARK)
|
|
install(TARGETS sudoku_demo sudoku_wfc_demo analyze_failing_puzzles debug_failing_puzzles sudoku_tests sudoku_benchmarks DESTINATION bin)
|
|
elseif(HAS_GTEST)
|
|
install(TARGETS sudoku_demo sudoku_wfc_demo analyze_failing_puzzles debug_failing_puzzles sudoku_tests DESTINATION bin)
|
|
else()
|
|
install(TARGETS sudoku_demo sudoku_wfc_demo analyze_failing_puzzles debug_failing_puzzles DESTINATION bin)
|
|
endif()
|