forked from zhanghang1989/PyTorch-Encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
77 lines (63 loc) · 2.66 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## ECE Department, Rutgers University
## Email: zhang.hang@rutgers.edu
## Copyright (c) 2017
##
## This source code is licensed under the MIT-style license found in the
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
CMAKE_POLICY(VERSION 2.8)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTorch.cmake)
IF(NOT CUDA_FOUND)
FIND_PACKAGE(CUDA 6.5 REQUIRED)
ENDIF()
# Detect CUDA architecture and get best NVCC flags
IF(NOT COMMAND CUDA_SELECT_NVCC_ARCH_FLAGS OR MSVC)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/select_compute_arch.cmake)
ENDIF()
LIST(APPEND CUDA_NVCC_FLAGS $ENV{TORCH_NVCC_FLAGS})
CUDA_SELECT_NVCC_ARCH_FLAGS(NVCC_FLAGS_EXTRA $ENV{TORCH_CUDA_ARCH_LIST})
LIST(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9.3")
if(CUDA_VERSION VERSION_LESS "8.0")
MESSAGE(STATUS "Found gcc >=5 and CUDA <= 7.5, adding workaround C++ flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES -D_MWAITXINTRIN_H_INCLUDED -D__STRICT_ANSI__")
endif(CUDA_VERSION VERSION_LESS "8.0")
endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9.3")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
IF(MSVC)
LIST(APPEND CUDA_NVCC_FLAGS "-Xcompiler /wd4819")
ADD_DEFINITIONS(-DTH_EXPORTS)
ENDIF()
IF(NOT ENCODING_INSTALL_LIB_SUBDIR)
SET(ENCODING_INSTALL_LIB_SUBDIR "${TORCH_BUILD_DIR}" CACHE PATH "ENCODING install library directory")
SET(ENCODING_INSTALL_INCLUDE_SUBDIR "${TORCH_BUILD_DIR}/include" CACHE PATH "ENCODING install include subdirectory")
ENDIF()
SET(CMAKE_MACOSX_RPATH 1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
FILE(GLOB src-cuda kernel/*.cu)
MESSAGE(STATUS "Torch_INSTALL_INCLUDE:" ${Torch_INSTALL_INCLUDE})
CUDA_INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/kernel
${CMAKE_CURRENT_SOURCE_DIR}/kernel/include
${Torch_INSTALL_INCLUDE}
)
CUDA_ADD_LIBRARY(ENCODING SHARED ${src-cuda})
IF(MSVC)
SET_TARGET_PROPERTIES(ENCODING PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib")
ENDIF()
TARGET_LINK_LIBRARIES(ENCODING
${TH_LIBRARIES}
${CUDA_cusparse_LIBRARY}
)
# Luarocks bug pre-14.04 prevents us from setting it for Lua-Torch
IF(ENCODING_SO_VERSION)
MESSAGE(STATUS "ENCODING_SO_VERSION: ${ENCODING_SO_VERSION}")
SET_TARGET_PROPERTIES(ENCODING PROPERTIES
VERSION ${ENCODING_SO_VERSION}
SOVERSION ${ENCODING_SO_VERSION})
ENDIF(ENCODING_SO_VERSION)
#INSTALL(TARGETS ENCODING LIBRARY DESTINATION ${ENCODING_INSTALL_LIB_SUBDIR})