cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
Include(FetchContent)

set(CMAKE_CXX_STANDARD 23) # latest c++
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# prepare out unit test framework
FetchContent_Declare(
  Catch2
  GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  GIT_TAG        v3.4.0 # or a later release
)
FetchContent_MakeAvailable(Catch2)

# Versioning
project ("AdventOfCode2024" VERSION 0.0.1 DESCRIPTION "" LANGUAGES CXX)
# ---

# Grab source files
file(GLOB_RECURSE AdventOfCode2024Sources
	"include/*.h"
	"include/*.hpp"
	"src/*.c"
	"src/*.cpp"
)
file(GLOB_RECURSE AdventOfCode2024Tests
	"tests/include/*.h"
	"tests/include/*.hpp"
	"tests/src/*.c"
	"tests/src/*.cpp"
)

# Project setup
set(output_target AdventOfCode2024)

# This is split in 2 because catch2 generates its own main() functions
# and we don't want to recompile everything twice, so we reuse the lib object.
#            lib
#          /     \
# main exe         catch2

# Library to contain logic/code
add_library(${output_target}-lib ${AdventOfCode2024Sources})
target_include_directories(${output_target}-lib PUBLIC "include")

# Executable that links to the lib containing the code
add_executable(${output_target} "AdventOfCode2024.cpp")
target_link_libraries(${output_target} PRIVATE ${output_target}-lib)

# Catch2 linked with the lib.
add_executable(${output_target}-tests ${AdventOfCode2024Tests})
target_include_directories(${output_target}-tests PRIVATE "tests/include")
target_link_libraries(${output_target}-tests PRIVATE
	${output_target}-lib
	Catch2::Catch2WithMain
)