Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions cmake/SC_CXX_schema_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,35 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
# schema scanner comes up with a short schema name for PROJECT() (which sets ${PROJECT_NAME})
message(STATUS "Will generate ${${PROJECT_NAME}_file_count} C++ files for ${PROJECT_NAME}.")

add_custom_target(generate_cpp_${PROJECT_NAME} DEPENDS exp2cxx ${expFile} ${sourceFiles} SOURCES ${sourceFiles})
set(_schema_generated_files)
foreach(_schema_source ${sourceFiles})
list(APPEND _schema_generated_files "${CMAKE_CURRENT_SOURCE_DIR}/${_schema_source}")
endforeach()
add_custom_target(generate_cpp_${PROJECT_NAME} DEPENDS exp2cxx ${expFile} ${_schema_generated_files} SOURCES ${_schema_generated_files})
# this calls a cmake script because it doesn't seem to be possible
# to divert stdout, stderr in cmake except via execute_process
add_custom_command(OUTPUT ${sourceFiles}
add_custom_command(OUTPUT ${_schema_generated_files}
COMMAND ${CMAKE_COMMAND} -DEXE=\"$<TARGET_FILE:exp2cxx>\" -DEXP=\"${expFile}\"
-DONESHOT=\"${SC_GENERATE_CXX_ONESHOT}\" -DSDIR=\"${CMAKE_CURRENT_LIST_DIR}\"
-DCHUNK_SIZE=\"${SC_EXP2CXX_CHUNK_SIZE}\"
-P ${SC_CMAKE_DIR}/SC_Run_exp2cxx.cmake
DEPENDS exp2cxx ${expFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMENT "[exp2cxx] Generating ${${PROJECT_NAME}_file_count} C++ files for ${PROJECT_NAME}."
)
include_directories(
set(_schema_include_dirs
${CMAKE_CURRENT_SOURCE_DIR} ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor
${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/cllazyfile
${SC_SOURCE_DIR}/src/cllazyfile/judy/src
)
# Schema libraries should be installed by default
if(BUILD_SHARED_LIBS)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${_schema_generated_files} LINK_LIBRARIES stepdai stepcore stepeditor steputils)
add_dependencies(${PROJECT_NAME} generate_cpp_${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${_schema_include_dirs})
if(${PROJECT_NAME}_unity_build)
target_compile_definitions(${PROJECT_NAME} PRIVATE SC_SDAI_UNITY_BUILD)
endif()
if(WIN32)
target_compile_definitions("${PROJECT_NAME}" PRIVATE SC_SCHEMA_DLL_EXPORTS)
if(MSVC)
Expand All @@ -123,9 +133,13 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
endif()

if(BUILD_STATIC_LIBS)
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepcore-static stepdai-static stepeditor-static steputils-static)
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${_schema_generated_files} LINK_LIBRARIES stepcore-static stepdai-static stepeditor-static steputils-static)
add_dependencies(${PROJECT_NAME}-static generate_cpp_${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${_schema_include_dirs})
target_compile_definitions("${PROJECT_NAME}-static" PRIVATE SC_STATIC)
if(${PROJECT_NAME}_unity_build)
target_compile_definitions(${PROJECT_NAME}-static PRIVATE SC_SDAI_UNITY_BUILD)
endif()
if(MSVC)
target_compile_options("${PROJECT_NAME}-static" PRIVATE "/bigobj")
endif()
Expand All @@ -145,4 +159,3 @@ endmacro(SCHEMA_TARGETS expFile schemaName sourceFiles)
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

3 changes: 1 addition & 2 deletions cmake/SC_Run_exp2cxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(ONESHOT AND EXISTS "${SDIR}/schema.cc")
message("WARNING: SC_GENERATE_CXX_ONESHOT is enabled. If generated code has been modified, it will NOT be rewritten!")
message("This is ONLY for debugging STEPcode internals!")
else()
execute_process(COMMAND ${EXE} ${EXP}
execute_process(COMMAND ${EXE} -k ${CHUNK_SIZE} ${EXP}
WORKING_DIRECTORY ${SDIR}
RESULT_VARIABLE _res
OUTPUT_FILE exp2cxx_stdout.txt
Expand All @@ -22,4 +22,3 @@ endif()
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

9 changes: 8 additions & 1 deletion cmake/SC_Targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ macro(SC_ADDEXEC execname)
message(SEND_ERROR "SC_ADDEXEC usage error - expected STATIC LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Executables consume their dependencies but do not publish an
# interface to downstream targets.
target_link_libraries(${execname} PRIVATE ${_lib})
endforeach()
target_link_libraries(${execname} PRIVATE ${${_arg_prefix}_LINK_LIBRARIES})
endif()
Expand Down Expand Up @@ -74,6 +77,11 @@ macro(SC_ADDLIB _addlib_target)
message(SEND_ERROR "SC_ADDLIB usage error - expected (static) LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Schema libraries are consumed directly by generated test programs.
# Publish their link requirements explicitly; the legacy unscoped
# signature does not reliably provide a transitive interface with
# current CMake versions.
target_link_libraries(${_addlib_target} PUBLIC ${_lib})
endforeach()
target_link_libraries(${_addlib_target} ${_lib})
endif()
Expand All @@ -93,4 +101,3 @@ endmacro()
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

65 changes: 56 additions & 9 deletions cmake/schema_scanner/schemaScanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern "C" {
#endif
}

#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
Expand All @@ -50,6 +51,35 @@ using std::ofstream;
using std::cerr;
using std::cout;

static unsigned long entityChunkSize = 256;
static unsigned long typeChunkSize = 256;

static bool
parseChunkSizes( const char * value )
{
if( !value || !value[0] ) {
return false;
}
char * end = 0;
const unsigned long entities = strtoul( value, &end, 10 );
if( !end || entities == 0 ) {
return false;
}
unsigned long types = entities;
if( *end == ':' ) {
char * typeEnd = 0;
types = strtoul( end + 1, &typeEnd, 10 );
if( !end[1] || !typeEnd || *typeEnd || types == 0 ) {
return false;
}
} else if( *end ) {
return false;
}
entityChunkSize = entities;
typeChunkSize = types;
return true;
}

/** \return true for types that exp2cxx won't generate code for */
bool notGenerated( const Type t ) {
switch( TYPEget_body( t )->type ) {
Expand Down Expand Up @@ -186,8 +216,10 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists << "# targets, logic, etc are within a set of macros shared by all schemas" << endl;
cmLists << "include(${SC_CMAKE_DIR}/SC_CXX_schema_macros.cmake)" << endl;

// * 2 for headers, + 10 other files
cmLists << "set(" << shortName << "_file_count " << ( ( ecount + tcount ) * 2 ) + 10 << ")" << endl << endl;
const int entityChunks = std::max( 1, ( ecount + static_cast<int>( entityChunkSize ) - 1 ) / static_cast<int>( entityChunkSize ) );
const int typeChunks = std::max( 1, ( tcount + static_cast<int>( typeChunkSize ) - 1 ) / static_cast<int>( typeChunkSize ) );
cmLists << "set(" << shortName << "_file_count " <<
( ecount + tcount ) * 2 + entityChunks + typeChunks + 11 << ")" << endl << endl;


cmLists << "PROJECT(" << shortName << ")" << endl;
Expand Down Expand Up @@ -224,10 +256,20 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,

cmLists << "# unity build: #include small .cc files to reduce the number" << endl;
cmLists << "# of translation units that must be compiled" << endl;
cmLists << "if(SC_UNITY_BUILD)" << endl << " # turns off include statements within type and entity .cc's - the unity T.U.'s include a unity header" << endl;
cmLists << " add_definitions( -DSC_SDAI_UNITY_BUILD)" << endl;
cmLists << " set(" << shortName << "_entity_impls Sdai" << schema_upper << "_unity_entities.cc)" << endl;
cmLists << " set(" << shortName << "_type_impls Sdai" << schema_upper << "_unity_types.cc)" << endl;
cmLists << "if(SC_UNITY_BUILD)" << endl << " # bounded unity chunks; definitions are target-local" << endl;
cmLists << " set(" << shortName << "_unity_build TRUE)" << endl;
cmLists << " set(" << shortName << "_entity_impls" << endl;
for( int chunk = 1; chunk <= entityChunks; ++chunk ) {
cmLists << " Sdai" << schema_upper << "_unity_entities_" <<
std::setfill( '0' ) << std::setw( 4 ) << chunk << ".cc" << endl;
}
cmLists << " )" << endl;
cmLists << " set(" << shortName << "_type_impls" << endl;
for( int chunk = 1; chunk <= typeChunks; ++chunk ) {
cmLists << " Sdai" << schema_upper << "_unity_types_" <<
std::setfill( '0' ) << std::setw( 4 ) << chunk << ".cc" << endl;
}
cmLists << " )" << endl;
cmLists << "else(SC_UNITY_BUILD)" << endl;
cmLists << " set(" << shortName << "_entity_impls" << endl;
cmLists << ei.str();
Expand All @@ -241,7 +283,8 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists << "set( " << shortName << "_misc_impls" << endl;
cmLists << " SdaiAll.cc compstructs.cc schema.cc" << endl;
cmLists << " Sdai" << schema_upper << ".cc" << endl;
cmLists << " Sdai" << schema_upper << ".init.cc )" << endl << endl;
cmLists << " Sdai" << schema_upper << ".init.cc" << endl;
cmLists << " Sdai" << schema_upper << ".sources.cmake )" << endl << endl;

cmLists << "set(schema_target_files ${" << shortName << "_entity_impls} " << "${" << shortName << "_type_impls} " << "${" << shortName << "_misc_impls})" << endl;
cmLists << "SCHEMA_TARGETS(\"" << input_filename << "\" \"" << schemaName << "\"" << endl;
Expand Down Expand Up @@ -330,14 +373,18 @@ int main( int argc, char ** argv ) {
DictionaryEntry de;
/* copied from fedex.c */
Express model;
if( ( argc != 2 ) || ( strlen( argv[1] ) < 1 ) ) {
fprintf( stderr, "\nUsage: %s file.exp\nOutput: a CMakeLists.txt to build the schema,", argv[0] );
if( ( argc != 2 && argc != 3 ) || ( strlen( argv[1] ) < 1 ) ) {
fprintf( stderr, "\nUsage: %s file.exp [entity-chunk-size[:type-chunk-size]]\nOutput: a CMakeLists.txt to build the schema,", argv[0] );
fprintf( stderr, " containing file names for entities, types, etc\n" );
fprintf( stderr, "also prints (to stdout) the absolute path to the directory CMakeLists.txt was created in\n" );
exit( EXIT_FAILURE );
}
EXPRESSprogram_name = argv[0];
input_filename = argv[1];
if( argc == 3 && !parseChunkSizes( argv[2] ) ) {
fprintf( stderr, "chunk sizes must be positive integers in N or N:N form\n" );
exit( EXIT_FAILURE );
}

EXPRESSinitialize();

Expand Down
12 changes: 10 additions & 2 deletions cmake/schema_scanner/schemaScanner.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ else(NOT DEFINED SC_UNITY_BUILD)
message( STATUS "Respecting user-defined SC_UNITY_BUILD value of ${SC_UNITY_BUILD}.")
endif(NOT DEFINED SC_UNITY_BUILD)

if(NOT DEFINED SC_EXP2CXX_CHUNK_SIZE)
set(SC_EXP2CXX_CHUNK_SIZE "64:8" CACHE STRING "Maximum entity:type objects in generated unity translation units")
endif()


# --- variables ---
# SC_ROOT: SC root dir
Expand Down Expand Up @@ -82,7 +86,7 @@ endif(WIN32)
# SCHEMA_FILE - path to the schema
# TODO should we have a result variable to return schema name(s) found?
macro(SCHEMA_CMLIST SCHEMA_FILE)
execute_process(COMMAND ${SCANNER_OUT_DIR}/schema_scanner ${SCHEMA_FILE}
execute_process(COMMAND ${SCANNER_OUT_DIR}/schema_scanner ${SCHEMA_FILE} ${SC_EXP2CXX_CHUNK_SIZE}
WORKING_DIRECTORY ${SC_BINARY_DIR}/schemas
RESULT_VARIABLE _ss_stat
OUTPUT_VARIABLE _ss_out
Expand All @@ -101,7 +105,11 @@ macro(SCHEMA_CMLIST SCHEMA_FILE)
list(FIND _already_added "${_dir}" _idx)
if(${_idx} EQUAL -1)
set_property(GLOBAL APPEND PROPERTY _SC_SCHEMA_DIRS "${_dir}")
add_subdirectory(${_dir} ${_dir}) #specify source and binary dirs as the same
# Keep generated targets under the top-level binary tree. Passing the
# absolute generated-source path as both arguments creates absolute
# make target names with newer CMake.
get_filename_component(_schema_dir_name "${_dir}" NAME)
add_subdirectory("${_dir}" "${SC_BINARY_DIR}/schema-targets/${_schema_dir_name}")
endif()
endforeach(_dir ${_ss_out})
# configure_file forces cmake to run again if the schema has been modified
Expand Down
31 changes: 30 additions & 1 deletion src/exp2cxx/classes.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
int multiple_inheritance = 1;
int print_logging = 0;
int old_accessors = 0;
unsigned long exp2cxx_entity_chunk_size = 64;
unsigned long exp2cxx_type_chunk_size = 8;

/**
* Turn the string into a new string that will be printed the same as the
Expand Down Expand Up @@ -203,7 +205,6 @@ void USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * t
}

int Handle_FedPlus_Args( int i, char * arg ) {
(void) arg; /* unused */
if( ( ( char )i == 's' ) || ( ( char )i == 'S' ) ) {
multiple_inheritance = 0;
}
Expand All @@ -213,6 +214,34 @@ int Handle_FedPlus_Args( int i, char * arg ) {
if( ( ( char )i == 'l' ) || ( ( char )i == 'L' ) ) {
print_logging = 1;
}
if( ( char )i == 'k' ) {
char * end = 0;
unsigned long entity_requested;
unsigned long type_requested;
if( !arg || !arg[0] ) {
fprintf( stderr, "exp2cxx: chunk sizes must use N or N:N form\n" );
return 1;
}
entity_requested = strtoul( arg, &end, 10 );
if( !end || entity_requested == 0 ) {
fprintf( stderr, "exp2cxx: chunk sizes must be positive integers\n" );
return 1;
}
type_requested = entity_requested;
if( *end == ':' ) {
char * type_end = 0;
type_requested = strtoul( end + 1, &type_end, 10 );
if( !end[1] || !type_end || *type_end || type_requested == 0 ) {
fprintf( stderr, "exp2cxx: chunk sizes must use N or N:N form\n" );
return 1;
}
} else if( *end ) {
fprintf( stderr, "exp2cxx: chunk sizes must use N or N:N form\n" );
return 1;
}
exp2cxx_entity_chunk_size = entity_requested;
exp2cxx_type_chunk_size = type_requested;
}
return 0;
}

Expand Down
17 changes: 16 additions & 1 deletion src/exp2cxx/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ typedef struct file_holder {
struct {
FILE * impl;
FILE * hdr;
FILE * aggregate;
unsigned long count;
unsigned long chunk;
char base[BUFSIZ+1];
} entity, type;
FILE * manifest;
char schema[BUFSIZ+1];
} unity;
} File_holder, FILES;

Expand Down Expand Up @@ -116,6 +122,16 @@ void resolution_success( void );
void SCHEMAprint( Schema schema, FILES* files, void* complexCol, int suffix );
const char * FundamentalType( const Type t, int report_reftypes );
void numberAttributes( Scope scope );
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned long exp2cxx_entity_chunk_size;
extern unsigned long exp2cxx_type_chunk_size;
void UNITYentityInclude( FILES * files, const char * implementation );
void UNITYtypeInclude( FILES * files, const char * implementation );
#ifdef __cplusplus
}
#endif

/*Variable*/
#define VARis_simple_explicit(a) (!VARis_type_shifter(a))
Expand All @@ -137,4 +153,3 @@ void USEREFout( Schema schema, Dictionary refdict, Linked_List reflis
#include "classes_entity.h"

#endif

2 changes: 1 addition & 1 deletion src/exp2cxx/classes_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ void ENTITYPrint( Entity entity, FILES * files, Schema schema, bool externMap )
impl = FILEcreate( names.impl );
assert( hdr && impl && "error creating files" );
fprintf( files->unity.entity.hdr, "#include \"%s\"\n", names.header ); /* TODO this is not necessary? */
fprintf( files->unity.entity.impl, "#include \"%s\"\n", names.impl );
UNITYentityInclude( files, names.impl );

ENTITYPrint_h( entity, hdr, remaining, schema );
ENTITYPrint_cc( entity, files->create, hdr, impl, remaining, schema, externMap );
Expand Down
2 changes: 1 addition & 1 deletion src/exp2cxx/classes_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void TYPEPrint( const Type type, FILES *files, Schema schema ) {
impl = FILEcreate( names.impl );
assert( hdr && impl && "error creating files" );
fprintf( files->unity.type.hdr, "#include \"%s\"\n", names.header );
fprintf( files->unity.type.impl, "#include \"%s\"\n", names.impl );
UNITYtypeInclude( files, names.impl );

TYPEPrint_h( type, hdr );
TYPEPrint_cc( type, &names, hdr, impl, schema );
Expand Down
Loading
Loading