Skip to content

Commit

Permalink
Fix grtfmi.tlc for Simscape (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer authored Apr 28, 2023
1 parent 7438622 commit 227d0c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
53 changes: 19 additions & 34 deletions grtfmi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
cmake_minimum_required (VERSION 3.22)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(MODEL_NAME "" CACHE STRING "Model name")
set(MATLAB_ROOT "C:/Program Files/MATLAB/R2016b" CACHE STRING "MATLAB install directory")
set(RTW_DIR "" CACHE STRING "RTW generated model directory")
set(ARCH "win64" CACHE STRING "System architecture")
set(CUSTOM_INCLUDE "" CACHE STRING "Additional include directories")
set(CUSTOM_SOURCE "" CACHE STRING "Additional source files")
set(CUSTOM_LIBRARY "" CACHE STRING "Additional static libraries")
Expand Down Expand Up @@ -56,21 +59,6 @@ else ()

endif ()

# MATLAB architecture
if (WIN32)
set(ARCH win)
elseif (APPLE)
set(ARCH maci)
else ()
set(ARCH glnxa)
endif ()

if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set (ARCH ${ARCH}64)
else ()
set (ARCH ${ARCH}32)
endif ()

if (MSVC)
# set configuration types
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING INTERNAL FORCE)
Expand Down Expand Up @@ -140,33 +128,22 @@ if (${SIMSCAPE})
file(GLOB PM_SOURCES "${MATLAB_ROOT}/toolbox/physmod/common/foundation/core/c/${ARCH}/*.c")
file(GLOB SSC_CORE_SOURCES "${MATLAB_ROOT}/toolbox/physmod/simscape/engine/core/c/${ARCH}/*.c")
file(GLOB SSC_SLI_SOURCES "${MATLAB_ROOT}/toolbox/physmod/simscape/engine/sli/c/${ARCH}/*.c")

add_library (ex STATIC ${EX_SOURCES})
add_library (mc STATIC ${MC_SOURCES})
add_library (ne STATIC ${NE_SOURCES})
add_library (pm STATIC ${PM_SOURCES})
add_library (ssc_core STATIC ${SSC_CORE_SOURCES})
add_library (ssc_sli STATIC ${SSC_SLI_SOURCES})
file(GLOB SSC_ST_SOURCES "${MATLAB_ROOT}/toolbox/physmod/simscape/simtypes/core/c/${ARCH}/*.c")

set(SIMSCAPE_INCLUDE
${MATLAB_ROOT}/toolbox/physmod/simscape/engine/sli/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/simscape/engine/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/simscape/compiler/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/simscape/ds/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/simscape/simtypes/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/network_engine/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/common/math/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/common/logging/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/common/lang/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/common/external/library/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/common/foundation/core/c/${ARCH}
${MATLAB_ROOT}/toolbox/physmod/simscape/simscapedemos
)

target_include_directories (ex PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})
target_include_directories (mc PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})
target_include_directories (ne PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})
target_include_directories (pm PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})
target_include_directories (ssc_core PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})
target_include_directories (ssc_sli PUBLIC ${RTW_DIR} ${RTW_INCLUDE} ${SIMSCAPE_INCLUDE})

foreach (INCLUDE_PATH ${SIMSCAPE_INCLUDE})
file(GLOB COMPONENT_HEADERS "${INCLUDE_PATH}/*.h")
set(SIMSCAPE_HEADERS ${SIMSCAPE_HEADERS} ${COMPONENT_HEADERS})
Expand All @@ -179,6 +156,7 @@ if (${SIMSCAPE})
${PM_SOURCES}
${SSC_CORE_SOURCES}
${SSC_SLI_SOURCES}
${SSC_ST_SOURCES}
)

endif ()
Expand All @@ -187,8 +165,19 @@ add_library (${MODEL_NAME} SHARED
${RTW_DIR}/modelDescription.xml
${HEADERS}
${SOURCES}
${SIMSCAPE_SOURCES}
)

if (${SIMSCAPE})
source_group("ex" FILES ${EX_SOURCES})
source_group("mc" FILES ${MC_SOURCES})
source_group("ne" FILES ${NE_SOURCES})
source_group("pm" FILES ${PM_SOURCES})
source_group("ssc_core" FILES ${SSC_CORE_SOURCES})
source_group("ssc_sli" FILES ${SSC_SLI_SOURCES})
source_group("ssc_st" FILES ${SSC_ST_SOURCES})
endif ()

set_property(TARGET ${MODEL_NAME} PROPERTY C_STANDARD 99)

target_include_directories (${MODEL_NAME} PUBLIC
Expand Down Expand Up @@ -217,10 +206,6 @@ target_compile_definitions(${MODEL_NAME} PUBLIC

target_link_libraries(${MODEL_NAME} ${CUSTOM_LIBRARY})

if (${SIMSCAPE})
target_link_libraries(${MODEL_NAME} ex mc ne pm ssc_core ssc_sli)
endif ()

file(READ ${MATLAB_ROOT}/simulink/include/simstruc.h CONTENTS)
file(WRITE ${RTW_DIR}/Temp/simstruc_rt.h "
/* Add definitions to allow compilation without compiler options */
Expand Down
4 changes: 2 additions & 2 deletions grtfmi/grtfmi_compile_wsl.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ function grtfmi_compile_wsl(varargin)

source_dir = grtfmi_wslpath(grtfmi_dir);

command = ['wsl "' cmake_command '" -S "' source_dir '" -B "' rtw_dir '"'];
command = ['wsl -u root "' cmake_command '" -S "' source_dir '" -B "' rtw_dir '"'];

status = system(command);
assert(status == 0, 'Failed to run CMake generator');

disp('### Building FMU')

command = ['wsl "' cmake_command '" --build "' rtw_dir '"'];
command = ['wsl -u root "' cmake_command '" --build "' rtw_dir '"'];
status = system(command);
assert(status == 0, 'Failed to build FMU');

Expand Down
3 changes: 2 additions & 1 deletion grtfmi/grtfmi_make_rtw_hook.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ function grtfmi_make_rtw_hook(hookMethod, modelName, rtwRoot, templateMakefile,
fprintf(fid, 'CMAKE_GENERATOR_TOOLSET:STRING=%s\n', toolset);
end
fprintf(fid, 'MODEL_NAME:STRING=%s\n', modelName);
fprintf(fid, 'RTW_DIR:STRING=%s\n', strrep(pwd, '\', '/'));
fprintf(fid, 'MATLAB_ROOT:STRING=%s\n', strrep(matlabroot, '\', '/'));
fprintf(fid, 'RTW_DIR:STRING=%s\n', strrep(pwd, '\', '/'));
fprintf(fid, 'ARCH:STRING=%s\n', computer('arch'));
fprintf(fid, 'CUSTOM_INCLUDE:STRING=%s\n', custom_include);
fprintf(fid, 'CUSTOM_SOURCE:STRING=%s\n', custom_source);
fprintf(fid, 'CUSTOM_LIBRARY:STRING=%s\n', custom_library);
Expand Down
1 change: 1 addition & 0 deletions grtfmi/grtfmi_simscape_sources.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{'common', 'foundation', 'core'}
{'simscape', 'engine', 'core'}
{'simscape', 'engine', 'sli'}
{'simscape', 'simtypes', 'core'}
};

sources = {};
Expand Down

0 comments on commit 227d0c3

Please sign in to comment.