Repository: pytorch
Issue: Policy CMP0012   is not set, CMake, Building For C++ With PyTorch CUDA
Labels: module: build,triaged,better-engineering

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

## To Reproduce

Steps to reproduce the behavior:

1. Download the PyTorch zip file with the following settings,
PyTorch Build: Stable(1.6.0)
Your OS: Linux
Package: LibTorch
Language: C++/Java
CUDA: 10.2

2. Unzip the folder to some/path/that/goes/here/
3. Add that path to the $PATH variable in order to use CMake
4. Make a new folder with the structure,

```markdown
example-folder/
   CMakeLists.txt
   example-app.cpp
```

Paste the following code for `CMakeLists.txt`, 
```
project(example-app)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET example-app
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:example-app>)
endif (MSVC)
```

Paste the following code for `exampe-app.cpp`,
```
#include <torch/torch.h>
#include <iostream>

int main() {
  torch::Tensor tensor = torch::raned({2, 3});
  std::cout << tensor << std::endl;
}  
```

Then do,
```bash
mkdir build
cd build 
cmake ..
make
./example-app
```

This generates the following logs from CMake,
```
CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:39 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:53 (if):
  if given arguments:

    "NOT" "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:57 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:62 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:67 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /home/saif/Downloads/Libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:89 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.16)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/saif/Downloads/Libraries/Test Files/Pytorch/build
```

Basically, it works and does generate a binary file, but throws some policy errors.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

That there is no policy conflict

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - PyTorch Version (e.g., 1.0): 1.6.0
 - OS (e.g., Linux): Linux
 - How you installed PyTorch (`conda`, `pip`, source): Source
 - Build command you used (if compiling from source): `mkdir build && cd build && cmake .. && make && ./example-app`
 - Python version: `3.8.5`
 - CUDA/cuDNN version: Not available
 - GPU models and configuration: Not available
 - Any other relevant information: Not really, no

## Additional context

Nope

<!-- Add any other context about the problem here. -->


cc @malfet @seemethere @walterddr