|
| 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 |
0 commit comments