Construction method, system and equipment of cross-platform Display software based on CMake and medium
By using CMake tools, generating build files suitable for different operating systems solves the problem of Makefile lack of cross-platform support, and improves development efficiency and building environment adaptability.
Patent Information
- Application Number
- CN202510139385.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-08
- Publication Date
- 2025-06-13
AI Technical Summary
The lack of cross-platform support for existing Makefiles has led to the writing of Makefiles for different operating systems (such as Windows, Linux, etc.), which increases maintenance costs and inefficient development efficiency.
Using CMake as a construction tool, we generate build files suitable for different operating systems and compilers through pre-written CMake configuration files to achieve cross-platform construction.
Reduces the workload of writing and maintaining build scripts individually for each target platform, improves development efficiency, and enhances adaptability to different build environments.
Smart Images

Figure CN120144177A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of embedded system development, and particularly relates to a construction method, system, device and medium of cross-platform Display software based on CMake. Background Art
[0002] In the compilation and construction process of software projects, Makefile is a commonly used build automation tool. Especially in the Linux system, it can efficiently manage dependencies and execute compilation tasks. However, Makefile lacks support for cross-platform. As a result, in order to adapt to different operating systems (such as Windows, Linux, etc.), it is usually necessary to write separate Makefiles for each platform, which increases the maintenance cost, makes it difficult to ensure code consistency, and reduces the development efficiency and the convenience of cross-platform porting. Summary of the Invention
[0003] Aiming at the problems in the background art, the present invention proposes a construction method, system, device and medium of cross-platform Display software based on CMake.
[0004] To achieve the above object, the present invention adopts the following technical solutions: In the first aspect, the present disclosure proposes a construction method of cross-platform Display software based on CMake, including: Responding to the CMake command, reading and parsing a pre-written CMake configuration file to generate a local build system file; Compiling project source files based on the local build system file to obtain target files; Linking libraries to the target files to obtain executable files.
[0005] Preferably, the parsing of the pre-written CMake configuration file includes: Determining project basic information; Determining the build environment; Determining the include path and library files of the thread library according to the build environment; Creating libraries and adding corresponding header files and source files to each library; Selecting the corresponding OGLX library for linking according to the build environment.
[0006] Preferably, the determining of the project basic information includes: Determining the project name; Adding preprocessor definitions; Organizing the project source code according to functional modules.
[0007] Preferably, the determination of the project basic information further includes: determining the minimum version of CMake.
[0008] Preferably, the determination of the build environment includes: Determining the current operating system type; Determining the output paths of the executable file and the libraries.
[0009] Preferably, the library types include internal libraries and external libraries.
[0010] Preferably, if the type of the operating system is Windows, copy the corresponding DLL files to the output path of the executable file.
[0011] In a second aspect, the present disclosure proposes a build system for a cross-platform Display software based on CMake, including: A parsing module, configured to read and parse a pre-written CMake configuration file in response to a CMake command, and generate a local build system file; A compilation module, configured to compile project source files based on the build system file to obtain target files; A linking module, configured to link libraries to the target files to obtain executable files.
[0012] In a third aspect, the present disclosure proposes a device, including a memory and a processor, where a computer instruction capable of running on the processor is stored on the memory, and when the processor runs the computer instruction, it executes a build method for a cross-platform Display software based on CMake according to the first aspect.
[0013] In a fourth aspect, the present disclosure proposes a computer-readable storage medium, on which a computer instruction is stored, and when the computer instruction runs, it can implement a build method for a cross-platform Display software based on CMake according to the first aspect.
[0014] Advantages of the present invention: 1. By using CMake as a build tool, compared with traditional Makefile, CMake can use a set of configuration files to achieve cross-platform building, automatically generating build files suitable for different operating systems and compilers, such as Makefile for Unix, Visual Studio solution files (.sln) for Windows, etc. This flexibility greatly reduces the workload of separately writing and maintaining build scripts for each target platform, and improves development efficiency.
[0015] 2. The method of the present invention uses CMake as a build tool. Different from Makefile which does not clearly distinguish between configuration and build instructions, CMake strictly separates these two processes: First, it generates platform-specific local build system files through pre-written CMake configuration files, and then uses these generated local build system files for actual compilation and linking, enhancing the adaptability to different build environments.
[0016] 3. The method of the present invention uses CMake as a build tool. Compared with Makefile which has relatively limited functions and mainly relies on simple rule and dependency handling and cannot meet more advanced requirements, CMake provides a rich set of functions, including conditional judgment, loop structure, variable operation, etc., enabling it to build more complex build systems.
[0017] Other features and advantages of the present invention will be described in the following specification, and in part will be obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention can be achieved and obtained through the structures pointed out in the specification and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0019] Figure 1 Shows a flowchart of a method for building a cross-platform Display software based on CMake of the present invention; Figure 2 Shows a device framework diagram of the present invention; Figure 3 Shows a schematic diagram of the device structure of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the protection scope of the present invention.
[0021] Refer to Figure 1As shown in the figure, a method for building a cross-platform Display software based on CMake specifically includes the following steps: S1. In response to the CMake command, read and parse the pre-written CMake configuration file to generate a local build system file; By using CMake as the build tool, compared with the traditional Makefile, CMake can achieve cross-platform building with a set of configuration files, automatically generating build files suitable for different operating systems and compilers, such as the Makefile for Unix, the Visual Studio solution file (.sln) for Windows, etc. This flexibility greatly reduces the workload of separately writing and maintaining build scripts for each target platform and improves development efficiency.
[0022] Specifically, parsing the pre-written CMake configuration file includes the following steps: S11. Determine the basic project information; S111. Determine the project name; Determining the project name is the first step in the CMake configuration process. This step ensures that the entire project has a clear identity. The project name not only affects the generated build files but also the name of the final output executable file or library file. Therefore, determining a clear project name is very important for project organization and subsequent maintenance. Moreover, in the case of multi-module or multi-subproject, the project name can also help distinguish each component.
[0023] S112. Add preprocessor definitions; Preprocessor definitions allow developers to customize the code according to different compilation environments. For example, additional logging or error checking functions can be enabled in the debug mode, while these features are disabled in the release version to optimize performance. By adding preprocessor definitions, the function of the program can be adjusted without changing the source code, and preprocessor definitions can also be used to activate or deactivate certain platform-specific functions or library interfaces.
[0024] S113. Organize the project source code according to functional modules; Specifically, divide the project source code into different modules according to its functions and responsibilities, create folders, and place these modules in the corresponding folders or directories.
[0025] Exemplarily, create folders such as SCADE_src, OGLX_lib, APP_IF_lib, USE_lib, HW_Interface, etc. to store function files. Among them: SCADE_src folder: used to store the SCADE code generated by SCADE Display Kcg and handwritten functions.
[0026] OGLX_lib folder: used to store external dependency functions such as lib libraries that SCADE can use. The content of the folder has two categories, one is header files and source files, and the other is the generated lib static libraries.
[0027] APP_IF_lib folder: used to store the interface functions between the application and SCADE.
[0028] Use_lib folder: used to store the relevant code for implementing each function, and can be further divided into multiple sub-folders according to the specific requirements of the project. Each sub-folder is used for a specific type of function or task, such as data processing, display, implementation of a single function, service functions, general functions, Ethernet interface, and use of the multi-threaded (pthread) library, etc. Which sub-folders to create can be selected according to the specific requirements of the project.
[0029] HW_Interface folder: the hardware interface folder, used for low-level hardware-related code, such as UDP, CAN, MVB, Uart, etc. Since not every project needs to handle all hardware interfaces, the HW_Interface folder should be created according to the actual project requirements.
[0030] As a preferred embodiment of the present disclosure, determining the project basic information further includes: S114, determining the minimum version of CMake. Different CMake versions provide different function supports. Some new function features may only be available in newer CMake versions. Therefore, it is necessary to ensure that the CMake version used is not lower than the specific requirements.
[0031] S12, determining the build environment; By determining the build environment, ensure that the project can be compiled and run correctly and efficiently on the target platform.
[0032] S121, determining the current operating system type; CMake is a cross-platform automated build system that has built-in support for multiple operating systems and provides some built-in variables to automatically detect the current operating system type (such as Windows, Linux, etc.). Specifically, a variable named SUBDIR is dynamically set according to the type of operating system being run, and corresponding information is output through CMake commands. This information is used to inform the user of the configuration status of the current operating system. Exemplarily, if the current operating system is detected to be Windows, then SUBDIR will be set to "Windows", and a message will be output to tell the user that it is configuring for the Windows system using the Windows subdirectory.
[0033] There are differences in library support, system calls, file path formats, etc. among different operating systems. Therefore, determining the operating system type provides a basis for subsequent configuration of CMake build files.
[0034] S122. Determine the output paths of the executable file and the library; The output paths of the executable file and the library affect the storage location of the generated files after compilation. By determining the output paths, the project becomes easier to manage and maintain.
[0035] S13. Determine the include path and library files of the thread library according to the build environment; Specifically, determine the include path and library files of the thread library according to the current operating system type.
[0036] S14. Create libraries and add corresponding header files and source files for each library; The creation of libraries not only simplifies the compilation process but also improves the code reusability and modularity. The process of creating libraries involves organizing relevant source files together and defining the dependencies between them. By specifying the correct header file search paths for each library, it ensures that other parts of the code can successfully reference the functions provided by these libraries, while avoiding unnecessary repeated compilation and improving the overall development efficiency.
[0037] S15. Select the corresponding OGLX library for linking according to the build environment; Specifically, select the corresponding OGLX library for linking according to the current operating system type. Since different operating systems may support different versions or implementations of OpenGL, it is necessary to dynamically select the corresponding OGLX library for linking according to the current operating system type.
[0038] S2. Compile the project source files based on the local build system files to obtain the target files; After CMake finishes parsing the CMake configuration file and generating the local build system file, the actual compilation phase follows. During this process, the build tool reads the generated local build system file (such as a Makefile) and then processes the source code files according to the set rules. Each source file is compiled individually into a corresponding object file. Object files are intermediate products in the build process and provide the basis for subsequent linking steps.
[0039] S3. Link libraries into the object files to obtain an executable file. Among them, the library types include internal libraries and external libraries.
[0040] The linking phase is the process of merging all object files and the required libraries into a complete executable file. It should be further noted that for Windows applications using dynamic link libraries (DLLs), it is also necessary to ensure that these DLL files can be correctly loaded at runtime, which means they should be placed in a location where the operating system can find them. Therefore, specific dynamic link library (DLL) files need to be copied to the output path of the executable file (exe).
[0041] Different from Makefile which does not clearly distinguish between configuration and build instructions, CMake strictly separates these two processes: First, generate platform-specific local build system files through pre-written CMake configuration files, and then use these generated local build system files for actual compilation and linking, enhancing the adaptability to different build environments.
[0042] Compared with Makefile whose functions are relatively limited and mainly rely on simple rules and dependency handling and cannot meet more advanced requirements, CMake provides a rich set of functions, including conditional judgment, loop structures, variable operations, etc., enabling it to build more complex build systems.
[0043] Refer to Figure 2 As shown, based on the same inventive concept, the present disclosure also proposes a cross-platform Display software build system based on CMake, including: A parsing module 110, configured to respond to a CMake command, read and parse a pre-written CMake configuration file, and generate a local build system file; A compilation module 120, configured to compile project source files based on the build system file to obtain object files; A linking module 130, configured to link libraries into the object files to obtain an executable file.
[0044] Refer to Figure 3As shown, based on the same inventive concept, the present disclosure also provides a device, including a memory and a processor. A computer instruction capable of running on the processor is stored on the memory. When the processor runs the computer instruction, it executes the above-mentioned method for constructing a cross-platform Display software based on CMake.
[0045] Based on the same inventive concept, the present disclosure also provides a computer-readable storage medium, on which a computer instruction is stored. When the computer instruction runs, the above-mentioned method for constructing a cross-platform Display software based on CMake can be implemented.
[0046] Among them, any reference to a memory, storage, database or other medium used in the embodiments provided by the present invention may include non-volatile and / or volatile memories. The non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. The volatile memory may include random access memory (RAM) or an external cache memory.
[0047] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.
[0048] Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for constructing cross-platform Display software based on CMake, characterized in that: include: In response to CMake commands, read and parse pre-written CMake configuration files to generate local build system files; Compile the project source file based on the local build system file to obtain the target file; Link the library to the target file to obtain an executable file.
2. According to the method for constructing cross-platform Display software based on CMake in claim 1, it is characterized in that: The parsing of the pre-written CMake configuration file includes: Determine the basic information of the project; Determine the build environment; Determine the include path and library file of the thread library according to the construction environment; Create libraries and add corresponding header files and source files for each library; According to the construction environment, select the corresponding OGLX library for linking.
3. The method for constructing cross-platform Display software based on CMake according to claim 2, characterized in that: The basic information of the project is determined, including: Determine the project name; Add preprocessor definitions; Organize the project source code into functional modules.
4. The method for constructing cross-platform Display software based on CMake according to claim 3, characterized in that: The determining of the basic project information further includes: determining a minimum version of CMake.
5. The method for constructing cross-platform Display software based on CMake according to claim 2, characterized in that: The determining of the construction environment includes: Determine the current operating system type; Determines the output path for executables and libraries.
6. The method for constructing cross-platform Display software based on CMake according to claim 1, characterized in that: The library types include internal libraries and external libraries.
7. The method for constructing cross-platform Display software based on CMake according to claim 5, characterized in that: If the type of the operating system is Windows, the corresponding DLL file is copied to the output path of the executable file.
8. A cross-platform Display software construction system based on CMake, characterized in that: include: The parsing module is used to respond to CMake commands, read and parse pre-written CMake configuration files, and generate local build system files; A compiling module, used to compile the project source file based on the build system file to obtain the target file; The link module is used to link the library to the target file to obtain an executable file.
9. A device comprising a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, characterized in that: When the processor runs the computer instructions, it executes the method for building cross-platform Display software based on CMake as described in any one of claims 1 to 7.
10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed, the method for constructing cross-platform Display software based on CMake as described in any one of claims 1 to 7 can be implemented.
