Skip to content

Commit 256bf1e

Browse files
starseekermpictor
authored andcommitted
We should have a working autotools build with the step tweaks now - make trunk step directory match that from CMake. Since there is no previous CMake build for the step subdirectory, go ahead and put everything here.
git-svn-id: https://brlcad.svn.sourceforge.net/svnroot/brlcad/brlcad/trunk/src/other/step@43254 2f96ce8b-6d43-0410-b8df-bffccc660ffb
1 parent 1ad794f commit 256bf1e

33 files changed

+1172
-73
lines changed

CMake/CheckCFileRuns.cmake

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# - Check if the given C source code compiles and runs.
2+
# CHECK_C_SOURCE_RUNS(<code> <var>)
3+
# <code> - source code to try to compile
4+
# <var> - variable to store the result
5+
# (1 for success, empty for failure)
6+
# The following variables may be set before calling this macro to
7+
# modify the way the check is run:
8+
#
9+
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
10+
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
11+
# CMAKE_REQUIRED_INCLUDES = list of include directories
12+
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
13+
14+
#=============================================================================
15+
# Copyright 2006-2009 Kitware, Inc.
16+
#
17+
# Distributed under the OSI-approved BSD License (the "License");
18+
# see accompanying file Copyright.txt for details.
19+
#
20+
# This software is distributed WITHOUT ANY WARRANTY; without even the
21+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22+
# See the License for more information.
23+
#=============================================================================
24+
# (To distributed this file outside of CMake, substitute the full
25+
# License text for the above reference.)
26+
27+
MACRO(CHECK_C_FILE_RUNS SOURCE VAR)
28+
IF("${VAR}" MATCHES "^${VAR}$")
29+
SET(MACRO_CHECK_FUNCTION_DEFINITIONS
30+
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
31+
IF(CMAKE_REQUIRED_LIBRARIES)
32+
SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
33+
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
34+
ELSE(CMAKE_REQUIRED_LIBRARIES)
35+
SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
36+
ENDIF(CMAKE_REQUIRED_LIBRARIES)
37+
IF(CMAKE_REQUIRED_INCLUDES)
38+
SET(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
39+
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
40+
ELSE(CMAKE_REQUIRED_INCLUDES)
41+
SET(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
42+
ENDIF(CMAKE_REQUIRED_INCLUDES)
43+
44+
MESSAGE(STATUS "Performing Test ${VAR}")
45+
TRY_RUN(${VAR}_EXITCODE ${VAR}_COMPILED
46+
${CMAKE_BINARY_DIR}
47+
${SOURCE}
48+
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${FILE_RUN_DEFINITIONS}
49+
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
50+
-DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
51+
"${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}"
52+
"${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
53+
COMPILE_OUTPUT_VARIABLE OUTPUT)
54+
# if it did not compile make the return value fail code of 1
55+
IF(NOT ${VAR}_COMPILED)
56+
SET(${VAR}_EXITCODE 1)
57+
ENDIF(NOT ${VAR}_COMPILED)
58+
# if the return value was 0 then it worked
59+
IF("${${VAR}_EXITCODE}" EQUAL 0)
60+
SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
61+
MESSAGE(STATUS "Performing Test ${VAR} - Success")
62+
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
63+
"Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n"
64+
"${OUTPUT}\n"
65+
"Return value: ${${VAR}}\n"
66+
"Source file was:\n${SOURCE}\n")
67+
ELSE("${${VAR}_EXITCODE}" EQUAL 0)
68+
IF(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
69+
SET(${VAR} "${${VAR}_EXITCODE}")
70+
ELSE(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
71+
SET(${VAR} "" CACHE INTERNAL "Test ${VAR}")
72+
ENDIF(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN")
73+
74+
MESSAGE(STATUS "Performing Test ${VAR} - Failed")
75+
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
76+
"Performing C SOURCE FILE Test ${VAR} failed with the following output:\n"
77+
"${OUTPUT}\n"
78+
"Return value: ${${VAR}_EXITCODE}\n"
79+
"Source file was:\n${SOURCE}\n")
80+
81+
ENDIF("${${VAR}_EXITCODE}" EQUAL 0)
82+
ENDIF("${VAR}" MATCHES "^${VAR}$")
83+
ENDMACRO(CHECK_C_FILE_RUNS)
84+

CMake/FindLEX.cmake

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# - Find lex executable and provides a macro to generate custom build rules
2+
#
3+
# The module defines the following variables:
4+
# LEX_FOUND - true is lex executable is found
5+
# LEX_EXECUTABLE - the path to the lex executable
6+
# LEX_LIBRARIES - The lex libraries
7+
#
8+
# If lex is found on the system, the module provides the macro:
9+
# LEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <string>])
10+
# which creates a custom command to generate the <FlexOutput> file from
11+
# the <FlexInput> file. If COMPILE_FLAGS option is specified, the next
12+
# parameter is added to the lex command line. Name is an alias used to
13+
# get details of this custom command. Indeed the macro defines the
14+
# following variables:
15+
# LEX_${Name}_DEFINED - true is the macro ran successfully
16+
# LEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
17+
# alias for FlexOutput
18+
# LEX_${Name}_INPUT - the lex source file, an alias for ${FlexInput}
19+
#
20+
# Flex scanners oftenly use tokens defined by Yacc: the code generated
21+
# by Flex depends of the header generated by Yacc. This module also
22+
# defines a macro:
23+
# ADD_LEX_YACC_DEPENDENCY(FlexTarget YaccTarget)
24+
# which adds the required dependency between a scanner and a parser
25+
# where <FlexTarget> and <YaccTarget> are the first parameters of
26+
# respectively LEX_TARGET and YACC_TARGET macros.
27+
#
28+
# ====================================================================
29+
# Example:
30+
#
31+
# find_package(YACC)
32+
# find_package(LEX)
33+
#
34+
# YACC_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
35+
# LEX_TARGET(MyScanner lexer.l ${CMAKE_CURRENT_BIANRY_DIR}/lexer.cpp)
36+
# ADD_LEX_YACC_DEPENDENCY(MyScanner MyParser)
37+
#
38+
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
39+
# add_executable(Foo
40+
# Foo.cc
41+
# ${YACC_MyParser_OUTPUTS}
42+
# ${LEX_MyScanner_OUTPUTS}
43+
# )
44+
# ====================================================================
45+
#
46+
#=============================================================================
47+
# Copyright 2010 United States Government as represented by
48+
# the U.S. Army Research Laboratory.
49+
# Copyright 2009 Kitware, Inc.
50+
# Copyright 2006 Tristan Carel
51+
# All rights reserved.
52+
#
53+
# Redistribution and use in source and binary forms, with or without
54+
# modification, are permitted provided that the following conditions
55+
# are met:
56+
#
57+
# * Redistributions of source code must retain the above copyright
58+
# notice, this list of conditions and the following disclaimer.
59+
#
60+
# * Redistributions in binary form must reproduce the above copyright
61+
# notice, this list of conditions and the following disclaimer in the
62+
# documentation and/or other materials provided with the distribution.
63+
#
64+
# * The names of the authors may not be used to endorse or promote
65+
# products derived from this software without specific prior written
66+
# permission.
67+
#
68+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
69+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
70+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
71+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
72+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
75+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
76+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
78+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79+
#=============================================================================
80+
81+
FIND_PROGRAM(LEX_EXECUTABLE flex DOC "path to the lex executable")
82+
IF(NOT LEX_EXECUTABLE)
83+
FIND_PROGRAM(LEX_EXECUTABLE lex DOC "path to the lex executable")
84+
ENDIF(NOT LEX_EXECUTABLE)
85+
MARK_AS_ADVANCED(LEX_EXECUTABLE)
86+
87+
FIND_LIBRARY(FL_LIBRARY NAMES fl
88+
DOC "path to the fl library")
89+
MARK_AS_ADVANCED(FL_LIBRARY)
90+
SET(LEX_LIBRARIES ${FL_LIBRARY})
91+
92+
IF(LEX_EXECUTABLE)
93+
94+
#============================================================
95+
# LEX_TARGET (public macro)
96+
#============================================================
97+
#
98+
MACRO(LEX_TARGET Name Input Output)
99+
SET(LEX_TARGET_usage "LEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
100+
IF(${ARGC} GREATER 3)
101+
IF(${ARGC} EQUAL 5)
102+
IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")
103+
SET(LEX_EXECUTABLE_opts "${ARGV4}")
104+
SEPARATE_ARGUMENTS(LEX_EXECUTABLE_opts)
105+
ELSE()
106+
MESSAGE(SEND_ERROR ${LEX_TARGET_usage})
107+
ENDIF()
108+
ELSE()
109+
MESSAGE(SEND_ERROR ${LEX_TARGET_usage})
110+
ENDIF()
111+
ENDIF()
112+
113+
ADD_CUSTOM_COMMAND(OUTPUT ${Output}
114+
COMMAND ${LEX_EXECUTABLE}
115+
ARGS ${LEX_EXECUTABLE_opts} -o${Output} ${Input}
116+
DEPENDS ${Input}
117+
COMMENT "[LEX][${Name}] Building scanner with ${LEX_EXECUTABLE}"
118+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
119+
120+
SET(LEX_${Name}_DEFINED TRUE)
121+
SET(LEX_${Name}_OUTPUTS ${Output})
122+
SET(LEX_${Name}_INPUT ${Input})
123+
SET(LEX_${Name}_COMPILE_FLAGS ${LEX_EXECUTABLE_opts})
124+
ENDMACRO(LEX_TARGET)
125+
#============================================================
126+
127+
128+
#============================================================
129+
# ADD_LEX_YACC_DEPENDENCY (public macro)
130+
#============================================================
131+
#
132+
MACRO(ADD_LEX_YACC_DEPENDENCY FlexTarget YaccTarget)
133+
134+
IF(NOT LEX_${FlexTarget}_OUTPUTS)
135+
MESSAGE(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
136+
ENDIF()
137+
138+
IF(NOT YACC_${YaccTarget}_OUTPUT_HEADER)
139+
MESSAGE(SEND_ERROR "Yacc target `${YaccTarget}' does not exists.")
140+
ENDIF()
141+
142+
SET_SOURCE_FILES_PROPERTIES(${LEX_${FlexTarget}_OUTPUTS}
143+
PROPERTIES OBJECT_DEPENDS ${YACC_${YaccTarget}_OUTPUT_HEADER})
144+
ENDMACRO(ADD_LEX_YACC_DEPENDENCY)
145+
#============================================================
146+
147+
#Need to run a test lex file to determine if YYTEXT_POINTER needs
148+
#to be defined
149+
EXEC_PROGRAM(${LEX_EXECUTABLE} ARGS ${CMAKE_SOURCE_DIR}/misc/CMake/test_srcs/lex_test.l -o ${CMAKE_BINARY_DIR}/CMakeTmp/lex_test.c RETURN_VALUE _retval OUTPUT_VARIABLE _lexOut)
150+
INCLUDE (CheckCFileRuns)
151+
SET(FILE_RUN_DEFINITIONS "-DYYTEXT_POINTER=1")
152+
CHECK_C_FILE_RUNS(${CMAKE_CURRENT_SOURCE_DIR}/CMake/test_srcs/sys_wait_test.c YYTEXT_POINTER)
153+
SET(FILE_RUN_DEFINITIONS)
154+
IF(CONFIG_H_FILE)
155+
FILE(APPEND ${CONFIG_H_FILE} "#cmakedefine YYTEXT_POINTER 1\n")
156+
ENDIF(CONFIG_H_FILE)
157+
158+
159+
ENDIF(LEX_EXECUTABLE)
160+
161+
INCLUDE(FindPackageHandleStandardArgs)
162+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LEX DEFAULT_MSG LEX_EXECUTABLE)
163+
164+
# FindLEX.cmake ends here

0 commit comments

Comments
 (0)