diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-06-02 10:14:39 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2023-06-12 12:18:41 +0200 |
commit | 9ce21fcde4a46c5bc1fa9adafd343812426e3962 (patch) | |
tree | 9882fd108ce63a71cfb0e7594a045070f3235af2 /doc/consume-cmake-libraries.org | |
parent | 3a902b7adedd380972c64d9a3c152e40b0dd302a (diff) | |
download | rules-cc-9ce21fcde4a46c5bc1fa9adafd343812426e3962.tar.gz |
doc: Convert docs to markdown
Diffstat (limited to 'doc/consume-cmake-libraries.org')
-rw-r--r-- | doc/consume-cmake-libraries.org | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/doc/consume-cmake-libraries.org b/doc/consume-cmake-libraries.org deleted file mode 100644 index 4aa75b6..0000000 --- a/doc/consume-cmake-libraries.org +++ /dev/null @@ -1,137 +0,0 @@ -* Consume CMake Libraries - -To support libraries built with CMake to be consumed by JustBuild, the rule -~["CC/foreign/cmake", "library"]~ can be used. This rule will run CMake and -collect the library's artifacts, public headers, and pkg-config files (if -available), to produce a proper JustBuild library target. - -In this example, we show how to consume the ~gtest~ library built with CMake -using JustBuild. - -** Example: Build the ~gtest~ Library with CMake - -First make sure that ~just~, ~just-mr~, and ~just-import-git~ are available in -your ~PATH~. Then, define a new workspace by creating a ~ROOT~ marker. - -#+BEGIN_SRC sh -$ touch ROOT -#+END_SRC - -To define a repository for the -[[https://github.com/google/googletest/tree/v1.13.0][gtest]] library, create the -following ~repos.template.json~ file. - -#+SRCNAME: repos.template.json -#+BEGIN_SRC js -{ "main": "tests" -, "repositories": - { "imports": {"repository": {"type": "file", "path": "imports"}} - , "gtest": - { "repository": - { "type": "git" - , "branch": "v1.13.0" - , "commit": "b796f7d44681514f58a683a3a71ff17c94edb0c1" - , "repository": "https://github.com/google/googletest" - } - , "target_root": "imports" - , "target_file_name": "gtest.TARGETS" - , "bindings": {"rules": "rules-cc"} - } - , "tests": - { "repository": {"type": "file", "path": "."} - , "bindings": {"rules": "rules-cc", "gtest": "gtest"} - } - } -} -#+END_SRC - -Now the missing ~rules-cc~ repository can be imported via: - -#+BEGIN_SRC sh -$ just-import-git -C repos.template.json --as rules-cc -b master https://github.com/just-buildsystem/rules-cc > repos.json -$ -#+END_SRC - -Create the file ~imports/gtest.TARGETS~ with the following content. - -#+SRCNAME: imports/gtest.TARGETS -#+BEGIN_SRC js -{ "gtest_main": - { "type": ["@", "rules", "CC/foreign/cmake", "library"] - , "name": ["gtest_main"] - , "version": ["1", "13", "0"] - , "project": [["TREE", null, "."]] - , "defines": ["BUILD_SHARED_LIBS=ON"] - , "out_hdr_dirs": ["gtest"] - , "out_libs": ["libgtest_main.so.1.13.0", "libgtest.so.1.13.0"] - , "pkg-config": ["gtest_main.pc", "gtest.pc"] - } -} -#+END_SRC - -The library ~gtest_main~ uses the rule ~["CC/foreign/cmake", "library"]~. It -sets ~defines~ to build shared libraries and collects the public header -directory ~gtest~, as well as the two libraries ~libgtest_main.so.1.13.0~ and -~libgtest.so.1.13.0~ (in this particular link order). Furthermore, to -automatically infer public compile and link flags (e.g., a link dependency to -the system's ~pthread~ library), the pkg-config files ~gtest_main.pc~ and -~gtest.pc~ are read, with the former (entry point) depending on the latter. - -Now, create the actual ~test~ target, which consumes the ~gtest_main~ library, -by creating the following ~TARGETS~ file. - -#+SRCNAME: TARGETS -#+BEGIN_SRC js -{ "test": - { "type": ["@", "rules", "CC/test", "test"] - , "name": ["test"] - , "srcs": ["test.cpp"] - , "private-deps": [["@", "gtest", "", "gtest_main"]] - } -} -#+END_SRC - -The last file missing yet is the actual test source file ~test.cpp~. - -#+SRCNAME: test.cpp -#+BEGIN_SRC cpp -#include <gtest/gtest.h> - -TEST(CastTest, double) { - EXPECT_EQ (42.0, double(42)); -} -#+END_SRC - -Finally, build the ~test~ target to run the test. - -#+BEGIN_SRC sh -$ just-mr build test -Pstdout -INFO: Requested target is [["@","tests","","test"],{}] -INFO: Analysed target [["@","tests","","test"],{}] -INFO: Export targets found: 0 cached, 0 uncached, 0 not eligible for caching -INFO: Target tainted ["test"]. -INFO: Discovered 7 actions, 2 trees, 3 blobs -INFO: Building [["@","tests","","test"],{}]. -INFO: Processed 7 actions, 0 cache hits. -INFO: Artifacts built, logical paths are: - result [7ef22e9a431ad0272713b71fdc8794016c8ef12f:5:f] - stderr [8b137891791fe96927ad78e64b0aad7bded08bdc:1:f] - stdout [fc46e9e95a8a393e3c94875d66b0de956305f6a6:728:f] - time-start [93887fee067665917f67e2cb757dd30bf22b23a0:11:f] - time-stop [93887fee067665917f67e2cb757dd30bf22b23a0:11:f] - (1 runfiles omitted.) -Running main() from src/gtest_main.cc -[==========] Running 1 test from 1 test suite. -[----------] Global test environment set-up. -[----------] 1 test from CastTest -[ RUN ] CastTest.double -[ OK ] CastTest.double (0 ms) -[----------] 1 test from CastTest (0 ms total) - -[----------] Global test environment tear-down -[==========] 1 test from 1 test suite ran. (0 ms total) -[ PASSED ] 1 test. - -INFO: Target tainted ["test"]. -$ -#+END_SRC |