-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
132 lines (104 loc) · 5.07 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT (BSim)
FIND_PACKAGE(CUDA REQUIRED)
MESSAGE("CUDA Version: ${CUDA_VERSION}")
FIND_PACKAGE(MPI REQUIRED)
FIND_PACKAGE(BLAS REQUIRED)
#message( STATUS BLAS found: ${BLAS_LIBRARIES} )
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${BLAS_INCLUDE_PATH})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#SET(CMAKE_BUILD_TYPE Debug)
#SET(CMAKE_BUILD_TYPE Release)
IF(NOT CMAKE_BUILD_TYPE)
#SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
#MESSAGE(STATUS "CXX" ${CMAKE_CXX_COMPILER_ID})
OPTION(USE_DOUBLE "Use double" OFF) # Enabled by default
IF(USE_DOUBLE)
ADD_DEFINITIONS(-DUSE_DOUBLE)
ENDIF(USE_DOUBLE)
OPTION(USE_LOG "Use log" OFF) # Enabled by default
IF(USE_LOG)
ADD_DEFINITIONS(-DLOG_DATA)
ENDIF(USE_LOG)
#IF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
# SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -stdlib=libc++ -O0 -Wall -g -ggdb -D LOG_DATA")
# SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -stdlib=libstdc++ -O3")
#ELSE( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
# SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -O0 -Wall -g -ggdb -D LOG_DATA")
# SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -O3")
#ENDIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)
SET(CUDA_SEPARABLE_COMPILATION ON)
STRING(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
if (CMAKE_BUILD_TYPE_UPPER STREQUAL "RELEASE")
IF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -stdlib=libstdc++ -O3 -fPIC")
ELSE( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++11 -O3 -fPIC")
ENDIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CUDA_NVCC_FLAGS_RELEASE "-std=c++11;-O3;-arch=sm_60;-lcufft")
elseif (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
IF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -stdlib=libc++ -O0 -Wall -g -ggdb -fPIC -D LOG_DATA")
ELSE( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++11 -O0 -Wall -g -ggdb -fPIC -D LOG_DATA")
ENDIF ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
#SET(CUDA_NVCC_FLAGS_DEBUG "-std=c++11;-g;-G;-lineinfo;-Xcompiler;-D LOG_DATA;-arch=sm_60")
SET(CUDA_NVCC_FLAGS_DEBUG "-std=c++11;-g;-G;-D LOG_DATA;-arch=sm_60;-lcufft")
endif (CMAKE_BUILD_TYPE_UPPER STREQUAL "RELEASE")
#SET(CUDA_NVCC_FLAGS_DEBUG "-arch=sm_60 -std=c++11 -g -G -lineinfo -Xcompiler -Wall -D LOG_DATA")
#SET(CUDA_NVCC_FLAGS_RELEASE "-arch=sm_60 -std=c++11 -O3")
SET(CPU_LIB bsim)
SET(GPU_LIB bsim_gpu)
SET(AUTO_CPU_SRC "src/utils/TypeFunc.cpp")
SET(AUTO_GPU_SRC "src/utils/TypeFunc.cu")
SET(GEN_TYPE_FUNC_SCRIPT "script/generate_type_functions.py")
FILE(GLOB_RECURSE CPU_SRC "src/*.cpp" "src/*.c")
FILE(GLOB_RECURSE GPU_SRC "src/*.cu")
LIST(REMOVE_ITEM CPU_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${AUTO_CPU_SRC}")
LIST(REMOVE_ITEM GPU_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${AUTO_GPU_SRC}")
FILE(GLOB CPU_TEST "test/cpu/*.cpp" "test/cpu/*.c")
FILE(GLOB GPU_TEST "test/gpu/*.cpp" "test/gpu/*.c" "test/gpu/*.cu")
FILE(COPY ${PROJECT_SOURCE_DIR}/CLEAN_ALL.cmake DESTINATION ${CMAKE_BINARY_DIR})
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/${AUTO_CPU_SRC} ${PROJECT_SOURCE_DIR}/${AUTO_GPU_SRC}
COMMAND echo "Generating ${AUTO_CPU_SRC} and ${AUTO_GPU_SRC}"
COMMAND python ${PROJECT_SOURCE_DIR}/${GEN_TYPE_FUNC_SCRIPT}
MAIN_DEPENDENCY src/utils/TypeFunc.h
COMMENT "Generate type func"
)
ADD_CUSTOM_TARGET(GEN_TYPE_FUNC_CPU DEPENDS ${PROJECT_SOURCE_DIR}/${AUTO_CPU_SRC})
ADD_CUSTOM_TARGET(GEN_TYPE_FUNC_GPU DEPENDS ${PROJECT_SOURCE_DIR}/${AUTO_GPU_SRC})
ADD_LIBRARY(${CPU_LIB} STATIC ${CPU_SRC} ${PROJECT_SOURCE_DIR}/${AUTO_CPU_SRC})
SET_TARGET_PROPERTIES(${CPU_LIB} PROPERTIES LINKER_LANGUAGE CXX)
ADD_DEPENDENCIES(${CPU_LIB} GEN_TYPE_FUNC_CPU)
FOREACH(exec_path ${CPU_TEST})
#MESSAGE("EXEC_PATH: ${exec_path}")
GET_FILENAME_COMPONENT(exec_file ${exec_path} NAME_WE)
#MESSAGE("EXEC_FILE: ${exec_file}")
ADD_EXECUTABLE(${exec_file} ${exec_path})
TARGET_LINK_LIBRARIES(${exec_file} ${CPU_LIB} ${BLAS_LIBRARIES})
ENDFOREACH()
CUDA_ADD_LIBRARY(${GPU_LIB} STATIC ${GPU_SRC} ${PROJECT_SOURCE_DIR}/${AUTO_GPU_SRC})
ADD_DEPENDENCIES(${GPU_LIB} GEN_TYPE_FUNC_GPU)
FOREACH(exec_path ${GPU_TEST})
#MESSAGE("EXEC_PATH: ${exec_path}")
GET_FILENAME_COMPONENT(exec_file ${exec_path} NAME_WE)
#MESSAGE("EXEC_FILE: ${exec_file}")
CUDA_ADD_EXECUTABLE(${exec_file} ${exec_path})
CUDA_ADD_CUFFT_TO_TARGET(${exec_file})
TARGET_LINK_LIBRARIES(${exec_file} ${GPU_LIB} ${CUDA_CUFFT_LIBRARIES} ${CPU_LIB} ${MPI_LIBRARIES} blas ${BLAS_LIBRARIES} python2.7)
ENDFOREACH()
#ADD_CUSTOM_COMMAND(TARGET multi-gpusim_test
# POST_BUILD
# COMMAND cp ${CMAKE_BINARY_DIR}/bin/multi-gpusim_test ${CMAKE_BINARY_DIR}/../shared
# COMMENT "Copy multi-gpusim_test to shared dir"
# )
ADD_CUSTOM_TARGET(clean-all
COMMAND ${CMAKE_BUILD_TOOL} clean
COMMAND ${CMAKE_COMMAND} -P CLEAN_ALL.cmake
)