forked from gpufit/Gpufit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
207 lines (170 loc) · 6.43 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Levenberg Marquardt curve fitting in CUDA
# https://github.com/gpufit/Gpufit
# see also CMake configuration in /docs/installation.rst
# CMake
cmake_minimum_required( VERSION 3.11 )
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
if( NOT PROJECT_NAME )
project( Gpufit VERSION 1.2.0 )
include( CTest )
endif()
if( NOT CMAKE_CXX_STANDARD )
set( CMAKE_CXX_STANDARD 14 )
endif()
if( MSVC ) # link runtime statically with MSVC
foreach( type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} )
string( TOUPPER ${type} TYPE )
foreach( flags CMAKE_C_FLAGS_${TYPE} CMAKE_CXX_FLAGS_${TYPE} )
get_property( help CACHE ${flags} PROPERTY HELPSTRING )
string( REPLACE "/MD" "/MT" ${flags} "${${flags}}" )
set( ${flags} "${${flags}}" CACHE STRING "${help}" FORCE )
endforeach()
endforeach()
endif()
function( add_launcher target executable arguments working_directory )
if( MSVC12 OR MSVC14 )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${target}.vcxproj.user
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
" <PropertyGroup>\n"
" <LocalDebuggerCommand>${executable}</LocalDebuggerCommand>\n"
" <LocalDebuggerCommandArguments>${arguments}</LocalDebuggerCommandArguments>\n"
" <LocalDebuggerWorkingDirectory>${working_directory}</LocalDebuggerWorkingDirectory>\n"
" </PropertyGroup>\n"
"</Project>\n"
)
endif()
endfunction()
# Default values
# Set the default value for the CUDA architecture flag
set( DEFAULT_CUDA_ARCH All )
# Set the default value for the USE_CUBLAS flag. Valid values are "ON" or "OFF".
set( DEFAULT_USE_CUBLAS OFF )
# Set the default value for the precision
set( DEFAULT_DOUBLE_PRECISION OFF )
# Precision
#set( DOUBLE_PRECISION ${DEFAULT_DOUBLE_PRECISION} )
if( DEFINED DOUBLE_PRECISION AND DOUBLE_PRECISION)
add_definitions( -DGPUFIT_DOUBLE )
endif()
# Boost
find_package( Boost 1.58.0 )
if( Boost_FOUND )
function( add_boost_test modules name )
string( REPLACE ";" "_" prefix "${modules}" )
set( target ${prefix}_Test_${name} )
add_executable( ${target} ${name}.cpp
${PROJECT_SOURCE_DIR}/tests/utils.h
${PROJECT_SOURCE_DIR}/tests/utils.cpp
)
target_include_directories( ${target} PRIVATE ${PROJECT_SOURCE_DIR} )
target_link_libraries( ${target} ${modules} Boost::boost )
set_property( TARGET ${target}
PROPERTY RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" )
set_property( TARGET ${target} PROPERTY FOLDER Tests )
add_test( NAME ${target}
COMMAND ${target} --build_info --log_level=all --report_level=detailed )
endfunction()
else()
set( BUILD_TESTING OFF )
message( WARNING "Boost NOT found - skipping tests! (set BOOST_ROOT manually)" )
endif()
# MATLAB
find_package( Matlab COMPONENTS MX_LIBRARY )
if( Matlab_FOUND )
find_program( Matlab_EXECUTABLE matlab
PATHS "${Matlab_ROOT_DIR}/bin" PATH_SUFFIXES win32 win64 NO_DEFAULT_PATH )
function( add_matlab_launcher target )
set( paths "${CMAKE_BINARY_DIR}/$(Configuration)" ${ARGN} )
list( GET paths -1 working_directory )
string( REPLACE ";" "','" paths "${paths}" )
set( arguments "-r addpath('${paths}');addpath(genpath(pwd))" )
add_launcher( ${target} "${Matlab_EXECUTABLE}" "${arguments}" "${working_directory}" )
endfunction()
endif()
# Python
find_package( PythonInterp )
if( PYTHONINTERP_FOUND )
function( add_python_launcher target )
set( paths "${CMAKE_BINARY_DIR}/$(Configuration)" ${ARGN} )
list( GET paths -1 working_directory )
string( REPLACE ";" "')\nsys.path.append('" paths "${paths}" )
set( arguments "-i -c \"import sys\nsys.path.append('${paths}')\"" )
add_launcher( ${target} "${PYTHON_EXECUTABLE}" "${arguments}" "${working_directory}" )
endfunction()
endif()
# Documentation (Latex->PDF)
find_package( LATEX COMPONENTS PDFLATEX )
if( LATEX_PDFLATEX_FOUND )
set( latex_manual_directory "${CMAKE_SOURCE_DIR}/docs/_build/latex" )
# run latex two times to get the references right
add_custom_target( DOCUMENTATION_PDFLATEX
COMMAND ${CMAKE_COMMAND} -E
chdir ${latex_manual_directory} "${PDFLATEX_COMPILER}" -interaction=nonstopmode Gpufit.tex
COMMAND ${CMAKE_COMMAND} -E
chdir ${latex_manual_directory} "${PDFLATEX_COMPILER}" -interaction=nonstopmode Gpufit.tex
COMMENT "Converting documentation to PDF"
)
set_property( TARGET DOCUMENTATION_PDFLATEX PROPERTY FOLDER CMakePredefinedTargets )
else()
message( WARNING "PDFLatex NOT found - cannot convert documentation to PDF!" )
endif()
# Cpufit
add_subdirectory( Cpufit )
# Gpufit
add_subdirectory( Gpufit )
# Examples using Gpufit and Cpufit
add_subdirectory( examples/c++/gpu_vs_cpu_profiling )
# Launcher
#
# Uses the following variables:
#
# Matlab_WORKING_DIRECTORY (Default: user home directory)
# -- Working directory for MATLAB applications using Cpufit and Gpufit.
# Python_WORKING_DIRECTORY (Default: user home directory)
# -- Working directory for Python applications using Gpufit.
if( WIN32 )
file( TO_CMAKE_PATH "$ENV{HOMEPATH}" home )
else()
file( TO_CMAKE_PATH "$ENV{HOME}" home )
endif()
if( Matlab_FOUND )
set( Matlab_WORKING_DIRECTORY "${home}" CACHE PATH "MATLAB working directory" )
if( Matlab_WORKING_DIRECTORY )
add_custom_target( RUN_MATLAB )
set_property( TARGET RUN_MATLAB PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( RUN_MATLAB CpufitMex GpufitMex )
add_matlab_launcher( RUN_MATLAB
"${CMAKE_SOURCE_DIR}/Cpufit/matlab"
"${CMAKE_SOURCE_DIR}/Gpufit/matlab"
"${Matlab_WORKING_DIRECTORY}"
)
endif()
endif()
if( PYTHONINTERP_FOUND )
set( Python_WORKING_DIRECTORY "${home}" CACHE PATH "Python working directory" )
if( Python_WORKING_DIRECTORY )
add_custom_target( RUN_PYTHON )
set_property( TARGET RUN_PYTHON PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( RUN_PYTHON Gpufit )
add_python_launcher( RUN_PYTHON
"${CMAKE_SOURCE_DIR}/Gpufit/python"
"${Python_WORKING_DIRECTORY}"
)
add_custom_target( RUN_PYTHON_CPUFIT )
set_property( TARGET RUN_PYTHON_CPUFIT PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( RUN_PYTHON_CPUFIT Cpufit )
add_python_launcher( RUN_PYTHON_CPUFIT
"${CMAKE_SOURCE_DIR}/Cpufit/python"
"${Python_WORKING_DIRECTORY}"
)
endif()
endif()
# Tests
if( BUILD_TESTING )
add_subdirectory( tests )
endif()
# Package
#set( CPACK_PACKAGE_VERSION ${PROJECT_VERSION} )
#set( CPACK_GENERATOR ZIP )
#include( CPack )