Skip to content

Commit 0fea20a

Browse files
committed
Start building towards an SCL build that can work with or without perplex/re2c/lemon. Fair bit more work to do - these are just the fundamental essentials.
1 parent 42f8870 commit 0fea20a

File tree

11 files changed

+7169
-36
lines changed

11 files changed

+7169
-36
lines changed

cmake/FindLEMON.cmake

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,8 @@
33
# The module defines the following variables
44
#
55
# LEMON_EXECUTABLE - path to the lemon program
6-
# LEMON_FOUND - true if the program was found
7-
#
8-
# If lemon is found, the module defines the macro
9-
# LEMON_TARGET(<Name> <LemonInput> <LemonSource> <LemonHeader>
10-
# [<ArgString>])
11-
# which will create a custom rule to generate a parser. <LemonInput> is
12-
# the path to a lemon file. <LemonSource> is the desired name for the
13-
# generated source file. <LemonHeader> is the desired name for the
14-
# generated header which contains the token list. Anything in the optional
15-
# <ArgString> parameter is appended to the lemon command line.
16-
#
17-
# The macro defines a set of variables:
18-
# LEMON_${Name}_DEFINED - True if the macro ran successfully
19-
# LEMON_${Name}_INPUT - The input source file, an alias for <LemonInput>
20-
# LEMON_${Name}_OUTPUT_SOURCE - The source file generated by lemon, an alias for <LemonSource>
21-
# LEMON_${Name}_OUTPUT_HEADER - The header file generated by lemon, an alias for <LemonHeader>
22-
# LEMON_${Name}_OUTPUTS - All bin outputs
23-
# LEMON_${Name}_EXTRA_ARGS - Arguments added to the lemon command line
24-
#
25-
# ====================================================================
26-
# Example:
27-
#
28-
# find_package(LEMON)
29-
# LEMON_TARGET(MyParser parser.y parser.c parser.h)
30-
# add_executable(Foo main.cpp ${LEMON_MyParser_OUTPUTS})
31-
# ====================================================================
32-
#
6+
# LEMON_TEMPLATE - location of the lemon template file
7+
338
#=============================================================================
349
# F I N D L E M O N . C M A K E
3510
#
@@ -72,9 +47,6 @@
7247
find_program(LEMON_EXECUTABLE lemon DOC "path to the lemon executable")
7348
mark_as_advanced(LEMON_EXECUTABLE)
7449

75-
find_program(MOVE_EXECUTABLE NAMES mv move DOC "path to the move executable")
76-
mark_as_advanced(MOVE_EXECUTABLE)
77-
7850
if(LEMON_EXECUTABLE AND NOT LEMON_TEMPLATE)
7951
get_filename_component(lemon_path ${LEMON_EXECUTABLE} PATH)
8052
if(lemon_path)

cmake/FindPERPLEX.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# - Find perplex executable
3+
#
4+
# PERPLEX_EXECUTABLE - path to the perplex program
5+
# ====================================================================
6+
7+
find_program(PERPLEX_EXECUTABLE perplex DOC "path to the perplex executable")
8+
mark_as_advanced(PERPLEX_EXECUTABLE)
9+
include(FindPackageHandleStandardArgs)
10+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PERPLEX DEFAULT_MSG PERPLEX_EXECUTABLE)

cmake/FindRE2C.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The module defines the following variables:
2+
# RE2C_EXECUTABLE - the path to the re2c executable
3+
#
4+
#=============================================================================
5+
6+
find_program(RE2C_EXECUTABLE re2c DOC "path to the re2c executable")
7+
mark_as_advanced(RE2C_EXECUTABLE)
8+
9+
include(FindPackageHandleStandardArgs)
10+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RE2C DEFAULT_MSG RE2C_EXECUTABLE)

cmake/LEMON_Util.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ macro(LEMON_TARGET Name LemonInput LemonSource LemonHeader)
6464
get_filename_component(LemonInputFull ${LemonInput} ABSOLUTE)
6565
get_filename_component(LemonSourceFull ${LemonSource} ABSOLUTE)
6666
get_filename_component(LemonHeaderFull ${LemonHeader} ABSOLUTE)
67-
67+
6868
if(NOT ${LemonInput} STREQUAL ${LemonInputFull})
6969
set(LEMON_${Name}_INPUT "${CMAKE_CURRENT_BINARY_DIR}/${LemonInput}")
7070
else(NOT ${LemonInput} STREQUAL ${LemonInputFull})

cmake/PERPLEX_Util.cmake

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Defines two macros - PERPLEX_TARGET, which takes perplex inputs and
2+
# runs both perplex and re2c to generate C source code/headers, and
3+
# ADD_PERPLEX_LEMON_DEPENDENCY which is used to set up dependencies between
4+
# scanner and parser targets when necessary.
5+
#
6+
# #====================================================================
7+
# Example:
8+
#
9+
# find_package(LEMON)
10+
# find_package(RE2C)
11+
# find_package(PERPLEX)
12+
#
13+
# LEMON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
14+
# PERPLEX_TARGET(MyScanner scanner.re ${CMAKE_CURRENT_BIANRY_DIR}/scanner.cpp ${CMAKE_CURRENT_BINARY_DIR}/scanner_header.hpp)
15+
# ADD_PERPLEX_LEMON_DEPENDENCY(MyScanner MyParser)
16+
#
17+
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
18+
# add_executable(Foo
19+
# Foo.cc
20+
# ${LEMON_MyParser_OUTPUTS}
21+
# ${PERPLEX_MyScanner_OUTPUTS}
22+
# )
23+
# ====================================================================
24+
#
25+
#=============================================================================
26+
#
27+
# Originally based off of FindBISON.cmake from Kitware's CMake distribution
28+
#
29+
# Copyright (c) 2010-2012 United States Government as represented by
30+
# the U.S. Army Research Laboratory.
31+
# Copyright 2009 Kitware, Inc.
32+
# Copyright 2006 Tristan Carel
33+
# All rights reserved.
34+
#
35+
# Redistribution and use in source and binary forms, with or without
36+
# modification, are permitted provided that the following conditions
37+
# are met:
38+
#
39+
# * Redistributions of source code must retain the above copyright
40+
# notice, this list of conditions and the following disclaimer.
41+
#
42+
# * Redistributions in binary form must reproduce the above copyright
43+
# notice, this list of conditions and the following disclaimer in the
44+
# documentation and/or other materials provided with the distribution.
45+
#
46+
# * The names of the authors may not be used to endorse or promote
47+
# products derived from this software without specific prior written
48+
# permission.
49+
#
50+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61+
#=============================================================================
62+
63+
#============================================================
64+
# PERPLEX_TARGET (public macro)
65+
#============================================================
66+
macro(PERPLEX_TARGET Name Input OutputSrc OutputHeader)
67+
if(${ARGC} GREATER 4)
68+
set(Template ${ARGV4})
69+
else(${ARGC} GREATER 4)
70+
set(Template ${BRLCAD_SOURCE_DIR}/src/other/perplex/scanner_template.c)
71+
endif(${ARGC} GREATER 4)
72+
73+
get_filename_component(OutputName ${OutputSrc} NAME)
74+
set(re2c_src "${CMAKE_CURRENT_BINARY_DIR}/${OutputName}.re")
75+
76+
add_custom_command(
77+
OUTPUT ${re2c_src} ${OutputHeader}
78+
COMMAND ${PERPLEX_EXECUTABLE} -c -o ${re2c_src} -i ${OutputHeader} -t ${Template} ${Input}
79+
DEPENDS ${Input} ${Template} ${PERPLEX_EXECUTABLE_TARGET} ${RE2C_EXECUTABLE_TARGET}
80+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
81+
COMMENT "[PERPLEX][${Name}] Generating re2c input with ${PERPLEX_EXECUTABLE}"
82+
)
83+
add_custom_command(
84+
OUTPUT ${OutputSrc}
85+
COMMAND ${RE2C_EXECUTABLE} -c -o ${OutputSrc} ${re2c_src}
86+
DEPENDS ${Input} ${re2c_src} ${OutputHeader} ${PERPLEX_EXECUTABLE_TARGET} ${RE2C_EXECUTABLE_TARGET}
87+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
88+
COMMENT "[RE2C][${Name}] Building scanner with ${RE2C_EXECUTABLE}"
89+
)
90+
set(PERPLEX_${Name}_DEFINED TRUE)
91+
set(PERPLEX_${Name}_OUTPUTS ${OutputSrc})
92+
set(PERPLEX_${Name}_INPUT ${Input})
93+
endmacro(PERPLEX_TARGET)
94+
95+
#============================================================
96+
# ADD_PERPLEX_LEMON_DEPENDENCY (public macro)
97+
#============================================================
98+
macro(ADD_PERPLEX_LEMON_DEPENDENCY PERPLEXTarget LemonTarget)
99+
100+
if(NOT PERPLEX_${PERPLEXTarget}_OUTPUTS)
101+
message(SEND_ERROR "PERPLEX target `${PERPLEXTarget}' does not exists.")
102+
endif()
103+
104+
if(NOT LEMON_${LemonTarget}_OUTPUT_HEADER)
105+
message(SEND_ERROR "Lemon target `${LemonTarget}' does not exists.")
106+
endif()
107+
108+
set_source_files_properties(${PERPLEX_${PERPLEXTarget}_OUTPUTS}
109+
PROPERTIES OBJECT_DEPENDS ${LEMON_${LemonTarget}_OUTPUT_HEADER})
110+
endmacro(ADD_PERPLEX_LEMON_DEPENDENCY)
111+
112+
#============================================================
113+
# PERPLEX_Utils.cmake ends here
114+
115+
# Local Variables:
116+
# tab-width: 8
117+
# mode: cmake
118+
# indent-tabs-mode: t
119+
# End:
120+
# ex: shiftwidth=2 tabstop=8

cmake/RE2C_Util.cmake

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# F I N D R E 2 C . C M A K E
2+
#
3+
# Provides a macro to generate custom build rules:
4+
5+
# RE2C_TARGET(Name RE2CInput RE2COutput [COMPILE_FLAGS <string>])
6+
# which creates a custom command to generate the <RE2COutput> file from
7+
# the <RE2CInput> file. If COMPILE_FLAGS option is specified, the next
8+
# parameter is added to the re2c command line. Name is an alias used to
9+
# get details of this custom command.
10+
11+
# This module also defines a macro:
12+
# ADD_RE2C_LEMON_DEPENDENCY(RE2CTarget LemonTarget)
13+
# which adds the required dependency between a scanner and a parser
14+
# where <RE2CTarget> and <LemonTarget> are the first parameters of
15+
# respectively RE2C_TARGET and LEMON_TARGET macros.
16+
#
17+
# ====================================================================
18+
# Example:
19+
#
20+
# find_package(LEMON)
21+
# find_package(RE2C)
22+
#
23+
# LEMON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
24+
# RE2C_TARGET(MyScanner scanner.re ${CMAKE_CURRENT_BIANRY_DIR}/scanner.cpp)
25+
# ADD_RE2C_LEMON_DEPENDENCY(MyScanner MyParser)
26+
#
27+
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
28+
# add_executable(Foo
29+
# Foo.cc
30+
# ${LEMON_MyParser_OUTPUTS}
31+
# ${RE2C_MyScanner_OUTPUTS}
32+
# )
33+
# ====================================================================
34+
#
35+
#=============================================================================
36+
# Copyright (c) 2010-2012 United States Government as represented by
37+
# the U.S. Army Research Laboratory.
38+
# Copyright 2009 Kitware, Inc.
39+
# Copyright 2006 Tristan Carel
40+
# All rights reserved.
41+
#
42+
# Redistribution and use in source and binary forms, with or without
43+
# modification, are permitted provided that the following conditions
44+
# are met:
45+
#
46+
# * Redistributions of source code must retain the above copyright
47+
# notice, this list of conditions and the following disclaimer.
48+
#
49+
# * Redistributions in binary form must reproduce the above copyright
50+
# notice, this list of conditions and the following disclaimer in the
51+
# documentation and/or other materials provided with the distribution.
52+
#
53+
# * The names of the authors may not be used to endorse or promote
54+
# products derived from this software without specific prior written
55+
# permission.
56+
#
57+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
58+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
60+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
61+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
63+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
67+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68+
#=============================================================================
69+
70+
#============================================================
71+
# RE2C_TARGET (public macro)
72+
#============================================================
73+
#
74+
macro(RE2C_TARGET Name Input Output)
75+
set(RE2C_TARGET_usage "RE2C_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
76+
if(${ARGC} GREATER 3)
77+
if(${ARGC} EQUAL 5)
78+
if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
79+
set(RE2C_EXECUTABLE_opts "${ARGV4}")
80+
SEPARATE_ARGUMENTS(RE2C_EXECUTABLE_opts)
81+
else()
82+
message(SEND_ERROR ${RE2C_TARGET_usage})
83+
endif()
84+
else()
85+
message(SEND_ERROR ${RE2C_TARGET_usage})
86+
endif()
87+
endif()
88+
89+
add_custom_command(OUTPUT ${Output}
90+
COMMAND ${RE2C_EXECUTABLE}
91+
ARGS ${RE2C_EXECUTABLE_opts} -o${Output} ${Input}
92+
DEPENDS ${Input} ${RE2C_EXECUTABLE_TARGET}
93+
COMMENT "[RE2C][${Name}] Building scanner with ${RE2C_EXECUTABLE}"
94+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
95+
96+
set(RE2C_${Name}_DEFINED TRUE)
97+
set(RE2C_${Name}_OUTPUTS ${Output})
98+
set(RE2C_${Name}_INPUT ${Input})
99+
set(RE2C_${Name}_COMPILE_FLAGS ${RE2C_EXECUTABLE_opts})
100+
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${Output}")
101+
endmacro(RE2C_TARGET)
102+
#============================================================
103+
104+
#============================================================
105+
# ADD_RE2C_LEMON_DEPENDENCY (public macro)
106+
#============================================================
107+
#
108+
macro(ADD_RE2C_LEMON_DEPENDENCY RE2CTarget LemonTarget)
109+
110+
if(NOT RE2C_${RE2CTarget}_OUTPUTS)
111+
message(SEND_ERROR "RE2C target `${RE2CTarget}' does not exists.")
112+
endif()
113+
114+
if(NOT LEMON_${LemonTarget}_OUTPUT_HEADER)
115+
message(SEND_ERROR "Lemon target `${LemonTarget}' does not exists.")
116+
endif()
117+
118+
set_source_files_properties(${RE2C_${RE2CTarget}_OUTPUTS}
119+
PROPERTIES OBJECT_DEPENDS ${LEMON_${LemonTarget}_OUTPUT_HEADER})
120+
endmacro(ADD_RE2C_LEMON_DEPENDENCY)
121+
#============================================================
122+
123+
# RE2C_Util.cmake ends here
124+
125+
# Local Variables:
126+
# tab-width: 8
127+
# mode: cmake
128+
# indent-tabs-mode: t
129+
# End:
130+
# ex: shiftwidth=2 tabstop=8

src/express/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ include_directories(
55
)
66

77
find_package(LEMON)
8-
LEMON_TARGET(ExpParser expparse.y expparse.c expparse.h)
9-
PERPLEX_TARGET(ExpScanner expscan.l ${CMAKE_CURRENT_BINARY_DIR}/expscan.c ${CMAKE_CURRENT_BINARY_DIR}/expscan.h)
10-
ADD_PERPLEX_LEMON_DEPENDENCY(ExpScanner ExpParser)
8+
find_package(PERPLEX)
9+
find_package(RE2C)
10+
if(LEMON_EXECUTABLE AND LEMON_TEMPLATE AND PERPLEX_EXECUTABLE AND RE2C_EXECUTABLE)
11+
include(${SCL_SOURCE_DIR}/cmake/LEMON_Util.cmake)
12+
include(${SCL_SOURCE_DIR}/cmake/RE2C_Util.cmake)
13+
include(${SCL_SOURCE_DIR}/cmake/PERPLEX_Util.cmake)
14+
LEMON_TARGET(ExpParser expparse.y expparse.c expparse.h)
15+
PERPLEX_TARGET(ExpScanner expscan.l ${CMAKE_CURRENT_BINARY_DIR}/expscan.c ${CMAKE_CURRENT_BINARY_DIR}/expscan.h)
16+
ADD_PERPLEX_LEMON_DEPENDENCY(ExpScanner ExpParser)
17+
set(EXPRESS_GENERATED_SRCS
18+
${LEMON_ExpParser_OUTPUT_SOURCE}
19+
${PERPLEX_ExpScanner_OUTPUTS}
20+
)
21+
else(LEMON_EXECUTABLE AND LEMON_TEMPLATE AND PERPLEX_EXECUTABLE AND RE2C_EXECUTABLE)
22+
set(EXPRESS_GENERATED_SRCS
23+
generated/expparse.c
24+
generated/expscan.c
25+
)
26+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/generated)
27+
endif(LEMON_EXECUTABLE AND LEMON_TEMPLATE AND PERPLEX_EXECUTABLE AND RE2C_EXECUTABLE)
1128

1229
set(EXPRESS_SOURCES
13-
${LEMON_ExpParser_OUTPUT_SOURCE}
14-
${PERPLEX_ExpScanner_OUTPUTS}
30+
${EXPRESS_GENERATED_SRCS}
1531
symbol.c
1632
type.c
1733
variable.c

0 commit comments

Comments
 (0)