source: git/modules/LexMacros.cmake @ 8cc501

spielwiese
Last change on this file since 8cc501 was 8cc501, checked in by Kai Krüger <krueger@…>, 13 years ago
Added files to compile with cmake. Still experimental. Might not work git-svn-id: file:///usr/local/Singular/svn/trunk@13240 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.1 KB
Line 
1# -*- mode: cmake; -*-
2#
3#
4#
5
6function(add_lex GEN_CPP_FILE INFILE PREFIX)
7  string(REGEX REPLACE "^.*/" "" FILE ${INFILE})
8  string(REPLACE ".l" "" NAME ${FILE})
9
10  set(_GEN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cpp)
11  set(_SOURCE_CPP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.cc)
12
13  message("add_lex ${${GEN_CPP_FILE}} ${INFILE}...")
14
15  if(NOT ${PREFIX} STREQUAL "")
16    set(OPT "-P${PREFIX}")
17    set(_orig ${CMAKE_CURRENT_SOURCE_DIR}/libparse.cc)
18  else(NOT ${PREFIX} STREQUAL "")
19    set(OPT "-s")
20    set(_orig ${CMAKE_CURRENT_SOURCE_DIR}/scanner.cc)
21  endif(NOT ${PREFIX} STREQUAL "")
22
23  add_custom_command(OUTPUT ${_GEN_CPP_FILE}
24    COMMAND ${FLEX} ${OPT} -o ${_GEN_CPP_FILE}.tmp  ${INFILE}
25    #    COMMAND cp ${_SOURCE_CPP_FILE}  ${_GEN_CPP_FILE}
26    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_GEN_CPP_FILE}.tmp ${_GEN_CPP_FILE}
27    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_SOURCE_CPP_FILE} ${_GEN_CPP_FILE}
28    COMMAND ls -l ${_GEN_CPP_FILE}.tmp ${_GEN_CPP_FILE}
29#    COMMAND ls -l ${_GEN_CPP_FILE}.tmp ${_GEN_CPP_FILE} ${_orig}
30     
31    DEPENDS ${INFILE}
32    COMMENT "Compiling '${INFILE}'..."
33    )
34
35  set(${GEN_CPP_FILE} ${_GEN_CPP_FILE} PARENT_SCOPE)
36endfunction()
37
38#
39#
40#
41function(check_lex_version GEN_VERSION)
42  execute_process(COMMAND ${FLEX} --version
43      OUTPUT_VARIABLE CMAKE_FLEX_VERSION)
44  string(REGEX REPLACE "flex ([0-9]+)\\.([0-9]+).*$" "\\1"
45         CMAKE_FLEX_MAJOR ${CMAKE_FLEX_VERSION})
46  string(REGEX REPLACE "flex ([0-9]+)\\.([0-9]+).*" "\\2"
47         CMAKE_FLEX_MINOR ${CMAKE_FLEX_VERSION})
48  string(REGEX REPLACE "flex ([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\3"
49         CMAKE_FLEX_PATCH ${CMAKE_FLEX_VERSION})
50
51   set(_GEN_VERSION 0)
52   if (${CMAKE_FLEX_MAJOR} EQUAL 2 AND ${CMAKE_FLEX_MINOR} EQUAL 5)
53     if(${CMAKE_FLEX_PATCH} GREATER 33)
54       set(_GEN_VERSION 1)
55     endif(${CMAKE_FLEX_PATCH} GREATER 33)
56   endif (${CMAKE_FLEX_MAJOR} EQUAL 2 AND ${CMAKE_FLEX_MINOR} EQUAL 5)
57
58   set(${GEN_VERSION} ${_GEN_VERSION} PARENT_SCOPE)
59   message(STATUS "Flex version '${CMAKE_FLEX_MAJOR}' '${CMAKE_FLEX_MINOR}' '${CMAKE_FLEX_PATCH}' ${_GEN_VERSION}")
60endfunction()
Note: See TracBrowser for help on using the repository browser.