cmake_minimum_required(VERSION 3.17)
project(MBARI-CPF
	VERSION 0.1
	LANGUAGES C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)

# There's a construct used in one of the files that is fine
# in GCC, since it's a GCC extension, but doesn't work in
# MSVC until C++20. But the ARM GCC compiler doesn't seem to
# build fully with C++20 at this moment. For expediency, MSVC
# test build will use C++20.
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#################
# Build Modules #
#################

if(CPF_TESTING_IS_ENABLED)
    include(CTest)
endif()

# Define and Process Project Options
include(BuildOptions.cmake)

# Dependency manager
include(cmake/CPM.cmake)
# Improved functions for checking compiler/linker flag support
include(cmake/compiler/CheckAndApplyFlags.cmake)
# Adds a function for generating a linker map
include(cmake/linker/map.cmake)
# Overrides add_executable so that linker script dependencies are registered automatically
include(cmake/linker/AddExecutableWithLinkerScriptDep.cmake)
# Provides functions to convert ELF files into .bin and .hex
include(cmake/Conversions.cmake)
# Enable code coverage analysis support
include(cmake/analysis/coverage.cmake)
# Enable code sanitizer build support
include(cmake/analysis/sanitizers.cmake)

# Specifies default compiler flags for the project
include(cmake/compiler/DefaultCompilerSettings.cmake)
# Specifies default linker flags for the project
include(cmake/linker/DefaultLinkerSettings.cmake)

# Define Packaging Rules
include(Packaging.cmake)

#########################
# External Dependencies #
#########################

add_subdirectory(external)

#######################
# Process Source Tree #
#######################

add_subdirectory(CPF)

##########################
# Enable Static Analysis #
##########################

set(CPPCHECK_DIRS CPF)

# Provides cppcheck targets and an option to compile with cppcheck analysis
include(cmake/analysis/cppcheck.cmake)
# Provides clang-tidy targets and and option to compile with clang-tidy analysis
include(cmake/analysis/clang-tidy.cmake)

###################
# Tooling Targets #
###################

set(CLANG_FORMAT_DIRS CPF)

# Provides clang-format build targets
include(cmake/format/clang-format.cmake)
# Provides complexity analysis targets
include(cmake/analysis/complexity.cmake)
# Defines code coverage analysis targets
enable_coverage_targets(MYPROJECT_tests)
# Provides Doxygen documentation generation target
include(cmake/documentation/doxygen.cmake)
# Provides SLOCCount targets
include(cmake/analysis/sloccount.cmake)
# Provides vale documentation linting target
include(cmake/analysis/vale.cmake)
