All Downloads are FREE. Search and download functionalities are using the official Maven repository.

da-common.0.9.2.source-code.JCudaCommon_CMake.txt Maven / Gradle / Ivy

There is a newer version: 12.0.0
Show newest version
##############################################################################
# Common CMake settings for all JCuda projects
#

set(JCUDA_CUDA_VERSION 9.2)

set(JCUDA_VERSION 0.9.2)

##############################################################################
# Set the CMake module path so that FindCUDA.cmake can be found

set(CMAKE_MODULE_PATH 
  "${CMAKE_CURRENT_LIST_DIR}/CMake"
  ${CMAKE_MODULE_PATH})



##############################################################################
# Find the required packages

if (NOT CUDA_FOUND)
    find_package(CUDA ${JCUDA_CUDA_VERSION} REQUIRED)
    
    # Try to find the NVRTC library, using the CUDA_TOOLKIT_ROOT_DIR
    # as the base directory for the search
    find_library(CUDA_nvrtc_LIBRARY 
        NAMES nvrtc 
        HINTS ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES /lib64 /lib/x64 /targets/x86_64-linux/lib /targets/aarch64-linux/lib)
endif()

if (NOT JNI_FOUND)
    find_package(JNI REQUIRED)
endif()



##############################################################################
# Define the common JNI include directories
    
set(JCudaCommonJNI_INCLUDE_DIRS 
    ${CMAKE_CURRENT_LIST_DIR}/JCudaCommonJNI/src)


##############################################################################
# Determine the host system, and set the JCUDA_OS and JCUDA_ARCH variables. 
# These will be used by the individual library CMake files to build the 
# final library name, e.g. "jcuda-windows-x86_64.dll"

if(CMAKE_HOST_WIN32)
  set(JCUDA_OS "windows")
elseif(CMAKE_HOST_APPLE)
  set(JCUDA_OS "apple")
  set(CMAKE_SKIP_RPATH FALSE)
elseif(CMAKE_HOST_UNIX)
  set(JCUDA_OS "linux")
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc*")
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(JCUDA_ARCH "ppc_64")
  endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(JCUDA_ARCH "aarch64")
  endif()
else()
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(JCUDA_ARCH "x86_64")
  else()
    set(JCUDA_ARCH "x86")
  endif()
endif()


##############################################################################
# Set the output directories for the built libraries: The runtime libraries
# (e.g. the DLLs) will be placed into a directory that later will be picked
# up by the Maven build to generate the JAR that contains the native library.
# This will be done generally for single-configuration compilers, and for 
# all configurations (e.g. RELEASE and MINSIZEREL) for multi-configuration 
# compilers like MSVC. 

set(JCUDA_NATIVE_LIBRARY_DIRECTORY 
    ../nativeLibraries/${JCUDA_OS}/${JCUDA_ARCH}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY 
    ${PROJECT_SOURCE_DIR}/${JCUDA_NATIVE_LIBRARY_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY 
    ${PROJECT_SOURCE_DIR}/${JCUDA_NATIVE_LIBRARY_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
foreach(CONFIGURATION_TYPE ${CMAKE_CONFIGURATION_TYPES})
    string(TOUPPER ${CONFIGURATION_TYPE} CONFIGURATION_TYPE)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} 
        ${PROJECT_SOURCE_DIR}/${JCUDA_NATIVE_LIBRARY_DIRECTORY})
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} 
        ${PROJECT_SOURCE_DIR}/${JCUDA_NATIVE_LIBRARY_DIRECTORY})
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} 
        ${CMAKE_BINARY_DIR}/lib)
endforeach(CONFIGURATION_TYPE CMAKE_CONFIGURATION_TYPES)



##############################################################################
# The compilation on MacOS >=10.11 and above requires additional
# linker flags. In order to detect whether MacOS >=10.11 is present,
# the underlying Darwin version number is checked here (see
# https://en.wikipedia.org/wiki/Darwin_%28operating_system%29)
# If it is greater than 14, then MacOS 10.11 or greater is running.
# The flags are added ONCE, to the CMAKE_SHARED_LINKER_FLAGS variable

if (NOT CMAKE_CUDA_SHARED_LINKER_FLAGS_INITIALIZED)
    if(CMAKE_HOST_APPLE)
        string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" 
            DARWIN_MAJOR_VERSION ${CMAKE_SYSTEM_VERSION})
        if(${DARWIN_MAJOR_VERSION} GREATER 14)    
            set(CMAKE_SHARED_LINKER_FLAGS 
                "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -F/Library/Frameworks -Xlinker -framework -Xlinker CUDA") 
        endif()
    endif()
    set(CMAKE_CUDA_SHARED_LINKER_FLAGS_INITIALIZED "true")
endif()





© 2015 - 2024 Weber Informatics LLC | Privacy Policy