forked from dcampora/cl_forward
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
197 lines (169 loc) · 7.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
#################################################################################
# Copyright ©2014 Advanced Micro Devices, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#################################################################################
set( SAMPLE_NAME clpixel )
set( SOURCE_FILES Tools.cpp Logger.cpp KernelInvoker.cpp
GpuPixelSearchByTriplet.cpp IndependentEntrypoint.cpp )
set( EXTRA_FILES Kernel.cl KernelDefinitions.h )
############################################################################
set(CMAKE_SUPPRESS_REGENERATION TRUE)
cmake_minimum_required( VERSION 2.8.0 )
project( ${SAMPLE_NAME} )
if(CMAKE_BUILD_TYPE MATCHES "[Tt][Bb][Bb]")
return( )
endif()
# Auto-select bitness based on platform
if( NOT BITNESS )
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
else()
set(BITNESS 32)
endif()
endif()
# Select bitness for non-msvc platform. Can be specified as -DBITNESS=32/64 at command-line
if( NOT MSVC )
set(BITNESS ${BITNESS} CACHE STRING "Specify bitness")
set_property(CACHE BITNESS PROPERTY STRINGS "64" "32")
endif()
# Unset OPENCL_LIBRARIES, so that corresponding arch specific libs are found when bitness is changed
unset(OPENCL_LIBRARIES CACHE)
if( BITNESS EQUAL 64 )
set(BITNESS_SUFFIX x86_64)
elseif( BITNESS EQUAL 32 )
set(BITNESS_SUFFIX x86)
else()
message( FATAL_ERROR "Bitness specified is invalid" )
endif()
# Set CMAKE_BUILD_TYPE (default = Release)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
# Set platform
if( NOT UNIX )
set(PLATFORM win)
else()
set(PLATFORM lnx)
endif()
############################################################################
# Find OpenCL include and libs
if("${ACCELERATOR}" STREQUAL NVIDIA)
find_path( OPENCL_INCLUDE_DIRS
NAMES OpenCL/cl.h CL/cl.h
HINTS ../../../../include/ $ENV{NVIDIA_INSTALL_PATH}/include/
$ENV{NVIDIA_INSTALL_PATH}/include/
)
else()
find_path( OPENCL_INCLUDE_DIRS
NAMES OpenCL/cl.h CL/cl.h
HINTS ../../../../include/ $ENV{AMDAPPSDKROOT}/include/
$ENV{NVIDIA_INSTALL_PATH}/include/
)
endif()
mark_as_advanced(OPENCL_INCLUDE_DIRS)
if("${ACCELERATOR}" STREQUAL NVIDIA)
find_library( OPENCL_LIBRARIES
NAMES OpenCL
HINTS ../../../../lib/ $ENV{NVIDIA_INSTALL_PATH}/lib64/
PATH_SUFFIXES ${PLATFORM}${BITNESS} ${BITNESS_SUFFIX}
)
else()
find_library( OPENCL_LIBRARIES
NAMES OpenCL
HINTS ../../../../lib/ $ENV{AMDAPPSDKROOT}/lib
PATH_SUFFIXES ${PLATFORM}${BITNESS} ${BITNESS_SUFFIX}
)
endif()
mark_as_advanced( OPENCL_LIBRARIES )
if( OPENCL_INCLUDE_DIRS STREQUAL "" OR OPENCL_LIBRARIES STREQUAL "")
message( FATAL_ERROR "Could not locate OpenCL include & libs" )
endif( )
############################################################################
# Tweaks for cygwin makefile to work with windows-style path
if( CYGWIN )
set( PATHS_TO_CONVERT
OPENCL_INCLUDE_DIRS
OPENCL_LIBRARIES
)
foreach( pathVar ${PATHS_TO_CONVERT} )
# Convert windows paths to cyg linux absolute path
execute_process( COMMAND cygpath -ua ${${pathVar}}
OUTPUT_VARIABLE ${pathVar}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endforeach( pathVar )
endif( )
############################################################################
set( COMPILER_FLAGS " " )
set( LINKER_FLAGS " " )
set( ADDITIONAL_LIBRARIES "" )
file(GLOB INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h" )
if("${ACCELERATOR}" STREQUAL NVIDIA)
include_directories( ${OPENCL_INCLUDE_DIRS} ../../../../include/SDKUtil $ENV{NVIDIA_INSTALL_PATH}/include )
else()
include_directories( ${OPENCL_INCLUDE_DIRS} ../../../../include/SDKUtil $ENV{AMDAPPSDKROOT}/include/SDKUtil )
endif()
add_executable( ${SAMPLE_NAME} ${SOURCE_FILES} ${INCLUDE_FILES} ${EXTRA_FILES})
# gcc/g++ specific compile options
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set( COMPILER_FLAGS "${COMPILER_FLAGS} -msse2 " )
# Note: "rt" is not present on mingw
if( UNIX )
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set( COMPILER_FLAGS " -g " )
endif( )
set( ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} "rt" )
endif( )
if( BITNESS EQUAL 32 )
set( COMPILER_FLAGS "${COMPILER_FLAGS} -m32 " )
set( LINKER_FLAGS "${LINKER_FLAGS} -m32 " )
else( )
set( COMPILER_FLAGS "${COMPILER_FLAGS} -m64 " )
set( LINKER_FLAGS "${LINKER_FLAGS} -m64 " )
endif( )
set( LINKER_FLAGS "${LINKER_FLAGS} ${EXTRA_LINKER_FLAGS_GXX} " )
set( ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} ${EXTRA_LIBRARIES_GXX} )
elseif( MSVC )
# Samples can specify additional libs/flags using EXTRA* defines
add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo" )
set( COMPILER_FLAGS "${COMPILER_FLAGS} ${EXTRA_COMPILER_FLAGS_MSVC} " )
set( LINKER_FLAGS "${LINKER_FLAGS} ${EXTRA_LINKER_FLAGS_MSVC} /SAFESEH:NO ")
set( ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} ${EXTRA_LIBRARIES_MSVC} )
endif( )
set( COMPILER_FLAGS "${COMPILER_FLAGS} ${EXTRA_COMPILER_FLAGS_GXX} -std=c++11 " )
set_target_properties( ${SAMPLE_NAME} PROPERTIES
COMPILE_FLAGS ${COMPILER_FLAGS}
LINK_FLAGS ${LINKER_FLAGS}
)
target_link_libraries( ${SAMPLE_NAME} ${OPENCL_LIBRARIES} ${ADDITIONAL_LIBRARIES} )
# Set output directory to bin
if( MSVC )
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BITNESS_SUFFIX})
else()
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BITNESS_SUFFIX}/${CMAKE_BUILD_TYPE})
endif()
# Copy extra files to binary directory
foreach( extra_file ${EXTRA_FILES} )
add_custom_command(
TARGET ${SAMPLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${extra_file} ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${extra_file} ./
)
endforeach( extra_file )
# Group sample based on FOLDER_GROUP defined in parent folder
if( FOLDER_GROUP )
set_target_properties(${SAMPLE_NAME} PROPERTIES FOLDER ${FOLDER_GROUP})
endif( )