A method and device for compiling model files based on CMake tool
Using the CMake tool to build Simulink model files on the ARM framework VxWorks7.0 system solves the problem that existing technology cannot run, achieves efficient model compilation and compatibility, and improves compilation efficiency.
Patent Information
- Application Number
- CN202410895367.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-07-05
AI Technical Summary
The existing technology cannot meet the requirements for running and using the Simulink mathematical model on the VxWorks7.0 system of the ARM framework, and cannot generate a suitable executable file.
By using the CMake tool to build model compilation intermediate files in the target system, build mathematical models, generate target tool chain files, and use compile commands to generate target executable files, the model files can be compiled and run on the ARM framework VxWorks7.0 system.
It simplifies the model compilation process, improves model compilation efficiency, solves the compatibility problem of model files running on the ARM framework VxWorks7.0 system, and meets the need for frequent replacement of model files.
Smart Images

Figure CN118426782B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for compiling a model file based on a CMake tool. Background Art
[0002] CMake is an open source, cross-platform build tool that can write configuration files that are independent of the running platform and compiler, generate local Makefiles or project / workspaces files, and then use them in a general build method to generate the required executable files.
[0003] Simulink mathematical models are widely used in simulation systems in the fields of aerospace, automobiles, and sensors, with a wide range of fields and platforms. In the prior art, the model compilation method is to generate library files (dll or .a) running on Windows and Linux systems through CMake and ert / grt files, or to generate model files (.out) running on systems below VxWorks6.x through the tornado file method provided by MATLAB. Both of the above model compilation methods cannot meet the requirements for the operation and use of model files on the VxWorks7.0 system of the ARM framework. Summary of the invention
[0004] The embodiment of the present application solves the problem that the prior art cannot meet the requirements for running and using model files on a VxWorks 7.0 system of an ARM framework by providing a method and device for compiling model files based on a CMake tool.
[0005] In the first aspect, an embodiment of the present application provides a method for compiling a model file based on the CMake tool, including: building a model compilation intermediate file in a target system after the environment is configured; building a mathematical model based on the CMake tool; building a target tool chain file required by CMake based on the mathematical model; calling the target tool chain file to generate a source code compilation rule file; and using a compilation command based on the source code compilation rule file and the target tool chain file to generate a target executable file.
[0006] In combination with the first aspect, in a possible implementation method, the configuration environment includes: installing the target tools required for model file compilation; wherein the target tools include CMake tools, VS2017, MATLAB and VxWorks7.0; configuring the environment variables of the target tools, and adding the file path of the model compilation intermediate file in MATLAB.
[0007] In combination with the first aspect, in a possible implementation method, the construction of the model compilation intermediate file includes: modifying the source code generation file tlc of the target system, and setting the file source of the target system to the embedded program code transcoder ert; setting the file name generation rules for model file compilation; modifying the compilation rule template tmf file according to the graphic template file grt.
[0008] In combination with the first aspect, in a possible implementation method, modifying the compilation rule template tmf file according to the graphic template file grt includes: adding dependent files in the compilation rule template tmf file, and specifying its dependent library and S-Func path; setting the compilation target environment, target compilation file type and target compiler options of the model file.
[0009] In combination with the first aspect, in a possible implementation method, after building the mathematical model, it also includes: configuring the compilation items of the model file, setting the simulation start time, fixed simulation step, model simulation step and model stop time of the model; and / or customizing the S-func interface and setting interface options for it; compiling the model file to generate a target source code file and a source code file compilation rule configuration file.
[0010] In combination with the first aspect, in a possible implementation method, building the target tool chain file required by CMake includes: creating a project file based on the target platform; determining whether it is a target compiler; if it is a target compiler, compiling the project file to generate the target tool chain file; otherwise, setting the compiler to the target compiler.
[0011] In combination with the first aspect, in a possible implementation method, the target executable file is generated using a compilation command based on the source code compilation rule file and the target tool chain file, including: changing the file type of the source code compilation rule file, and tailoring the content therein to generate a compilation script; configuring the target tool chain file; configuring the compilation command of the model file and the target file generation path; loading the compilation script into the path where the source code file is located, and running the compilation script to generate the target executable file.
[0012] In the second aspect, an embodiment of the present application provides a device for compiling model files based on the CMake tool, including: a construction module, used to build a model compilation intermediate file in a target system after the environment is configured; a building module, used to build a mathematical model based on the CMake tool; a tool chain file module, used to build a target tool chain file required by CMake based on the mathematical model; a compilation rule file module, used to call the target tool chain file to generate a source code compilation rule file; a compilation module, used to use a compilation command to generate a target executable file based on the source code compilation rule file and the target tool chain file.
[0013] In a third aspect, an embodiment of the present application provides a device, comprising: a processor; a memory for storing processor-executable instructions; when the processor executes the executable instructions, it implements the method described in the first aspect or any possible implementation method of the first aspect.
[0014] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium includes a medium for storing a computer program or instructions, which, when executed, enables the method described in the first aspect or any possible implementation method of the first aspect to be implemented.
[0015] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0016] The embodiment of the present application can solve the need for frequent replacement of model files during the use of the simulation system through model compilation intermediate files and source code compilation rule files; through the target executable file, the compilation process can be simplified and the model compilation efficiency can be improved. The problem that the existing technology cannot meet the operation and use of model files on the VxWorks7.0 system of the ARM framework is solved. In addition, the model file can be run on the VxWorks7.0 system of the ARM framework, and the model compilation efficiency can also be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A flowchart of a method for compiling a model file based on the CMake tool provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of the structure of a device for compiling model files based on the CMake tool provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0021] The following describes some of the techniques involved in the embodiments of the present application to facilitate understanding, and they should be considered as merely exemplary. Therefore, it should be appreciated by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, some descriptions of well-known functions and structures are omitted in the following description.
[0022] Figure 1 1 is a flowchart of a method for compiling a model file based on a CMake tool provided in an embodiment of the present application, including steps 101 to 105. Figure 1 This is only an execution order shown in the embodiment of the present application, and does not represent the only execution order of a method for compiling a model file based on the CMake tool. If the final result can be achieved, Figure 1 The steps shown may be performed in parallel or reversed.
[0023] Step 101: Build the model compilation intermediate file in the target system after the environment is configured. In the embodiment of the present application, the target tool required for model file compilation is installed. Among them, the target tool includes CMake tool, VS2017, MATLAB and VxWorks7.0. Configure the environment variables of the target tool, and add the file path of the model compilation intermediate file in MATLAB. Specifically, before configuring the environment, install the required CMake (a free multi-platform compilation tool designed to build, test and package software) tools, VS2017 (Visual Studio 2017, an integrated development environment for developing various types of applications), MATLAB (a commercial mathematical software) and VxWorks7.0 (an embedded real-time operating system) and other software. Then configure the environment variables of the above software respectively. Exemplarily, double-click the downloaded CMake installation package to start the installation program. In the installation wizard, select the installation path of CMake, set the installation path and start the installation until it is completed. VS2017, MATLAB, VxWorks7.0 and other software can be installed according to the installation tutorials in the operation documentation. During the installation process, you can set the installation path for each software separately or use the default installation path according to actual needs.
[0024] Those skilled in the art should know that MATLAB usually does not need to be directly configured into environment variables, but its related paths are automatically set during the installation process. However, if you need to configure a specific search path or working directory for MATLAB, you can use the addpath and savepath functions in the MATLAB command line or script. It should be noted that you configure the search path of MATLAB, not its root path. If you need to configure the root path of MATLAB (for example, to reference files in the MATLAB installation directory in a script), you can use an absolute path or a relative path directly in the script.
[0025] In MATLAB, model compilation intermediate files are usually automatically managed in MATLAB's temporary folder or project folder. However, you need to specify a specific intermediate file path for a specific model file or project. You need to view MATLAB's documentation or use related functions and toolboxes to manage these files. For example, use the "Working Directory" option in Simulink's "Model Configuration Parameters" dialog box to specify the intermediate file storage location of the model file.
[0026] In an embodiment of the present application, the source code generation file tlc (English full name: Embed Language Compiler files, Chinese: Custom Code Generator) of the target system is modified, and the file source of the target system is set to the embedded code transcoder ert (English full name: Embedded Coder, Chinese: Embedded Coder). Specifically, the file name generation rule for model file compilation is set. According to the graph template file grt (English full name: GrapherTemplate, graph template file, used to save graph templates, including predefined settings for generating graphs), the compilation rule template tmf file (English full name: Template Makefile files, Chinese: compilation rule template) is modified. Specifically, dependent files are added to the compilation rule template tmf file, and its dependent library and S-Func path are specified. Set the compilation target environment, target compilation file type, and target compiler options of the model file.
[0027] In one embodiment of the present application, CMake and ert / grt files can be used to generate library files (dll or .a) running on Windows and Linux systems, which cannot meet the needs of frequently changing executable files. The tornado file method provided by MATLAB can be used to generate model files (.out) running on systems below VxWorks6.x. Currently, it is not possible to directly compile executable files that can run on VxWorks7.0. In response to this problem, the CMake tool and toolchain file (toolchain.cmake) can be used to implement the problem of running mathematical models on the VxWorks7.0 system of the ARM framework.
[0028] Specifically, to compile the model file using the CMake tool, you need to configure a complete set of running and compiling environments, correctly install VS2017, MATLAB R2018b, Workbench4.0 (compile VxWorks7.0 tools) and CMake tools, and configure the system environment variables required for software operation, including the MATLAB R2018b root path and running path, CMake tool running path, VxWorks7.0 compiler path, etc. MATLAB software needs to configure the library file path, open the MATLAB R2018b software, set the path in the software, and add the model compilation intermediate file path D:\MATLAB\R2018b\rtw\c\lyncon_2_0 and S-func library file path D:\MATLAB\R2018b\base_com_simulink_lib_lyncon.
[0029] Create the model compilation intermediate file required for model file compilation. Specifically, according to the ert folder in MATLAB R2018b, set the target system file lyncon_shrlib_2_0_cmake.tlc from the ert.tlc file, set some fixed property configurations in model file compilation, and set the naming rules for the source code folder generated by model file compilation. Based on the tmf file in grt, modify the content of the compilation template file lyncon_cmake.tmf, set the files that need to be compiled during source code compilation, set the source file path and the file path that the compilation depends on, including the intermediate file (lyncon_2_0) path required for model file compilation, MATLAB header file path, S-func library file path, set the path of the source code file to be compiled, set the target file name generation rule, set the compilation target environment, set the target compiler, and define the target compilation properties.
[0030] In addition, a model file external interface file lyncon_main.cpp may be added to provide an external use interface for the model file. The external interface includes an input interface, an output interface, an initialization parameter interface, and a current version interface of the model file.
[0031] Step 102: Build a mathematical model based on the CMake tool. In the embodiment of the present application, configure the compilation items of the model file, set the simulation start time, fixed simulation step size, model simulation step size and model stop time of the model file. And / or customize the S-func interface and set interface options for it. Compile the model file to generate the target source code file and the source code file compilation rule configuration file.
[0032] Specifically, according to the functional requirements, a new Simulink digital model is created, a digital model is built and the functional correctness and completeness are verified, the compilation options are configured, and the model simulation start time, fixed simulation step size, model simulation step size, and model stop time are set. In the code generation option CodeGeneration, the target system file System target file is set to lyncon_shrlib_2_0_cmake.tlc, and the compilation process option Build process is set to Generate code only. When using s-func, the non-inlined S-func interface (i.e., non-inlined S-functions) of the Interface option needs to be checked. Use Simulink to compile the model file, and generate the target source code file *.c and the source code file compilation rule configuration file xx.mk in the xx_board_lyncon_shrlib_rtw_cmake folder.
[0033] Step 103: Build the target toolchain file required by CMake based on the mathematical model. In the embodiment of the present application, create a project file based on the target platform. Determine whether it is a target compiler. If it is a target compiler, compile the project file to generate a target toolchain file. Otherwise, set the compiler to the target compiler.
[0034] Specifically, build the tool chain file, open the Workbench4.0 software, create a VxWorks 7 CMakeDownloadable Kernel Module Project project (after correctly installing the CMake tool software, you can use the Workbench4.0 software to compile the project normally), select the target platform (that is, the board support package BSP) correctly according to the target hardware framework, and select the compiler of the same type as the target platform system (VxWorks7.0). Here, select the GUN compiler to compile the project. In the project directory, generate the target tool chain file toolchain.cmake.
[0035] Step 104: Call the target toolchain file to generate a source code compilation rule file. In the embodiment of the present application, the file type of the source code compilation rule file is changed, and the content thereof is cut to generate a compilation script. Configure the target toolchain file. Configure the compilation command of the model file and the target file generation path. Load the compilation script into the path where the source code file is located, and run the compilation script to generate the target executable file.
[0036] Specifically, enter the xx_board_lyncon_shrlib_rtw_cmake folder, create a new automated execution script autocompile.bat file, in the automated script, get the current path as the script execution path, get the xx.mk file under the current path (this file is the original type of source code file compilation rule configuration file), open the xx.mk file to trim the file content, and write the trimmed file content into the newly created CMakeLists.txt file (a file that describes the link compilation rules).
[0037] Step 105: Generate the target executable file using the compilation command based on the source code compilation rule file and the target toolchain file. Specifically, configure the CMake toolchain command, set the dependent library MATLAB root path, set the toolchain file (toolchain.cmake) path, CMake execution start path (current path), set the generated target type to TARGET_VXOWKRS_DKM, set the compilation option to Eclipse CDT4 - Unix Makefiles, set the target generation path to the cmake_build folder under the current path, after the CMake command is executed, enter the cmake_build file, execute the make command, call the compilation rule file Makefile under the cmake_build file, generate the executable file .out, copy the executable file to the target folder, and the target file is generated. If the software path in the automated compilation script is unchanged, there is no need to rewrite the script, and the script can be reused.
[0038] This application abandons the original method of combining MATLAB and tornado files, and chooses the method of jointly compiling CMake tools and ert / grt files, changing the model compilation intermediate files required for model file compilation, configuring model compilation options, and generating model source code files and source code file compilation rule configuration files. Depends on the target platform (BSP package), creates a VxWorks 7CMake Downloadable Kernel Module Project project, and compiles the project to generate a toolchain file (toolchain.cmake). The CMake tool calls the toolchain file (toolchain.cmake) and the source code file compilation rule configuration file (CMakeList: a rule file that describes link compilation), generates a source code compilation rule file (ie, Makefile file), and uses the compilation command (make) to generate a target executable file (.out), so as to run the model file on the VxWorks7.0 system of the ARM framework. At the same time, by referring to this method, the operation of model files on different platforms can be solved.
[0039] Although the present application provides method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in this embodiment is only one way of executing the order of many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in sequence or in parallel according to the method shown in this embodiment or the accompanying drawings (for example, in a parallel processor or multi-threaded processing environment).
[0040] like Figure 2 As shown, the embodiment of the present application also provides a device 200 for compiling a model file based on a CMake tool. The device includes: a construction module 201, a building module 202, a tool chain file module 203, a compilation rule file module 204 and a compilation module 205, as follows.
[0041] The construction module 201 is used to construct the model compilation intermediate file in the target system after the environment is configured.
[0042] The building module 202 is used to build a mathematical model based on the CMake tool.
[0043] The tool chain file module 203 is used to construct the target tool chain file required by CMake based on the mathematical model.
[0044] The compilation rule file module 204 is used to call the target tool chain file to generate a source code compilation rule file.
[0045] The compiling module 205 is used to generate a target executable file using a compiling command based on a source code compiling rule file and a target tool chain file.
[0046] Some modules in the apparatus described in the present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0047] The devices or modules described in the above application embodiments can be implemented by computer chips or entities, or by products with certain functions. For the convenience of description, the above devices are described in various modules according to their functions. When implementing the embodiments of the present application, the functions of each module can be implemented in the same or multiple software and / or hardware. Of course, the module that implements a certain function can also be implemented by combining multiple sub-modules or sub-units.
[0048] The methods, devices or modules described in this application can be implemented in the form of computer-readable program codes. The controller can be implemented in any appropriate manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program codes (such as software or firmware) that can be executed by the (micro)processor, logic gates, switches, application-specific integrated circuits (English: Application Specific Integrated Circuit; Abbreviation: ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program codes, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included in it for implementing various functions can also be regarded as structures within the hardware component. Or even, the means for realizing various functions may be regarded as both a software module for realizing the method and a structure within a hardware component.
[0049] An embodiment of the present application further provides a device, comprising: a processor; a memory for storing processor executable instructions; when the processor executes the executable instructions, the method described in the embodiment of the present application is implemented.
[0050] The embodiments of the present application also provide a non-volatile computer-readable storage medium on which a computer program or instruction is stored. When the computer program or instruction is executed, the method described in the embodiments of the present application is implemented.
[0051] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist independently, or two or more modules may be integrated into one module.
[0052] The above storage media include but are not limited to random access memory (RAM), read-only memory (ROM), cache, hard disk drive (HDD) or memory card. The memory can be used to store computer program instructions.
[0053] It can be seen from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary hardware. Based on this understanding, the technical solution of the present application can be essentially or partly reflected in the prior art in the form of a software product, or it can be reflected in the implementation process of data migration. The computer software product can be stored in a storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a mobile terminal, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0054] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. All or part of this application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, mobile communication terminals, multi-processor systems, microprocessor-based systems, programmable electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.
[0055] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit the present application. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the present application.
Claims
1. A method for compiling a model file based on a CMake tool, characterized in that: include: Constructing a model compilation intermediate file in the target system after the environment is configured; wherein constructing the model compilation intermediate file includes: Modify the source code of the target system to generate the file tlc, and set the file source of the target system to the embedded code transcoder ert; Set the file name generation rules for model file compilation; Modifying the compilation rule template tmf file according to the graphic template file grt, including: adding dependent files in the compilation rule template tmf file, and specifying its dependent library and S-Func path; setting the compilation target environment, target compilation file type and target compiler options of the model file; Build mathematical models based on CMake tools; Building the target toolchain file required by CMake based on the mathematical model; Calling the target toolchain file to generate a source code compilation rule file; Generate a target executable file using a compile command based on the source code compile rule file and the target tool chain file, including: Changing the file type of the source code compilation rule file and trimming the content therein to generate a compilation script; Configure the target toolchain file; Configure the compilation command of the model file and the target file generation path; The compilation script is loaded into the path where the source code file is located, and the compilation script is run to generate the target executable file.
2. The method according to claim 1, characterized in that: The configuration environment includes: Install the target tools required for compiling the model file; wherein the target tools include CMake tools, VS2017, MATLAB and VxWorks7.0; Configure the environment variables of the target tool and add the file path of the model compilation intermediate file in MATLAB.
3. The method according to claim 1, characterized in that After the mathematical model is constructed, the following steps are also included: Configure the compilation items of the model file, set the simulation start time, fixed simulation step size, model simulation step size and model stop time of the model; and / or Customize the S-func interface and set interface options for it; Compile the model file to generate the target source code file and the source code file compilation rule configuration file.
4. The method according to claim 1, characterized in that: The target toolchain files required to build CMake include: Create project files based on the target platform; Determine whether it is a target compiler; If it is a target compiler, the project file is compiled to generate the target tool chain file; otherwise, the compiler is set as the target compiler.
5. A device for compiling a model file based on a CMake tool, characterized in that: include: A construction module is used to construct a model compilation intermediate file in the target system after the environment is configured; wherein, the construction of the model compilation intermediate file includes: Modify the source code of the target system to generate the file tlc, and set the file source of the target system to the embedded code transcoder ert; Set the file name generation rules for model file compilation; Modifying the compilation rule template tmf file according to the graphic template file grt, including: adding dependent files in the compilation rule template tmf file, and specifying its dependent library and S-Func path; setting the compilation target environment, target compilation file type and target compiler options of the model file; Building module, used to build mathematical models based on CMake tools; A toolchain file module, used for building a target toolchain file required by CMake based on the mathematical model; A compilation rule file module, used to call the target tool chain file to generate a source code compilation rule file; A compiling module, used to generate a target executable file using a compiling command based on the source code compiling rule file and the target tool chain file, including: Changing the file type of the source code compilation rule file and trimming the content therein to generate a compilation script; Configure the target toolchain file; Configure the compilation command of the model file and the target file generation path; The compilation script is loaded into the path where the source code file is located, and the compilation script is run to generate the target executable file.
6. A device for executing a method for compiling a model file based on a CMake tool, characterized in that: include: processor; a memory for storing processor-executable instructions; When the processor executes the executable instructions, the method according to any one of claims 1 to 4 is implemented.
7. A non-volatile computer-readable storage medium, characterized in that: The device comprises a computer program or an instruction for storing the computer program or the instruction, which, when executed, enables the method according to any one of claims 1 to 4 to be implemented.
