Files
mysysy/CMakeLists.txt
2025-03-26 11:39:22 +08:00

46 lines
1.5 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.19)
# cmake_policy(SET CMP0135 OLD)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(sysy
VERSION 0.0.0.1
DESCRIPTION "The SysY language compiler"
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
# ========== 修改点 1强制 Debug 模式(调试时使用) ==========
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not set, defaulting to Debug mode for GDB support.")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo." FORCE)
endif()
# ========== 修改点 2确保 Debug 模式生成调试信息 ==========
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Debug mode enabled: Adding -g flag for GDB debugging.")
add_compile_options(-g -O0) # -O0 禁用优化,避免干扰调试
endif()
# Set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# ANTLR
set(ANTLR_EXECUTABLE "${PROJECT_SOURCE_DIR}/antlr/antlr-4.13.2-complete.jar")
set(ANTLR_RUNTIME "${PROJECT_SOURCE_DIR}/antlr/antlr4-runtime-4.13.2")
set(ANTLR4_INSTALL ON)
set(WITH_DEMO OFF)
set(ANTLR_BUILD_CPP_TESTS OFF)
add_subdirectory(${ANTLR_RUNTIME})
# Project source files
add_subdirectory(src)