Reputation: 26647
I'm trying to translate a Makefile into CMakeLists.txt.
Makefile which works
fb1-5: fb1-5.l fb1-5.y
bison -d fb1-5.y
flex fb1-5.l
cc -o $@ fb1-5.tab.c lex.yy.c -lfl
CMakeLists.txt attempt
cmake_minimum_required(VERSION 3.7)
project(calc)
set(CMAKE_C_STANDARD 99)
FIND_PACKAGE(BISON REQUIRED)
SET(BisonOutput ${CMAKE_SOURCE_DIR}/parser.c)
IF(BISON_FOUND)
ADD_CUSTOM_COMMAND(
OUTPUT ${BisonOutput}
COMMAND ${BISON_EXECUTABLE}
-d
${CMAKE_SOURCE_DIR}/fb1-5.y
COMMENT "Generating parser.c"
)
ENDIF()
FIND_PACKAGE(FLEX REQUIRED)
SET(FlexOutput ${CMAKE_SOURCE_DIR}/scanner.c)
IF(FLEX_FOUND)
ADD_CUSTOM_COMMAND(
OUTPUT ${FlexOutput}
COMMAND ${FLEX_EXECUTABLE}
${CMAKE_SOURCE_DIR}/fb1-5.l
COMMENT "Generating fb1-5.l"
)
ENDIF()
ADD_LIBRARY(calc ${BisonOutput} ${FlexOutput})
It says it finds bison and flex in clion
-- Found BISON: /usr/bin/bison (found version "3.0.4")
-- Found FLEX: /usr/bin/flex (found version "2.6.0")
But my CMake script won't generate an executable. How should I define "executable" and how can I make the CMake build script work in CLion?
Upvotes: 1
Views: 3332
Reputation: 1698
But my CMake script won't generate an executable. How should I define "executable" and how can I make the CMake build script work in CLion?
I think you should at least do something like this:
add_executable(fb1-5
${BisonOutput}
${FlexOutput}
)
See add_executable.
Upvotes: 3