Fixes for object target dependencies
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / cagpu / opencl / CMakeLists.txt
CommitLineData
e5ef0c3a 1# **************************************************************************
2# * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3# * *
4# * Author: The ALICE Off-line Project. *
5# * Contributors are mentioned in the code where appropriate. *
6# * *
7# * Permission to use, copy, modify and distribute this software and its *
8# * documentation strictly for non-commercial purposes is hereby granted *
9# * without fee, provided that the above copyright notice appears in all *
10# * copies and that both the copyright notice and this permission notice *
11# * appear in the supporting documentation. The authors make no claims *
12# * about the suitability of this software for any purpose. It is *
13# * provided "as is" without express or implied warranty. *
14# **************************************************************************
15
16# Module
17set(MODULE AliHLTTPCCAGPUOpenCL)
18
19# AMD APP SDK required for OpenCL tracker; it's using specific
20# extensions (currently) not provided by other vendors.
21# either set cmake variable via "-D$AMDAPPSDKROOT=/path/to/amdappsdkroot"
22# or via environment variable $AMDAPPSDKROOT
23if(NOT AMDAPPSDKROOT)
24 set(AMDAPPSDKROOT $ENV{AMDAPPSDKROOT})
25endif()
26
27if(NOT AMDAPPSDKROOT)
28 message(FATAL_ERROR "AMDAPPSDKROOT not set. Please install AMD APP SDK and set $AMDAPPSDKROOT or disable HLT_OPENCL.")
29endif()
30
31if(NOT "$ENV{GPU_FORCE_64BIT_PTR}" STREQUAL "1")
32 message(FATAL_ERROR "Please set env variable $GPU_FORCE_64BIT_PTR=1, required by HLT OpenCL tracker.")
33endif()
34
35#convenience variables
36set(CAGPUDIR ${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca/cagpu)
37
38# build the OpenCL compile wrapper:
39# -- checks the correct vendor implementation (AMD)
40# -- builds binary code (blob) for the found platform(s)
41add_executable(opencl_compiler ${CAGPUDIR}/makefiles/makefile_opencl_compiler.cpp)
42target_link_libraries(opencl_compiler -L${AMDAPPSDKROOT}/lib/x86_64 amdocl64 OpenCL)
43
44#convenience variables
45set(CL_SRC AliHLTTPCCAGPUTrackerOpenCL.cl )
46set(CL_BIN ${CMAKE_CURRENT_BINARY_DIR}/AliHLTTPCCAGPUTrackerOpenCLCode.bin )
47set(CL_INC
48 -I${AliRoot_SOURCE_DIR}/HLT/BASE
49 -I${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca
50 -I${CAGPUDIR}
51)
52
53# executes OpenCL compiler wrapper to build binary object
54add_custom_command(
55 OUTPUT ${CL_BIN}
56 COMMAND opencl_compiler -output-file ${CL_BIN} ${CL_SRC} -- ${CL_INC} -x clc++
57 MAIN_DEPENDENCY ${CL_SRC}
58)
59
60# make cmake compile the assembler file
61set_source_files_properties(${CAGPUDIR}/makefiles/include.S PROPERTIES LANGUAGE CXX)
62# add proper dependency on included binary code
63set_source_files_properties(${CAGPUDIR}/makefiles/include.S PROPERTIES OBJECT_DEPENDS ${CL_BIN})
64
65# bit of a hack, but otherwise dictionary compilation fails:
66# defines __ROOT__; triggers "ifdef" in source code to circumvent broken cint behaviour with "volatile" keyword
67# not sure why __ROOT__ is used here, could just as well be something else
68set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/G__AliHLTTPCCAGPUOpenCL.cxx PROPERTIES COMPILE_DEFINITIONS "__ROOT__")
69
70# Module include folder
71include_directories(${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca/cagpu/opencl
72 ${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca/makefiles
73 ${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca/cagpu
74 ${AliRoot_SOURCE_DIR}/HLT/TPCLib/tracking-ca
75 )
76
77# Additional include folders in alphabetical order except ROOT
78include_directories(${ROOT_INCLUDE_DIRS}
79 ${AliRoot_SOURCE_DIR}/HLT/BASE
80 ${AMDAPPSDKROOT}/include
81 )
82
83# Sources in alphabetical order
84set(SRCS
85 ${CAGPUDIR}/AliHLTTPCCAGPUTrackerBase.cxx
86 AliHLTTPCCAGPUTrackerOpenCL.cxx
87 ${CAGPUDIR}/makefiles/include.S
88 )
89
90# Headers from sources
91set(HDRS
92 ${CAGPUDIR}/AliHLTTPCCAGPUTrackerBase.h
93 ${CAGPUDIR}/AliHLTTPCCAGPUTrackerCommon.h
94 AliHLTTPCCAGPUTrackerOpenCL.h
95 AliHLTTPCCAGPUTrackerOpenCLInternals.h
96 )
97
98# Generate the dictionary
99# It will create G_ARG1.cxx and G_ARG1.h / ARG1 = function first argument
100get_directory_property(incdirs INCLUDE_DIRECTORIES)
101generate_dictionary("${MODULE}" "${MODULE}LinkDef.h" "${HDRS}" "${incdirs}")
102
103# Generate the ROOT map
104# Dependecies
105set(LIBDEPS ${CUDA_LIBRARIES} cuda)
106generate_rootmap("${MODULE}" "${LIBDEPS}" "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}LinkDef.h")
107
108# Add a library to the project using the specified source files
109add_library(${MODULE} SHARED ${SRCS} G__${MODULE}.cxx)
110#CUDA run-time and driver
111link_directories(${AMDAPPSDKROOT}/lib/x86_64)
112target_link_libraries(amdocl64 OpenCL)
113
114# Additional compilation flags
68aeb13b 115set_target_properties(${MODULE} PROPERTIES COMPILE_FLAGS "")
e5ef0c3a 116
117*# Installation
118install(TARGETS ${MODULE}
119 ARCHIVE DESTINATION lib
120 LIBRARY DESTINATION lib)
121
122install(FILES ${HDRS} DESTINATION include)