cmake_minimum_required(VERSION 3.21) project(aoc VERSION 0.0.0) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Group CMake targets inside a folder set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json for language servers include(FetchContent) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 10.1.0 ) list(APPEND FETCH_CONTENTS fmt) FetchContent_Declare( utf8cpp GIT_REPOSITORY https://github.com/nemtrif/utfcpp.git GIT_TAG v4.0.5 ) list(APPEND FETCH_CONTENTS utf8cpp) FetchContent_Declare( stb GIT_REPOSITORY https://github.com/mononerv/stb.git GIT_TAG 698c6fb9889c71494b49c9187d249af5fc87b211 ) list(APPEND FETCH_CONTENTS stb) # Turn off BUILD_TESTING globally to prevent CTest from being included in CTRE set(BUILD_TESTING OFF CACHE BOOL "Disable testing globally" FORCE) # Set the CTRE_BUILD_TESTS option before including the CTRE library set(CTRE_BUILD_TESTS OFF CACHE BOOL "Build ctre Tests" FORCE) FetchContent_Declare( ctre GIT_REPOSITORY https://github.com/hanickadot/compile-time-regular-expressions.git GIT_TAG v3.9.0 ) list(APPEND FETCH_CONTENTS ctre) FetchContent_MakeAvailable(${FETCH_CONTENTS}) find_package(Threads REQUIRED) # Group dependencies in Visual Studio and Xcode if (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode") set_target_properties(fmt PROPERTIES FOLDER deps) set_target_properties(stb PROPERTIES FOLDER deps) endif() set(BASE_DEFINITIONS "ASIO_STANDALONE") if (APPLE) message("Platform Apple") list(APPEND BASE_DEFINITIONS "AOC_PLATFORM=Apple" ) set(IS_UNIX true) elseif (UNIX AND NOT APPLE AND NOT EMSCRIPTEN) # Linux, BSD, Solaris, Minix message("Platform Unix") list(APPEND BASE_DEFINITIONS "AOC_PLATFORM=Linux" ) set(IS_UNIX true) elseif (WIN32) message("Platform Windows") list(APPEND BASE_DEFINITIONS "AOC_PLATFORM=Windows" ) else() message(FATAL_ERROR "Unkown platform!") endif() # Compiler specific options if (NOT MSVC) set(BASE_OPTIONS "-Wall" "-Wextra" "-Wconversion" "-Wpedantic" "-Wshadow" "-Werror" # fmt warnings "-Wno-unknown-attributes" # ctre warning "-Wno-missing-template-arg-list-after-template-kw" ) else() set(BASE_OPTIONS "/W4" "/WX" "/utf-8" "/Zc:__cplusplus" #"/fsanitize=address" # Doesn't work without Visual Studio ) endif() set(HEADERS aoc/aoc.hpp ) set(SOURCES "aoc.cpp") add_library(aoc OBJECT ${HEADERS} ${SOURCES}) target_include_directories(aoc PUBLIC ${PROJECT_SOURCE_DIR} PRIVATE ${PROJECT_SOURCE_DIR}/aoc ) target_compile_features(aoc PRIVATE cxx_std_23) target_compile_options(aoc PRIVATE ${BASE_OPTIONS}) target_compile_definitions(aoc PRIVATE ${BASE_DEFINITIONS} ) target_link_libraries(aoc PUBLIC fmt utf8cpp ctre stb::stb Threads::Threads ) source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES}) add_subdirectory(sol/24)