Re: [CMake] cmake, lex yacc

2007-12-06 Thread Gonzalo Garramuño

Timur Ivanov wrote:

Hello!

Sorry if it was discussed already but I can't find anything really
useful for me.

In current project I use lex  yacc and Makefile rules looks like:



cmake currently does not ship with bison and flex modules, 
unfortunately.  Here's a couple of mine.


--- FindFlex.cmake
# - Try to find Flex
# Once done this will define
#
#  FLEX_FOUND - system has Flex
#  FLEX_EXECUTABLE - path of the flex executable
#  FLEX_VERSION - the version string, like 2.5.31
#


FIND_PROGRAM(FLEX_EXECUTABLE NAMES flex flex.exe )

IF(FLEX_EXECUTABLE)
SET(FLEX_FOUND TRUE)

EXECUTE_PROCESS(COMMAND ${FLEX_EXECUTABLE} --version
OUTPUT_VARIABLE _FLEX_VERSION
)
string (REGEX MATCH [0-9]+\\.[0-9]+\\.[0-9]+ FLEX_VERSION 
${_FLEX_VERSION})

ENDIF(FLEX_EXECUTABLE)

IF(FLEX_FOUND)
  IF(NOT Flex_FIND_QUIETLY)
MESSAGE(STATUS Found Flex: ${FLEX_EXECUTABLE})
  ENDIF(NOT Flex_FIND_QUIETLY)
ELSE(FLEX_FOUND)
  IF(Flex_FIND_REQUIRED)
MESSAGE(FATAL_ERROR Could not find Flex)
  ENDIF(Flex_FIND_REQUIRED)
ENDIF(FLEX_FOUND)
---

 FindBison.cmake
# - Try to find Bison
# Once done this will define
#
#  BISON_FOUND - system has Bison
#  BISON_EXECUTABLE - path of the bison executable
#  BISON_VERSION - the version string, like 2.5.31
#

FIND_PROGRAM(BISON_EXECUTABLE NAMES bison bison.exe )

IF(BISON_EXECUTABLE)
SET(BISON_FOUND TRUE)

EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version
OUTPUT_VARIABLE _BISON_VERSION
)
string (REGEX MATCH [0-9]+\\.[0-9]+\\.[0-9]+ BISON_VERSION 
${_BISON_VERSION})

ENDIF(BISON_EXECUTABLE)

IF(BISON_FOUND)
  IF(NOT Bison_FIND_QUIETLY)
MESSAGE(STATUS Found Bison: ${BISON_EXECUTABLE})
  ENDIF(NOT Bison_FIND_QUIETLY)
ELSE(BISON_FOUND)
  IF(Bison_FIND_REQUIRED)
MESSAGE(FATAL_ERROR Could not find Bison)
  ENDIF(Bison_FIND_REQUIRED)
ENDIF(BISON_FOUND)
--

--- Sample usage


FIND_PACKAGE( Flex  REQUIRED)
FIND_PACKAGE( Bison REQUIRED)

#
# Create custom command for flex/lex (note the outputs)
#
ADD_CUSTOM_COMMAND(
   SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/grammar.lex
   COMMAND ${FLEX_EXECUTABLE}
   ARGS -o${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c
-Pmrl_yy -8 -CFe ${CMAKE_CURRENT_SOURCE_DIR}/grammar.lex
   TARGET miparser
   OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c
   )

#
# Create custom commands for bison/yacc (note the DEPENDS)
#
ADD_CUSTOM_COMMAND(
  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/grammar.y
  COMMAND ${BISON_EXECUTABLE}
  ARGS -l -pmrl_yy  -o${CMAKE_CURRENT_BINARY_DIR}/grammar.tab.cpp
 ${CMAKE_CURRENT_SOURCE_DIR}/grammar.y
  TARGET miparser
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c
  OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/grammar.tab.cpp
)



--
Gonzalo Garramuño
[EMAIL PROTECTED]

AMD4400 - ASUS48N-E
GeForce7300GT
Xubuntu Gutsy
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake, lex yacc

2007-12-06 Thread Gonzalo Garramuño

Gonzalo Garramuño wrote:

Timur Ivanov wrote:

Hello!

Sorry if it was discussed already but I can't find anything really
useful for me.

In current project I use lex  yacc and Makefile rules looks like:



cmake currently does not ship with bison and flex modules, 
unfortunately.  Here's a couple of mine.




Silly me replying to a year old thread...  apologies to all.


--
Gonzalo Garramuño
[EMAIL PROTECTED]

AMD4400 - ASUS48N-E
GeForce7300GT
Xubuntu Gutsy
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


[CMake] cmake, lex yacc

2007-07-30 Thread Timur Ivanov
Hello!

Sorry if it was discussed already but I can't find anything really
useful for me.

In current project I use lex  yacc and Makefile rules looks like:

YACC=bison
LEX=flex

config_yacc.c: config_yacc.y config.h
$(YACC) -d -o config_yacc.c config_yacc.y

config_lex.c: config_lex.l config_yacc.c
$(LEX) -oconfig_lex.c config_lex.l

then compile config_yacc.c and config_lex.c

Now I want to port all of that to cmake but can't find how to express
dependences for yacc and lex sources, that is if .y or .l file changes
proper .c file will be regenerated by yacc or lex.
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake, lex yacc

2007-07-30 Thread James Bigler

Hi,

Timur Ivanov wrote:

Hello!

Sorry if it was discussed already but I can't find anything really
useful for me.


There have been several posts about this to the mailing list.  Did you search 
the archives?  Here are a couple of posts.


http://public.kitware.com/pipermail/cmake/2007-May/014077.html
http://www.cmake.org/pipermail/cmake/2002-September/003028.html

James

___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake, lex yacc

2007-07-30 Thread Tristan Carel
On 7/30/07, Timur Ivanov [EMAIL PROTECTED] wrote:
 Hello!

 Sorry if it was discussed already but I can't find anything really
 useful for me.

 In current project I use lex  yacc and Makefile rules looks like:

 YACC=bison
 LEX=flex

 config_yacc.c: config_yacc.y config.h
 $(YACC) -d -o config_yacc.c config_yacc.y

 config_lex.c: config_lex.l config_yacc.c
 $(LEX) -oconfig_lex.c config_lex.l

 then compile config_yacc.c and config_lex.c

 Now I want to port all of that to cmake but can't find how to express
 dependences for yacc and lex sources, that is if .y or .l file changes
 proper .c file will be regenerated by yacc or lex.

You can find 2 modules `FindBison.cmake' and `FindFlex.cmake' on the
CMake bug tracker that have not been integrated yet.

http://www.cmake.org/Bug/bug.php?op=showbugid=4018pos=3

These 2 modules provide the necessary to find the tools on the system
(location, version) and very easily create custom targets thanks to
the macros FLEX_TARGET and BISON_TARGET. They support a set of options
to pass additional flags, or to generate a `verbose output file' to
debug conflicts.
Another macro named `ADD_FLEX_BISON_DEPENDENCY' can be used when a
Flex scanner uses tokens defined by Bison where in this case the
scanner depends on the header file generated by Bison.

These modules have been tested on many systems, but by only one developer.

Hope this help.
-- 
Tristan Carel
Music with dinner is an insult both to the cook and the violinist.
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] cmake, lex yacc

2007-07-30 Thread Maik Beckmann
Am Montag, 30. Juli 2007 16:46:44 schrieb Timur Ivanov:
 YACC=bison
 LEX=flex

 config_yacc.c: config_yacc.y config.h
 $(YACC) -d -o config_yacc.c config_yacc.y

 config_lex.c: config_lex.l config_yacc.c
 $(LEX) -oconfig_lex.c config_lex.l


CMakeLists.txt
project(parsing_foo)

find_program(LEX_EXE
flex
)
if(LEX_EXE STREQUAL LEX_EXE-NOTFOUND)
message(FATAL_ERROR dear user, plase install flex!)
endif(LEX_EXE STREQUAL LEX_EXE-NOTFOUND)

find_program(YACC_EXE
bison
)
if(YACC_EXE STREQUAL YACC_EXE-NOTFOUND)
message(FATAL_ERROR dear user, plase install bison!)
endif(YACC_EXE STREQUAL YACC_EXE-NOTFOUND)

# reuseable cmake macro for yacc
MACRO(YACC_FILE _filename)
GET_FILENAME_COMPONENT(_basename ${_filename} NAME_WE)
ADD_CUSTOM_COMMAND(
OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.c
${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h
COMMAND ${YACC_EXE} -d
--output=${_basename}.c
${CMAKE_CURRENT_SOURCE_DIR}/${_filename}
DEPENDS ${_filename}
)
ENDMACRO(YACC_FILE)

# reuseable cmake macro for lex
MACRO(LEX_FILE _filename)
GET_FILENAME_COMPONENT(_basename ${_filename} NAME_WE)
ADD_CUSTOM_COMMAND(
OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.c
COMMAND ${LEX_EXE}
-o${_basename}.c
${CMAKE_CURRENT_SOURCE_DIR}/${_filename}
DEPENDS ${_filename} )
ENDMACRO(LEX_FILE)

YACC_FILE(config_yacc.y)
LEX_FILE(config_lex.l)

add_executable(my_parsing_exe
... # whatever
config_yacc.c
config_lex.c
)

# just one more parsing executable
YACC_FILE(xyz_yacc.y)
LEX_FILE(xyz_lex.l)

add_executable(xyz_parsing_exe
... # whatever
xyz_yacc.c
xyz_lex.c
)
/CMakeLists.txt


HTH, Maik Beckmann
___
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake