| CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) |
| CMAKE_POLICY(VERSION 2.8) |
| |
| IF(NOT Torch_FOUND) |
| FIND_PACKAGE(Torch REQUIRED) |
| ENDIF() |
| |
| 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) |
| INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/select_compute_arch.cmake) |
| ENDIF() |
| 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 THCUNN_INSTALL_LIB_SUBDIR) |
| SET(THCUNN_INSTALL_LIB_SUBDIR "lib" CACHE PATH "THCUNN install library directory") |
| ENDIF() |
| |
| FILE(GLOB src-cuda *.cu) |
| |
| CUDA_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) |
| CUDA_ADD_LIBRARY(THCUNN MODULE ${src-cuda}) |
| |
| IF(MSVC) |
| SET_TARGET_PROPERTIES(THCUNN PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib") |
| ENDIF() |
| |
| INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) |
| TARGET_LINK_LIBRARIES(THCUNN THC TH ${CUDA_cusparse_LIBRARY}) |
| |
| INSTALL(TARGETS THCUNN LIBRARY DESTINATION ${THCUNN_INSTALL_LIB_SUBDIR}) |