简体   繁体   中英

CMake: specifying build toolchain

Very new to CMake, and so far I'm finding it to be extremely helpful. I have a set of custom libraries that I would like to build for multiple platforms using cross-compilation. The toolchains are installed, and I can hand-create the Makefile s that I need to do so, but I would like to be able to make use of CMake.

Is there a way to tell cmake which toolchain to use, either at the command line or in the CMakeLists.txt file?

Have a look here : basically, you define a "toolchain file" that sets things like the system name, paths to compilers and so on. You then call cmake like so:

cmake /path/to/src -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/foo-bar-baz.cmake

To customize the build settings so you don't have to specify the parameter every time:

For Visual Studio - here

For Vusual Studio Code :

Install the Cmake Tools extension if haven't done so already. In the .vscode/ settings.json file set the parameter cmake.configureArgs . You can also set it from Settings -> CMake Tools configuration -> Add Item . Mine looks like this:

{
    "cmake.configureArgs": [
        "-DCMAKE_TOOLCHAIN_FILE=C:/Users/.../vcpkg/scripts/buildsystems/vcpkg.cmake"
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM