Skip to content

Commit 2e6ee66

Browse files
committed
cmake changes to match new behavior of scanner
1 parent 86bf2df commit 2e6ee66

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

cmake/schema_scanner/schemaScanner.cmake

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,29 @@ endif( NOT ${_ss_build_stat} STREQUAL "0" )
5555
# not sure if it makes sense to install this or not...
5656
install( PROGRAMS ${SCANNER_OUT_DIR}/schema_scanner DESTINATION ${BIN_INSTALL_DIR} )
5757

58-
# macro LIST_SCHEMA_FILES
59-
# lists the files created for individual entities or types in the schema,
60-
# but not the schema-level files (i.e. SdaiSCHEMA_NAME.cc)
58+
# macro SCHEMA_CMLIST
59+
# runs the schema scanner on one express file, creating a CMakeLists.txt file for each schema found. Those files are added via add_subdirectory().
6160
#
6261
# SCHEMA_FILE - path to the schema
63-
# OUT_PATH_PREFIX - prefixed to the name of each file; easier while building lists than later
64-
# SCHEMA_NAME_RES - result variable, set to the schema name. if multiple schemas in a file, a semicolon-separated list
65-
# HEADERS_RES - result variable, which will contain a list of generated headers
66-
# IMPLS_RES - result variable, which will contain a list of generated implementation files
67-
MACRO( LIST_SCHEMA_FILES SCHEMA_FILE OUT_PATH_PREFIX SCHEMA_NAME_RES HEADERS_RES IMPLS_RES)
62+
# TODO should we have a result variable to return schema name(s) found?
63+
MACRO( SCHEMA_CMLIST SCHEMA_FILE )
6864
execute_process( COMMAND ${SCANNER_OUT_DIR}/schema_scanner ${SCHEMA_FILE}
6965
WORKING_DIRECTORY ${SC_BINARY_DIR}/schemas
7066
RESULT_VARIABLE _ss_stat
7167
OUTPUT_VARIABLE _ss_out
7268
ERROR_VARIABLE _ss_err
7369
)
74-
if( NOT ${_ss_stat} STREQUAL "0" )
70+
if( NOT "${_ss_stat}" STREQUAL "0" )
7571
#check size of output, put in file if large?
76-
message( FATAL_ERROR "Schema scan exited with error code ${_ss_build_stat}. stdout:\n${_ss_out}\nstderr:\n${_ss_err}" )
77-
endif( NOT ${_ss_stat} STREQUAL "0" )
78-
# scanner output format
79-
# :schema_name:;entity/e_name.h;entity/e_name.cc;type/t_name.h;type/t_name.cc;...;\n
80-
string( STRIP "${_ss_out}" _scan )
81-
foreach( _item ${_scan} )
82-
if( ${_item} MATCHES "^:.*:$" )
83-
#schema name(s) will be wrapped in colons
84-
string(REGEX REPLACE "^:(.*):$" "\\1" _schema ${_item})
85-
list( APPEND ${SCHEMA_NAME_RES} ${_schema} )
86-
elseif( ${_item} MATCHES ".*\\.h$" )
87-
# header
88-
list( APPEND ${HEADERS_RES} ${OUT_PATH_PREFIX}/${_item} )
89-
elseif( ${_item} MATCHES ".*\\.cc$" )
90-
# implementation
91-
list( APPEND ${IMPLS_RES} ${OUT_PATH_PREFIX}/${_item} )
92-
else()
93-
# unknown?!
94-
if( NOT _item STREQUAL "" )
95-
message( FATAL_ERROR "unrecognized item in schema scanner output: '${_item}'. aborting." )
96-
endif( NOT _item STREQUAL "" )
97-
endif( ${_item} MATCHES "^:.*:$" )
98-
endforeach( _item ${_ss_out} )
72+
message( FATAL_ERROR "Schema scan exited with error code ${_ss_stat}. stdout:\n${_ss_out}\nstderr:\n${_ss_err}" )
73+
endif( NOT "${_ss_stat}" STREQUAL "0" )
74+
# scanner output format: each line contains an absolute path. each path is a dir containing a CMakeLists for one schema
75+
# there will be usually be a single line of output, but it is not illegal for multiple schemas to exist in one .exp file
76+
string( STRIP "${_ss_out}" _ss_stripped )
77+
string( REGEX REPLACE "\\\n" ";" _list ${_ss_stripped} )
78+
foreach( _dir ${_list} )
79+
# message( "${SCHEMA_FILE}: ${_dir}" )
80+
add_subdirectory( ${_dir} ${_dir} ) #specify source and binary dirs as the same
81+
endforeach( _dir ${_ss_out} )
9982
configure_file( ${SCHEMA_FILE} ${SCANNER_OUT_DIR}/${_schema} ) #if multiple schemas in one file, _schema is the last one printed.
100-
ENDMACRO( LIST_SCHEMA_FILES SCHEMA_FILE SCHEMA_NAME_RES HEADERS_RES IMPLS_RES)
83+
ENDMACRO( SCHEMA_CMLIST SCHEMA_FILE )

data/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
4848
message( STATUS "Generating code for ${SCHEMA_SHORT_NAME}.")
4949
set( SCHEMA_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_SHORT_NAME} )
5050

51-
LIST_SCHEMA_FILES( ${SCHEMA_FILE} ${SCHEMA_OUTPUT_DIR} SCHEMA_N _headers _impls )
52-
# message("schema ${SCHEMA_FILE}: ${SCHEMA_N}, ${_headers}, ${_impls}" )
51+
SCHEMA_CMLIST( ${SCHEMA_FILE} )
5352

5453
# read the schema name from a line like 'SCHEMA AUTOMOTIVE_DESIGN;'
55-
# file(STRINGS ${SCHEMA_FILE} SCHEMA_STATEMENT LIMIT_COUNT 1 REGEX "^SCHEMA .*")
56-
# string(REGEX REPLACE "^SCHEMA \(.*\)\;$" "\\1" SCHEMA_N ${SCHEMA_STATEMENT} )
54+
file(STRINGS ${SCHEMA_FILE} SCHEMA_STATEMENT LIMIT_COUNT 1 REGEX "^SCHEMA .*")
55+
string(REGEX REPLACE "^SCHEMA \(.*\)\;$" "\\1" SCHEMA_N ${SCHEMA_STATEMENT} )
5756
# TODO handle multiple schemas in SCHEMA_N
5857
string(TOUPPER ${SCHEMA_N} SCHEMA_LONG_NAME) #exp2cxx always uses upper case for file names
5958

6059
#the names of the files that will be generated
6160
set( FEDEX_HEADERS ${SCHEMA_OUTPUT_DIR}/Sdaiclasses.h;${SCHEMA_OUTPUT_DIR}/schema.h;${SCHEMA_OUTPUT_DIR}/Sdai${SCHEMA_LONG_NAME}.h;${_headers} )
62-
set( FEDEX_OUT ${SCHEMA_OUTPUT_DIR}/compstructs.cc;${SCHEMA_OUTPUT_DIR}/schema.cc; ${SCHEMA_OUTPUT_DIR}/Sdai${SCHEMA_LONG_NAME}.cc;${SCHEMA_OUTPUT_DIR}/SdaiAll.cc; ${SCHEMA_OUTPUT_DIR}/Sdai${SCHEMA_LONG_NAME}.init.cc;${_impls};${FEDEX_HEADERS} )
61+
set( FEDEX_OUT ${SCHEMA_OUTPUT_DIR}/compstructs.cc;${SCHEMA_OUTPUT_DIR}/schema.cc;
62+
${SCHEMA_OUTPUT_DIR}/Sdai${SCHEMA_LONG_NAME}.cc;${SCHEMA_OUTPUT_DIR}/SdaiAll.cc;
63+
${SCHEMA_OUTPUT_DIR}/Sdai${SCHEMA_LONG_NAME}.init.cc;${_impls};${FEDEX_HEADERS} )
6364

6465
install( FILES ${FEDEX_HEADERS} DESTINATION include/${SCHEMA_SHORT_NAME} )
6566

0 commit comments

Comments
 (0)