THSS-DB / TDB

Educational Database Management System for Software School of Tsinghua University
Mulan Permissive Software License, Version 2
13 stars 17 forks source link

CMAKE_CXX_FLAGS not correctly set in CMakeLists.txt #18

Closed hotwords123 closed 3 months ago

hotwords123 commented 4 months ago

在项目根目录下的 CMakeLists.txt 中,先使用了 add_subdirectory 添加子目录,然后才将 CMAKE_CXX_FLAGS 设置为 CMAKE_COMMON_FLAGS 的值,相关代码如下:

https://github.com/THSS-DB/TDB/blob/a4537c07cd8cb37c599f34b8c74e7e3fb2657eb4/CMakeLists.txt#L95-L109

本地测试时(cmake 版本为 3.29.3),开启 verbose 选项构建发现 CMAKE_CXX_FLAGS 并没有被应用到编译过程中,查看 build/src/server/CMakeFiles/server.dir/flags.make 也发现 CXX_FLAGS 仅为 -g -std=gnu++2a,但 configure 时的输出为

CMAKE_CXX_FLAGS is  -Wall -Werror  -O0 -g -DDEBUG  -fno-omit-frame-pointer -fsanitize=address -fprofile-arcs -ftest-coverage

如果把 SET(CMAKE_CXX_FLAGS ${CMAKE_COMMON_FLAGS}) 移到 add_subdirectory 前面,这些 flags 就能被正常传入编译过程中。因此可以推测,只有在 add_subdirectory 之前设置的 CMAKE_CXX_FLAGS 才能对子文件夹中的 target 正常生效。从 CMakeLists.txt 的编写逻辑上看,目前观察到的构建过程应该不是预期的行为。

这些编译开关的缺失导致了一些问题:

不过直接应用这些编译开关也有一些问题(更严格说来应该是现有代码的问题):

感觉 codebase 比较庞大,处理这个问题有点棘手……

hotwords123 commented 4 months ago

相关问题在 #19 中修复了一些,#17 中提到的还没有改,可能需要讨论一下修改方法。

RkGrit commented 4 months ago

你说的是对的,这些问题确实存在,可以提一个pr修复一下,最晚会在明年的lab中更新这部分

hotwords123 commented 4 months ago

大部分找到的 bug 和内存泄漏问题已经在 #19 中提交了,麻烦助教再检查一下,辛苦了!

RkGrit commented 3 months ago

检查了没啥问题👍🏻