@@ -55,46 +55,29 @@ endif( NOT ${_ss_build_stat} STREQUAL "0" )
5555# not sure if it makes sense to install this or not...
5656install ( 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} \n stderr:\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} \n stderr:\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 )
0 commit comments