-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathCMakeLists.txt
202 lines (177 loc) · 7.2 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
cmake_minimum_required(VERSION 2.8)
#if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# set(ON_LINUX 1)
#endif()
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor")
endif()
if (NOT CMAKE_BUILD_TYPE)
# message("Setting build type to 'Release'")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
OPTION(BUILD_TESTS "Build unit-tests." OFF)
OPTION(DEV_RUN_COG "Only EasyCL maintainers need this, otherwise set to 'OFF'." OFF)
OPTION(PROVIDE_LUA_ENGINE "eg for Torch, we use Torch's engine." ON)
OPTION(USE_CLEW "Use clew, for dynamic runtime linking with opencl." ON)
OPTION(USE_SYSTEM_CLEW "Link to system clew." OFF)
OPTION(BUILD_SHARED "Build shared (cannot turn off without disabling clew." ON)
#set(TYPEDEF_INT64 int64_t CACHE STRING "typedef for int64")
#set(TYPEDEF_UINT64 uint64_t CACHE STRING "typedef for uint64")
add_definitions(-DTYPEDEF_INT64=${TYPEDEF_INT64})
add_definitions(-DTYPEDEF_UINT64=${TYPEDEF_UINT64})
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX
"${CMAKE_CURRENT_SOURCE_DIR}/dist" CACHE PATH "Installation prefix, default 'dist'" FORCE
)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# https://cmake.org/Wiki/CMake_RPATH_handling
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_MACOSX_RPATH TRUE)
if(BUILD_TESTS AND NOT PROVIDE_LUA_ENGINE)
# find_library(Lua51 REQUIRED)
message("Error: if building tests, need to enable PROVIDE_LUA_ENGINE")
endif()
# remove obsolete options, so dont clutter the ccmake config page
unset(INT64_TYPEDEF CACHE)
unset(UINT64_TYPEDEF CACHE)
unset(TYPEDEF_INT64 CACHE)
unset(TYPEDEF_UINT64 CACHE)
unset(LUA_AVAILABLE CACHE)
unset(KERNEL_TEMPLATING CACHE)
unset(CLBLAS_DIR CACHE)
unset(TEST_CLBLAS CACHE)
if(USE_CLEW)
# unset(OpenCL_DIR CACHE)
unset(OPENCL_INCLUDE_DIRS CACHE)
unset(OPENCL_LIBRARIES CACHE)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# include_directories("${CMAKE_INSTALL_PREFIX}/include")
include_directories(thirdparty/lua-5.1.5/src)
set(TEMPLATESRC templates/LuaTemplater.cpp templates/TemplatedKernel.cpp)
set(TEMPLATETESTS test/testLuaTemplater.cpp test/testTemplatedKernel.cpp)
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(USE_CLEW)
if(USE_SYSTEM_CLEW)
include_directories(/usr/include/CL)
# TODO use <CL/clew.h> in the source, clew follows glew style includes
else()
include("${CMAKE_MODULE_PATH}/build_clew.cmake")
include_directories(${clew_INCLUDE_DIRS})
endif()
endif()
if(PROVIDE_LUA_ENGINE)
file(STRINGS thirdparty/lua-5.1.5/files.txt lua_src1)
foreach(source ${lua_src1})
set(lua_src ${lua_src} thirdparty/lua-5.1.5/src/${source})
endforeach()
endif(PROVIDE_LUA_ENGINE)
# add_definitions(-DCL_USE_DEPRECATED_OPENCL_1_0_APIS)
if(BUILD_SHARED)
add_library(EasyCL SHARED EasyCL.cpp CLKernel.cpp CLWrapper.cpp platforminfo_helper.cpp deviceinfo_helper.cpp DevicesInfo.cpp DeviceInfo.cpp
util/easycl_stringhelper.cpp util/StatefulTimer.cpp
${lua_src}
${TEMPLATESRC})
else()
add_library(EasyCL EasyCL.cpp CLKernel.cpp CLWrapper.cpp platforminfo_helper.cpp deviceinfo_helper.cpp DevicesInfo.cpp DeviceInfo.cpp
util/easycl_stringhelper.cpp util/StatefulTimer.cpp
${lua_src}
${TEMPLATESRC})
endif()
if(WIN32)
target_link_libraries(EasyCL winmm) # needed for timeGetTime
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if(USE_CLEW)
add_definitions(-DUSE_CLEW)
target_link_libraries(EasyCL clew)
else()
# find_package(OpenCL REQUIRED)
include("${CMAKE_MODULE_PATH}/FindOpenCL.cmake")
target_link_libraries(EasyCL ${OPENCL_LIBRARIES})
endif()
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
target_link_libraries(EasyCL dl)
endif()
if(NOT PROVIDE_LUA_ENGINE)
IF(APPLE)
SET_TARGET_PROPERTIES(EasyCL PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
ENDIF(APPLE)
else()
IF(APPLE)
SET_TARGET_PROPERTIES(EasyCL PROPERTIES LINK_FLAGS "-single_module")
ADD_DEFINITIONS(-DLUA_USE_LINUX)
ENDIF(APPLE)
endif(NOT PROVIDE_LUA_ENGINE)
add_executable(gpuinfo gpuinfo.cpp platforminfo_helper.cpp deviceinfo_helper.cpp DeviceInfo.cpp DeviceInfo.cpp)
if(USE_CLEW)
# target_link_libraries(gpuinfo ${CLEW_LIBRARIES})
target_link_libraries(gpuinfo clew)
else()
target_link_libraries(gpuinfo ${OPENCL_LIBRARIES})
endif()
if(UNIX)
target_link_libraries(gpuinfo dl)
endif()
if(BUILD_TESTS)
if(UNIX)
add_library(easycl_gtest SHARED thirdparty/gtest/gtest-all.cc)
target_link_libraries(easycl_gtest pthread)
else()
add_library(easycl_gtest thirdparty/gtest/gtest-all.cc)
endif()
add_executable(easycl_unittests test/testscalars.cpp test/testintarray.cpp test/testfloatwrapper.cpp
test/testqueues.cpp test/testclarray.cpp test/testfloatwrapperconst.cpp test/testintwrapper.cpp
test/test_scenario_te42kyfo.cpp
test/testfloatarray.cpp test/testeasycl.cpp test/testinout.cpp test/testintwrapper_huge.cpp
test/testlocal.cpp test/testdefines.cpp test/testbuildlog.cpp test/testnewinstantiations.cpp
test/testucharwrapper.cpp test/testkernelstore.cpp test/testdirtywrapper.cpp test/testDeviceInfo.cpp
${TEMPLATETESTS} test/testStructs.cpp
test/asserts.cpp test/gtest_main.cpp test/GtestGlobals.cpp test/testprofiling.cpp
test/testcopybuffer.cpp test/teststatefultimer.cpp test/testFastRead.cpp
${CLBLAS_TEST_SOURCES})
target_link_libraries(easycl_unittests easycl_gtest EasyCL)
if(USE_CLEW)
target_link_libraries(easycl_unittests clew)
endif(USE_CLEW)
target_include_directories(easycl_unittests PRIVATE thirdparty/gtest)
endif(BUILD_TESTS)
if(DEV_RUN_COG)
add_custom_target(
cog
python ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cogapp/cog.py -q -I ${CMAKE_CURRENT_SOURCE_DIR}/cog-batteries -r ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/templates/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/templates/*.h ${CMAKE_CURRENT_SOURCE_DIR}/util/*.h
)
add_dependencies(EasyCL cog)
endif(DEV_RUN_COG)
INSTALL(TARGETS EasyCL EXPORT EasyCL-targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
FILE(GLOB HEADERS_ROOT *.h)
FILE(GLOB HEADERS_TEMPLATES templates/*.h)
FILE(GLOB HEADERS_UTIL util/*.h)
INSTALL(FILES ${HEADERS_ROOT} DESTINATION include/easycl)
INSTALL(FILES ${HEADERS_TEMPLATES} DESTINATION include/easycl/templates)
INSTALL(FILES ${HEADERS_UTIL} DESTINATION include/easycl/util)
INSTALL(PROGRAMS easycl_activate.sh DESTINATION bin)
INSTALL(EXPORT EasyCL-targets DESTINATION lib/EasyCL)
if(BUILD_TESTS)
INSTALL(FILES ${CLFILES} DESTINATION bin)
INSTALL(TARGETS easycl_gtest easycl_unittests gpuinfo
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
endif(BUILD_TESTS)
########### Add uninstall target ###############
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")