You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The files in this directory are for documentation only. In the current file/directory configuration they cannot be used as a `build2` project. Use `bdep new` to create a proper project and replace the files where necessary. See [../package_managers.md#build2] for details.
- :octicons-tag-24: Available versions: current version and older versions since `3.7.3` (see [cppget.org](https://cppget.org/nlohmann-json))
712
-
- :octicons-rocket-24: The package is maintained and published by the community in [this the repository][(https://github.com/conan-io/conan-center-index/tree/master/recipes/nlohmann_json](https://github.com/build2-packaging/nlohmann-json/)).
712
+
- :octicons-rocket-24: The package is maintained and published by the `build2` community in [this the repository][(https://github.com/conan-io/conan-center-index/tree/master/recipes/nlohmann_json](https://github.com/build2-packaging/nlohmann-json/)).
713
713
- :octicons-file-24: File issues at the [package source repository](https://github.com/build2-packaging/nlohmann-json/issues/)
Note: [`build2`](https://build2.org) should not be considered as a standalone package-manager. It is a build-system + package manager + project manager, a set of tools that work hand-in-hand. `build2`-based projects do not rely on existing `CMake` scripts and the build scripts defining the project's targets are specific to `build2`.
717
+
716
718
To use this package in an exising [`build2`](https://build2.org) project, the general steps are:
717
719
718
-
0. <details><summary>Make the package available to download from a package repository that provides it.</b></summary>
720
+
1. <details><summary>Make the package available to download from a package repository that provides it.</b></summary>
719
721
720
722
Your project's `repositories.manifest` specifies where the package manager will try to acquire packages by default. Make sure one of the repositories specified in this file provides `nlhomann-json` package.
721
723
The recommended open-source repository is [`cppget.org`](https://cppget.org/).
@@ -728,7 +730,7 @@ To use this package in an exising [`build2`](https://build2.org) project, the ge
728
730
```
729
731
</details>
730
732
731
-
1. <details><summary>Add this package as dependency of your project.</summary>
733
+
2. <details><summary>Add this package as dependency of your project.</summary>
732
734
733
735
In your project's `manifest` add the dependency to the package, like `depends: nlohmann-json`, probably with some [version constraints](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml#guide-add-remove-deps).
734
736
For example, to depend on the latest `3.x` version available:
@@ -738,12 +740,12 @@ To use this package in an exising [`build2`](https://build2.org) project, the ge
738
740
</details>
739
741
740
742
741
-
2. <details><summary>Add this library (from the package) as dependency of your target that uses it.</summary>
743
+
2. <details><summary>Add this library as dependency of your target that uses it.</summary>
742
744
743
745
In the `buildfile` defining the target that will use this library:
744
-
- import the target from the `nlhomann-json` package, for example:
746
+
- import the target `lib{json}` from the `nlhomann-json` package, for example:
745
747
```
746
-
import nljson = nlhomann-json%json
748
+
import nljson = nlhomann-json%lib{json}
747
749
```
748
750
- add the library's target as requirement for your target using it, for example:
749
751
```
@@ -753,7 +755,7 @@ To use this package in an exising [`build2`](https://build2.org) project, the ge
753
755
754
756
3. <details><summary>Use the library in your project's code and build it.</summary>
755
757
756
-
At this point, any `b` or `bdep update` command that will update/build the project will also acquire the missing dependency automatically, then build it and link it with your target.
758
+
At this point, assuming your project is initialized in a build-configuration, any `b` or `bdep update` command that will update/build the project will also acquire the missing dependency automatically, then build it and link it with your target.
757
759
758
760
If you just want to trigger the dependencies synchronization for all your configurations:
759
761
```
@@ -762,15 +764,90 @@ To use this package in an exising [`build2`](https://build2.org) project, the ge
762
764
</details>
763
765
764
766
??? example "Example: from scratch, using `build2`'s [`bdep new` command](https://build2.org/bdep/doc/bdep-new.xhtml)"
765
-
```
766
-
# create a simple executable project from scratch, with a simplfied directory layout, using `.hpp/.cpp` file extensions:
767
-
bdep new example -exe,no-subdirs,no-tests -l c++,cpp
768
767
769
-
```
768
+
1. Create a new executable project "example" (see [`bdep new` command details](https://build2.org/bdep/doc/bdep-new.xhtml) for the various options to create a new project):
770
769
771
-
```shell
772
-
bdep new -t exe -l c++
773
-
```
770
+
```shell
771
+
bdep new example
772
+
```
773
+
774
+
2. Enable acquiring packages from https://cppget.org by uncommenting these lines in `example/repositories.manifest`:
775
+
776
+
```make
777
+
:
778
+
role: prerequisite
779
+
location: https://pkg.cppget.org/1/stable
780
+
```
781
+
782
+
Your `example/manifest` should now look like this:
783
+
784
+
```make title="project's `repositories.manifest`"
785
+
--8<-- "integration/build2/repositories.manifest"
786
+
```
787
+
788
+
3. Add any available `3.x` version of the `nlohmann-json` package as dependency to the project by adding this line to `example/manifest`:
789
+
790
+
```make
791
+
depends: nlohmann-json ^3.0.0
792
+
```
793
+
794
+
Your `example/manifest` should now look like this:
795
+
796
+
```make title="project's `manifest`"
797
+
--8<-- "integration/build2/manifest"
798
+
```
799
+
800
+
4. In `example/example/buildfile`, import the library's target to be used as requirement for building the executable target `exe{example}` by replacing the top lines of that file by:
Your `example/example/buildfile` should now look like this:
810
+
811
+
```make title="project's `buildfile`"
812
+
--8<-- "integration/build2/buildfile"
813
+
```
814
+
815
+
5. Initialize the project in a C/C++ build configuration directory that we will create in the same command, with the default C++ build toolchain for simplicity:
816
+
817
+
```shell
818
+
cd example/
819
+
bdep init -C @myconfig cc
820
+
```
821
+
822
+
Note that this will also download the project's dependencies, here the package `nlhomann-json` into the newly created build configuration directory `example-myconfig/`.
823
+
824
+
6. Replace the C++ source code in `example/example/example.cxx` by this code:
825
+
826
+
```cpp title="example.cxx"
827
+
--8<-- "integration/build2/example.cpp"
828
+
```
829
+
830
+
7. Build the project by using [`b`](https://build2.org/build2/doc/b.xhtml) or [`bdep update`](https://build2.org/bdep/doc/bdep.xhtml):
831
+
832
+
```shell
833
+
# in example/
834
+
b
835
+
```
836
+
837
+
This should generate the executable in `example-myconfig/example/example/` and add a symbolic link to it in `example/example/`.
838
+
839
+
- If you want to be able to test that executable's output is correct, you can use build2's executable testing tooling `tescript` by changing the content of `example/example/testscript` to this code:
840
+
841
+
```cpp title="`testscript` checking the output of the program"
842
+
--8<-- "integration/build2/testscript"
843
+
```
844
+
845
+
Then run [`b test`](https://build2.org/build2/doc/b.xhtml) or [`bdep test`](https://build2.org/bdep/doc/bdep.xhtml) to automatically check the program's output. Assuming that the c++ code above didnt change, it should not fail as long as the library outputs the expected json format.
0 commit comments