CMakeLists.txt 2.59 KB
Newer Older
1
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
moto's avatar
moto committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# Most of the configurations are taken from PyTorch
# https://github.com/pytorch/pytorch/blob/0c9fb4aff0d60eaadb04e4d5d099fb1e1d5701a9/CMakeLists.txt

# Use compiler ID "AppleClang" instead of "Clang" for XCode.
# Not setting this sometimes makes XCode C compiler gets detected as "Clang",
# even when the C++ one is detected as "AppleClang".
cmake_policy(SET CMP0010 NEW)
cmake_policy(SET CMP0025 NEW)

# Suppress warning flags in default MSVC configuration.  It's not
# mandatory that we do this (and we don't if cmake is old), but it's
# nice when it's possible, and it's possible on our Windows configs.
if(NOT CMAKE_VERSION VERSION_LESS 3.15.0)
  cmake_policy(SET CMP0092 NEW)
endif()

project(torchaudio)

21

moto's avatar
moto committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# check and set CMAKE_CXX_STANDARD
string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard)
if(env_cxx_standard GREATER -1)
  message(
      WARNING "C++ standard version definition detected in environment variable."
      "PyTorch requires -std=c++14. Please remove -std=c++ settings in your environment.")
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Apple specific
if(APPLE)
  # Get clang version on macOS
  execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
  string(REGEX REPLACE "Apple LLVM version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
  message( STATUS "CLANG_VERSION_STRING:         " ${CLANG_VERSION_STRING} )

  # RPATH stuff
  set(CMAKE_MACOSX_RPATH ON)

  set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()


# Options
50
option(BUILD_SOX "Build libsox statically" ON)
moto's avatar
moto committed
51
option(BUILD_KALDI "Build kaldi statically" ON)
52
option(BUILD_RNNT "Enable RNN transducer" ON)
moto's avatar
moto committed
53
option(BUILD_LIBTORCHAUDIO "Build C++ Library" ON)
moto's avatar
moto committed
54
option(BUILD_TORCHAUDIO_PYTHON_EXTENSION "Build Python extension" OFF)
Caroline Chen's avatar
Caroline Chen committed
55
option(USE_CUDA "Enable CUDA support" OFF)
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
option(USE_ROCM "Enable ROCM support" OFF)


# check that USE_CUDA and USE_ROCM are not set at the same time
if(USE_CUDA AND USE_ROCM)
  message(FATAL "CUDA and ROCm are mutually exclusive")
endif()

if(USE_ROCM) 
  # Find the HIP package, set the HIP paths, load the HIP CMake.
  include(cmake/LoadHIP.cmake)
  if(NOT PYTORCH_FOUND_HIP)
    set(USE_ROCM OFF)
  endif()
endif()
Caroline Chen's avatar
Caroline Chen committed
71
72
73
74

if(USE_CUDA)
  enable_language(CUDA)
endif()
moto's avatar
moto committed
75
76
77

find_package(Torch REQUIRED)

moto's avatar
moto committed
78
79
# TORCH_CXX_FLAGS contains the same -D_GLIBCXX_USE_CXX11_ABI value as PyTorch
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${TORCH_CXX_FLAGS}")
moto's avatar
moto committed
80
81
82

add_subdirectory(third_party)
add_subdirectory(torchaudio/csrc)