Files
nudt-compiler-cpp/CMakeLists.txt

50 lines
1.6 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
cmake_minimum_required(VERSION 3.20)
project(compiler LANGUAGES C CXX)
# 统一 C++ 标准(按实验环境可调整)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ANTLR 生成代码目录约定(不进仓库,生成在构建目录)
set(ANTLR4_GENERATED_DIR "${CMAKE_BINARY_DIR}/generated/antlr4")
# 统一的编译/包含目录选项(子模块复用)
add_library(build_options INTERFACE)
target_compile_features(build_options INTERFACE cxx_std_17)
target_include_directories(build_options INTERFACE
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${ANTLR4_GENERATED_DIR}"
)
option(COMPILER_ENABLE_WARNINGS "Enable common compiler warnings" ON)
if(COMPILER_ENABLE_WARNINGS)
if(MSVC)
target_compile_options(build_options INTERFACE /W4)
else()
target_compile_options(build_options INTERFACE -Wall -Wextra -Wpedantic)
endif()
endif()
# 尝试查找系统 ANTLR4 runtime找不到则提供占位 target便于先配置工程
find_package(antlr4-runtime CONFIG QUIET)
set(ANTLR4_RUNTIME_TARGET "")
if(TARGET antlr4_shared)
set(ANTLR4_RUNTIME_TARGET antlr4_shared)
elseif(TARGET antlr4_static)
set(ANTLR4_RUNTIME_TARGET antlr4_static)
elseif(TARGET antlr4-runtime)
set(ANTLR4_RUNTIME_TARGET antlr4-runtime)
endif()
if(ANTLR4_RUNTIME_TARGET STREQUAL "")
add_library(antlr4_runtime_fallback INTERFACE)
set(ANTLR4_RUNTIME_TARGET antlr4_runtime_fallback)
message(STATUS "antlr4-runtime 未找到:将以占位 target 配置工程;需要 ANTLR 功能时请安装/引入 antlr4-runtime。")
endif()
add_subdirectory(src)