-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
executable file
·177 lines (147 loc) · 6.13 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
# -*- CMake -*- ---------------------------------------------------------
cmake_minimum_required(VERSION 3.1)
option(INTEL_CC "Use the Intel compiler." OFF)
option(IBM_XL "Use IBM compiler." OFF)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Detect Intel Compiler - Note this needs to be before the project statement to work correctly
if (INTEL_CC)
find_program(CMAKE_C_COMPILER NAMES icc)
find_program(CMAKE_CXX_COMPILER NAMES icpc)
find_program(CMAKE_AR NAMES xiar)
find_program(CMAKE_LINKER NAMES xild)
if (CMAKE_C_COMPILER MATCHES CMAKE_C_COMPILER-NOTFOUND OR
CMAKE_CXX_COMPILER MATCHES CMAKE_CXX_COMPILER-NOTFOUND OR
CMAKE_AR MATCHES CMAKE_AR-NOTFOUND OR
CMAKE_LINKER MATCHES CMAKE_LINKER-NOTFOUND)
message(FATAL_ERROR "Cannot find Intel compiler. You may need to run `. /opt/intel/bin/compilervars.sh intel64'")
endif ()
endif (INTEL_CC)
if (IBM_XL)
find_program(CMAKE_C_COMPILER NAMES xlc)
find_program(CMAKE_CXX_COMPILER NAMES xlc++)
find_program(CMAKE_AR NAMES ar)
find_program(CMAKE_LINKER NAMES ld)
if (CMAKE_C_COMPILER MATCHES CMAKE_C_COMPILER-NOTFOUND OR
CMAKE_CXX_COMPILER MATCHES CMAKE_CXX_COMPILER-NOTFOUND OR
CMAKE_AR MATCHES CMAKE_AR-NOTFOUND OR
CMAKE_LINKER MATCHES CMAKE_LINKER-NOTFOUND)
message(FATAL_ERROR "Cannot find IBM compiler.")
endif ()
endif ()
project(ThreadWorker)
# project version
SET(MAJOR_VERSION 0)
SET(MINOR_VERSION 1)
SET(PATCH_VERSION 0)
SET(PACKAGE_NAME ${PROJECT_NAME})
SET(PACKAGE_TARNAME ${PROJECT_NAME})
SET(CPACK_PACKAGE_VENDOR "UNKNOWN")
SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}" )
SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}" )
SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}" )
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${PROJECT_NAME} ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
ENABLE_TESTING()
SET(${PROJECT_NAME}_LIBS)
SET(${PROJECT_NAME}CUDA_LIBS)
SET(${PROJECT_NAME}HIP_LIBS)
SET(${PROJECT_NAME}_SRCS)
# Add source files
SET(${PROJECT_NAME}_SRCS
src/ThreadWorker.cpp)
OPTION(BUILD_CUDA "Build CUDA Support" ON)
OPTION(BUILD_HIP "Build HIP Support" OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Find CUDA
IF(BUILD_CUDA)
FIND_PACKAGE(CUDA)
MESSAGE(STATUS "CUDA found in : " ${CUDA_TOOLKIT_INCLUDE})
IF(CUDA_FOUND)
INCLUDE_DIRECTORIES ( ${CUDA_TOOLKIT_INCLUDE} )
LIST(APPEND ${PROJECT_NAME}CUDA_LIBS ${CUDA_CUDART_LIBRARY} )
ENDIF(CUDA_FOUND)
ENDIF()
# Search for rocm in common locations
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
if(BUILD_HIP)
find_package(hip REQUIRED)
endif()
# Add shared library target
ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRCS})
# change lib_target properties
SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES
# create *nix style library versions + symbolic links
VERSION ${MAJOR_VERSION}
SOVERSION ${MAJOR_VERSION}
# allow creating static and shared libs without conflicts
CLEAN_DIRECT_OUTPUT 1
# avoid conflicts between library and binary target names
OUTPUT_NAME ${PROJECT_NAME} )
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LIBS} Threads::Threads)
if(CUDA_FOUND)
add_library(${PROJECT_NAME}CUDA SHARED ${${PROJECT_NAME}_SRCS})
set_target_properties(${PROJECT_NAME}CUDA PROPERTIES COMPILE_FLAGS "-DHAVE_CUDA" )
SET_TARGET_PROPERTIES( ${PROJECT_NAME}CUDA PROPERTIES
# create *nix style library versions + symbolic links
VERSION ${MAJOR_VERSION}
SOVERSION ${MAJOR_VERSION}
# allow creating static and shared libs without conflicts
CLEAN_DIRECT_OUTPUT 1
# avoid conflicts between library and binary target names
OUTPUT_NAME ${PROJECT_NAME}CUDA )
target_link_libraries(${PROJECT_NAME}CUDA ${${PROJECT_NAME}_LIBS} ${${PROJECT_NAME}CUDA_LIBS} Threads::Threads)
INSTALL(TARGETS ${PROJECT_NAME}CUDA DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
EXPORT ${PROJECT_NAME}CUDA-targets)
endif()
if(hip_FOUND)
add_library(${PROJECT_NAME}HIP SHARED ${${PROJECT_NAME}_SRCS})
set_target_properties(${PROJECT_NAME}HIP PROPERTIES COMPILE_FLAGS "-DHAVE_HIP" )
set_target_properties( ${PROJECT_NAME}HIP PROPERTIES
# create *nix style library versions + symbolic links
VERSION ${MAJOR_VERSION}
SOVERSION ${MAJOR_VERSION}
# allow creating static and shared libs without conflicts
CLEAN_DIRECT_OUTPUT 1
# avoid conflicts between library and binary target names
OUTPUT_NAME ${PROJECT_NAME}HIP )
target_link_libraries(${PROJECT_NAME}HIP ${${PROJECT_NAME}_LIBS} ${${PROJECT_NAME}HIP_LIBS} Threads::Threads hip::host)
install(TARGETS ${PROJECT_NAME}HIP DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
EXPORT ${PROJECT_NAME}HIP-targets)
endif()
# install library
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
EXPORT ${PROJECT_NAME}-targets)
# Add files to be installed
INSTALL(FILES src/${PROJECT_NAME}.h DESTINATION include)
#INSTALL(FILES src/${PROJECT_NAME}Version.h DESTINATION include)
INSTALL(FILES CMake/Find${PROJECT_NAME}.cmake DESTINATION .)
INSTALL(EXPORT ${PROJECT_NAME}-targets DESTINATION lib)
# Add Unit Test
ADD_EXECUTABLE(${PROJECT_NAME}Test src/${PROJECT_NAME}Test.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}Test ${PROJECT_NAME})
ADD_TEST(${PROJECT_NAME}Test ${EXECUTABLE_OUTPUT_PATH}/${PROJECT_NAME}Test)
ADD_SUBDIRECTORY(doc)
# Create the ${PROJECT_NAME}Config.cmake file for installation.
CONFIGURE_FILE(${${PROJECT_NAME}_SOURCE_DIR}/CMake/${PROJECT_NAME}Config.cmake.in
${${PROJECT_NAME}_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY IMMEDIATE)
INCLUDE(InstallRequiredSystemLibraries)
SET(CPACK_PACKAGE_LIBRARIES ${PROJECT_NAME})
#set(CPACK_COMPONENTS_ALL applications libraries headers)
INCLUDE(CPack)