# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(PANDA_HOST LANGUAGES CXX)

set(PANDA_ROOT ${PANDA_ROOT_SOURCE_DIR})

# ----- Platform definitions ---------------------------------------------------
include(${PANDA_ROOT_SOURCE_DIR}/cmake/Definitions.cmake)

# ----- Template Based Generator -----------------------------------------------
include(${PANDA_ROOT_SOURCE_DIR}/cmake/TemplateBasedGen.cmake)

# ----- Default flags ----------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Default common flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror")

# Additional flags for NORTTI
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")

# ----- Panda CMake functions --------------------------------------------------
include(${PANDA_ROOT_SOURCE_DIR}/cmake/PandaCmakeFunctions.cmake)

# ----- Stubs ------------------------------------------------------------------
if(NOT COMMAND add_check_style)
    function(add_check_style)
        # Stub
    endfunction()
endif()

if(NOT COMMAND panda_add_gtest)
    function(panda_add_gtest)
        # Stub
    endfunction()
endif()

if(NOT COMMAND panda_add_sanitizers)
    function(panda_add_sanitizers)
        # Stub
    endfunction()
endif()

if(NOT COMMAND panda_add_to_clang_tidy)
    function(panda_add_to_clang_tidy)
        #stub
    endfunction()
endif()

# ----- Targets ----------------------------------------------------------------
set(SECUREC_ROOT ${PANDA_THIRD_PARTY_SOURCES_DIR}/securec)
add_subdirectory(${PANDA_THIRD_PARTY_CONFIG_DIR}/securec ${CMAKE_CURRENT_BINARY_DIR}/third_party/libc_sec)

set(MINIZ_ROOT ${PANDA_THIRD_PARTY_SOURCES_DIR}/miniz/amalgamation)
add_subdirectory(${PANDA_THIRD_PARTY_CONFIG_DIR}/miniz ${CMAKE_CURRENT_BINARY_DIR}/third_party/miniz)

add_subdirectory(${PANDA_ROOT_SOURCE_DIR}/isa ${CMAKE_CURRENT_BINARY_DIR}/isa)
add_subdirectory(${PANDA_ROOT_SOURCE_DIR}/libpandabase ${CMAKE_CURRENT_BINARY_DIR}/libpandabase)
add_subdirectory(${PANDA_ROOT_SOURCE_DIR}/libziparchive ${CMAKE_CURRENT_BINARY_DIR}/libziparchive)
add_subdirectory(${PANDA_ROOT_SOURCE_DIR}/libpandafile ${CMAKE_CURRENT_BINARY_DIR}/libpandafile)
add_subdirectory(${PANDA_ROOT_SOURCE_DIR}/assembler ${CMAKE_CURRENT_BINARY_DIR}/assembler)
