CMakeLists.txt 5.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#---------------------------------------------------
# OpenMM CUDA Platform
#
# Creates OpenMM library, base name=OpenMMCuda.
# Default libraries are shared & optimized. Variants
# are created for static (_static) and debug (_d).
#
# Windows:
#   OpenMMCuda[_d].dll
#   OpenMMCuda[_d].lib
#   OpenMMCuda_static[_d].lib
# Unix:
#   libOpenMMCuda[_d].so
#   libOpenMMCuda_static[_d].a
#----------------------------------------------------

17
18
# Only run tests if this machine has a cuda-capable GPU
# So run a little test program at configuration time to sniff for GPUs
19
# find_package(CUDA) # find_package has already run and causes trouble w/ cmake 2.4
20
21
22
23
24
# message("Checking for working GPU...")
# On Peter E.'s computer, DYLD_LIBRARY_PATH does not include the CUDA path, so in order to 
# get this gpu-sniffer to work, we need to set DYLD_LIBRARY_PATH here.
get_filename_component(CUDART_DIR "${FOUND_CUDART}" PATH)
file(TO_NATIVE_PATH "${CUDART_DIR}" CUDART_NATIVE_DIR)
25
26
27
28
29
30
31
if(APPLE)
        set(ENV{DYLD_LIBRARY_PATH} "$ENV{DYLD_LIBRARY_PATH}:${CUDART_NATIVE_DIR}")
elseif(UNIX)
        set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${CUDART_NATIVE_DIR}")
elseif(MSVC)
        set(ENV{PATH} "$ENV{PATH};${CUDART_NATIVE_DIR}")
endif(APPLE)
32
33
34
35
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
    ${CMAKE_BINARY_DIR} 
    ${CMAKE_CURRENT_SOURCE_DIR}/tests/has_cuda_gpu.c
    CMAKE_FLAGS 
36
37
38
        # -DINCLUDE_DIRECTORIES:STRING=${CUDA_TOOLKIT_INCLUDE}
        # -DLINK_LIBRARIES:STRING=${CUDA_CUDART_LIBRARY}
        -DINCLUDE_DIRECTORIES:STRING=${CUDA_INCLUDE}
39
        -DLINK_LIBRARIES:STRING=${FOUND_CUDART}
40
41
42
    COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR
    RUN_OUTPUT_VARIABLE RUN_OUTPUT_VAR
)
43
# message("${RUN_OUTPUT_VAR}") # Display number of GPUs found
44
# COMPILE_RESULT_VAR is TRUE when compile succeeds
45
# RUN_RESULT_VAR is zero when a GPU is found
46
47
48
49
50
51
52
53
set(CUDA_HAVE_GPU_MAYBE TRUE)
if(NOT COMPILE_RESULT_VAR)
    set(CUDA_HAVE_GPU_MAYBE FALSE)
endif(NOT COMPILE_RESULT_VAR)
if(RUN_RESULT_VAR)
    set(CUDA_HAVE_GPU_MAYBE FALSE)
endif(RUN_RESULT_VAR)
if(CUDA_HAVE_GPU_MAYBE)
54
    set(CUDA_HAVE_GPU TRUE CACHE BOOL "Whether CUDA-capable GPU is present")
55
    # message("GPU check succeeded")
56
else(CUDA_HAVE_GPU_MAYBE)
57
    set(CUDA_HAVE_GPU FALSE CACHE BOOL "Whether CUDA-capable GPU is present")
58
59
60
    message("GPU check failed")
    message("${COMPILE_OUTPUT_VAR}")
    message("${RUN_OUTPUT_VAR}")
61
endif(CUDA_HAVE_GPU_MAYBE)
62
63
64
if(CUDA_HAVE_GPU)
    SUBDIRS (tests)
endif(CUDA_HAVE_GPU)
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(OPENMM_SOURCE_SUBDIRS .)


# Collect up information about the version of the OpenMM library we're building
# and make it available to the code so it can be built into the binaries.

SET(OPENMMCUDA_LIBRARY_NAME OpenMMCuda)

SET(SHARED_TARGET ${OPENMMCUDA_LIBRARY_NAME})
SET(STATIC_TARGET ${OPENMMCUDA_LIBRARY_NAME}_static)


# Ensure that debug libraries have "_d" appended to their names.
# CMake gets this right on Windows automatically with this definition.
IF (${CMAKE_GENERATOR} MATCHES "Visual Studio")
    SET(CMAKE_DEBUG_POSTFIX "_d" CACHE INTERNAL "" FORCE)
ENDIF (${CMAKE_GENERATOR} MATCHES "Visual Studio")

# But on Unix or Cygwin we have to add the suffix manually
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
    SET(SHARED_TARGET ${SHARED_TARGET}_d)
    SET(STATIC_TARGET ${STATIC_TARGET}_d)
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)


# These are all the places to search for header files which are
# to be part of the API.
SET(API_INCLUDE_DIRS) # start empty
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
    # append
    SET(API_INCLUDE_DIRS ${API_INCLUDE_DIRS}
                         ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include 
                         ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include/internal)
ENDFOREACH(subdir)

# We'll need both *relative* path names, starting with their API_INCLUDE_DIRS,
# and absolute pathnames.
SET(API_REL_INCLUDE_FILES)   # start these out empty
SET(API_ABS_INCLUDE_FILES)

FOREACH(dir ${API_INCLUDE_DIRS})
    FILE(GLOB fullpaths ${dir}/*.h)	# returns full pathnames
    SET(API_ABS_INCLUDE_FILES ${API_ABS_INCLUDE_FILES} ${fullpaths})

    FOREACH(pathname ${fullpaths})
        GET_FILENAME_COMPONENT(filename ${pathname} NAME)
        SET(API_REL_INCLUDE_FILES ${API_REL_INCLUDE_FILES} ${dir}/${filename})
    ENDFOREACH(pathname)
ENDFOREACH(dir)

# collect up source files
SET(SOURCE_FILES) # empty
SET(SOURCE_INCLUDE_FILES)

FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
123
    FILE(GLOB_RECURSE src_files  ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c)
124
125
126
127
128
129
130
131
    FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h)
    SET(SOURCE_FILES         ${SOURCE_FILES}         ${src_files})   #append
    SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
    INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)

INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)

132
# SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake)
133

Mark Friedrichs's avatar
Mark Friedrichs committed
134
SUBDIRS (sharedTarget)