如何将 .h 文件添加到 CMake 中的 flex 定义

How to add a .h file to a flex definition in CMake

所以我想在 Clion 的项目中使用 flex(因为我在 windows),它使用 CMake 但我无法编译,因为我的 lexer.l 文件包含 token.h 我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

find_package(FLEX)

FLEX_TARGET(MyScanner lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(lexer token.h ${FLEX_MyScanner_OUTPUTS}
         printtoken.c lexan.h lexanl.c )

错误:

[ 16%] Building C object CMakeFiles/lexer.dir/lex.yy.c.o
lexan.l:36:10: fatal error: token.h: No such file or directory
compilation terminated.
CMakeFiles/lexer.dir/build.make:74: recipe for target 'CMakeFiles/lexer.dir/lex.yy.c.o' failed

如何添加 token.h?

已解决的问题:

我必须将 ${CMAKE_SOURCE_DIR} 添加到 include_directories() 调用中才能找到头文件。