
include(CXXHelpers)

# depends on logic checking on parent CMakeLists.txt first
if (ALL_CHAPTERS)
    foreach(chapter ${CHAPTER_LIST})
        target_compile_features(${PREFIX_PROJECT_NAME}-${chapter} INTERFACE cxx_std_17)
    endforeach()
else()
    target_compile_features(${PREFIX_PROJECT_NAME}-${CHAPTER} INTERFACE cxx_std_17)
endif()

if (CMAKE_COMPILER_IS_GNUCXX)
    include(gccdefaults)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    include(clangdefaults)
elseif(MSVC)
    include(msvcdefaults)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
    if (ALL_CHAPTERS)
        foreach(chapter ${CHAPTER_LIST})
            target_compile_definitions(${PREFIX_PROJECT_NAME}-${chapter} PUBLIC BUILD_OPTLEVEL_OPT)
        endforeach()
    else()
        target_compile_definitions(${PREFIX_PROJECT_NAME}-${CHAPTER} PUBLIC BUILD_OPTLEVEL_OPT)
    endif()

elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    if (ALL_CHAPTERS)
        foreach(chapter ${CHAPTER_LIST})
            target_compile_definitions(${PREFIX_PROJECT_NAME}-${chapter} PUBLIC BUILD_OPTLEVEL_OPT)
        endforeach()
    else()
        target_compile_definitions(${PREFIX_PROJECT_NAME}-${CHAPTER} PUBLIC BUILD_OPTLEVEL_OPT)
    endif()

elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
    if (ALL_CHAPTERS)
        foreach(chapter ${CHAPTER_LIST})
            target_compile_definitions(${PREFIX_PROJECT_NAME}-${chapter} PUBLIC BUILD_OPTLEVEL_OPT)
        endforeach()
    else()
        target_compile_definitions(${PREFIX_PROJECT_NAME}-${CHAPTER} PUBLIC BUILD_OPTLEVEL_OPT)
    endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
    if (ALL_CHAPTERS)
        foreach(chapter ${CHAPTER_LIST})
            target_compile_definitions(${PREFIX_PROJECT_NAME}-${chapter} PUBLIC BUILD_OPTLEVEL_DEV)
        endforeach()
    else()
        target_compile_definitions(${PREFIX_PROJECT_NAME}-${CHAPTER} PUBLIC BUILD_OPTLEVEL_DEV)
    endif()
endif()
