# cmake: how to use libtorch in my project

**URL:** https://discourse.cmake.org/t/cmake-how-to-use-libtorch-in-my-project/5092
**Category:** Usage
**Created:** [February 23, 2022, 4:57am UTC](https://discourse.cmake.org/t/cmake-how-to-use-libtorch-in-my-project/5092 "2022-02-23T04:57:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [February 23, 2022, 4:57am UTC](https://discourse.cmake.org/t/cmake-how-to-use-libtorch-in-my-project/5092/1 "2022-02-23T04:57:26Z")

</div>

I want to use libtorch in my project.

The libtorch release the debug/release version:

```auto
Download here (Release version):
https://download.pytorch.org/libtorch/cu102/libtorch-win-shared-with-deps-1.10.2%2Bcu102.zip
Download here (Debug version):
https://download.pytorch.org/libtorch/cu102/libtorch-win-shared-with-deps-debug-1.10.2%2Bcu102.zip

```

Both debug/release contain a cmake file. I can seperately use libtorch by provide the libtorch\_dir as: libtorch\_debug/xx/TorchConfig.cmake or libtorch\_release/xx/TorchConfig.cmake.

However, in this way, if I want to switch debug to release in vs, I need to cmake again.

Is it possible to cmake once and switch vs from debug to release?

Any suggestion is appreciated~~~

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 23, 2022, 3:35pm UTC](https://discourse.cmake.org/t/cmake-how-to-use-libtorch-in-my-project/5092/2 "2022-02-23T15:35:21Z")

</div>

When the configuration file changes like that, there’s no way to support it with a single configure. There needs to be a single `TorchConfig.cmake` file which makes both the release and debug builds available (as configuration-specific property values).
