3/31/2023 0 Comments Bazel vs cmake![]() my_project/buildġ/1 Test #1: HelloTest.BasicAssertions. The CXX compiler identification is GNU 10.2.1 The C compiler identification is GNU 10.2.1 Now you can build and run your test: my_project$ cmake -S. Last two lines enable CMake’s test runner to discover the tests included in the You want to build ( hello_test), and links it to GoogleTest ( gtest_main). The above configuration enables testing in CMake, declares the C++ test binary ![]() ) include (GoogleTest ) gtest_discover_tests (hello_test ) ![]() With GoogleTest declared as a dependency, you can use GoogleTest code withinĪs an example, create a file named hello_ in your my_project Hash often to point to the latest version.įor more information about how to create CMakeLists.txt files, see the The Git commit hash of the GoogleTest version to use we recommend updating the The above configuration declares a dependency on GoogleTest which is downloadedįrom GitHub. ) # For Windows: Prevent overriding the parent project's compiler/linker settings set (gtest_force_shared_crt ON CACHE BOOL "" FORCE ) FetchContent_MakeAvailable (googletest ) Naively, we can use a custom cmake rule (addcustomtarget or ExternalProjectAdd) to invoke bazel build for Bar. You’ll use this file to set up your project and declare a dependency onįirst, create a directory for your project:Ĭmake_minimum_required (VERSION 3.14 ) project (my_project ) # GoogleTest requires at least C++14 set (CMAKE_CXX_STANDARD 14 ) include (FetchContent ) FetchContent_Declare ( Project Foo uses cmake for its build system project Bar uses bazel. Set up a projectĬMake uses a file named CMakeLists.txt to configure the build system for a Note: The terminal commands in this tutorial show a Unix shell prompt, but theĬommands work on the Windows command line as well. If you don’t already have CMake installed, see the See Supported Platforms for more information about platforms CMake and a compatible build tool for building the.A compatible C++ compiler that supports at least C++14.You’re using GoogleTest for the first time or need a refresher, we recommend Therefore during the apr_util build the apr build artifacts will be available in the $$EXT_BUILD_DEPS$$/apr.This tutorial aims to get you up and running with GoogleTest using CMake. It is an autotools example, but it does not matter. With rules_foreign_cc you can do something like this: configure_make( However sometimes you want to add some dependency to your cmake_external. Bazel is really serious about it, because such a sneaky dependency can not be tracked, thus you could change something here, and Bazel will not recompile your target With proper sandboxing implementation you can not even read /home/jackshi/projects/third_party/libtorch because that path is not in your deps. a http_archive, then all needed dependencies will be there, and you should not care about it, because that location is removed after the action is finished. When you define BUILD file for your workspace created by for e.g. No, for each action the Bazel setup a whole needed environment using a feature, which is called sandboxing. Just use:ĭeps = how does CMAKE_PREFIX_PATH work when the files are remote, acquired through http_archive, do you use ~/.cache/bazel directory? I am not sure how you did your research, but it looks like your library has a full support for Bazel. It is s a good approach, when there is no other way than calling a CMake You can use rules_foreign_cc, which will run and execute CMake for you. The more you compile from sources the better and more robust your build stack is. That approach is rather bad, because you can not control the build process of this library. To do so just create an ordinary cc_library rule, where you add your compiled libraries *.a as srcs ![]() In Bazel you can use library, which is already built.You do not want to use it here, because it's a CMake way to solve the problem Library, which you want to find does not have to be compilled even in CMake. Therefore there is not necessity for CMake, because it is already compiled.įind_package is a CMake feature, which find already compiled dependency using an algorithm, which search most common install paths. Your link ( ) is not a source code, it's fully compiled library. Can bazel create a target for this package without a top level CMakeList.txt? It should be looking for TorchConfig.cmake right?Īlso, how does CMAKE_PREFIX_PATH work when the files are remote, acquired through http_archive, do you use ~/.cache/bazel directory? This is true, however, when you link it with find_package(Torch REQUIRED), top level CMakeList.txt is not needed. Lib_source = I try to link to it, I get does not appear to contain CMakeList.txt "CMAKE_PREFIX_PATH": "/home/jackshi/projects/third_party/libtorch", I have the following in my WORKSPACE: new_local_repository( To link pytorch c++ library with CMake, you really just need find_package(Torch REQUIRED) and use -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |