Using Example 1: Integrating json¶
In this document, we will create a Demo that calls the built-in nolhmann/json library from IMakeCore.
nlohmann/json Library¶
The nolhmann/json library is pre-integrated into IMakeCore, so there is no need to download it from the network. We can use this library directly.
Do you remember our ipc tool? This tool can display the nlohmann/json library. Execute the ipc packages command, and the output is as follows:
This is all the libraries integrated into IMakeCore. Here we can see the nlohmann.json library in the output:
The version of the nlohmann.json library is 3.12.0.
This nlohmann.json library is located in the IMakeCore installation directory, as shown below:
IMakeCore currently supports two project management tools: qmake and cmake.
Using IMakeCore with qmake¶
Let's create a new qmake project. This is a simple qmake project with nothing else. Its directory structure is as follows:
The file contents are as follows:
Now we have a default project. Next, we will integrate IMakeCore into this project. There are two ways to integrate IMakeCore: automatic integration and manual integration.
Automatic Integration of IMakeCore¶
The ipc tool has an init subcommand. Open a command-line tool in the directory of the qmake_project.pro file and execute the ipc init command. The command output is as follows:
The last line of the command output, add imake support succeed, indicates that IMakeCore has been integrated into the project. At this point, the project's contents have also changed. Run qmake again, and the project's contents will be updated to:
The directory contents are as follows:
The project contents are as follows:
The project has now integrated the IMakeCore content. Next, let's add the nlohmann.json library to this project. Modify the packages.json file to include the following content:
We have only added one line: "nlohmann.json" : "3.12.0". This integrates the nlohmann.json library into the project.
Run qmake again, and the project will now look like this:
The nlohmann.json library is now in the project.
Manual Integration of IMakeCore¶
In addition to the ipc init command, users can also manually integrate IMakeCore by copying the following content into the project's .pro file:
After running qmake, IMakeCore is also integrated into the project. Subsequently, users can simply add the required libraries in the packages.json file.
Using IMakeCore with CMake¶
Integrating IMakeCore into CMake is the same as with qmake. Users can use the ipc init command or integrate it manually. The content of the CMakeLists.txt file is as follows:
The content for CMake differs from qmake:
Here, the ICMakeCoreInit function requires the project name as an argument.
Except for the differences in CMakeLists.txt, the configuration is consistent with qmake projects and will not be explained further.
Using nlohmann.json¶
Now that IMakeCore integration is complete and the nlohmann.json library is in the project, let's modify the main.cpp file for both the cmake_project and qmake_project as follows:
The content here is not about what is output, but rather the line #include <json.hpp>, which truly integrates the nolhmann.json library. There should be no errors.
The project's output is as follows:
The output is correct.
Download¶
These examples can be downloaded as follows. After downloading, you can compile and run them directly.




