-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
185 lines (154 loc) · 6.83 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
cmake_minimum_required(VERSION 3.13.0)
project(lomp)
# General project options
enable_testing()
# By default, we want to build in Release mode
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
message(STATUS "Build type set to: ${CMAKE_BUILD_TYPE}")
# Project languages
enable_language(CXX)
enable_language(C)
# We use C11 and C++17 and we do not want GNU extensions
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
# set(CMAKE_VERBOSE_MAKEFILE on)
# define LOMP specific configuration options
option(LOMP_WARN_API_STUBS "Warn about missing API entry points" ON)
option(LOMP_WARN_ARCH_FEATURES "Warn about missing implementations for arch features" ON)
option(LOMP_GNU_SUPPORT "Build GNU-style runtime entry points" OFF)
option(LOMP_ICC_SUPPORT "Build additional entry points for Intel classic compilers" OFF)
option(LOMP_MICROBM_WITH_LOMP "Use LOMP for micro-benchmarks" OFF)
option(LOMP_BUILD_MICROBM "Build micro-benchmarks" ON)
option(LOMP_BUILD_EXAMPLES "Build example programs" ON)
option(LOMP_SERIAL "Build a serial version of the LOMP library" OFF)
option(LOMP_SHARED_LIB "Build a shared-library version of LOMP" ON)
set(LOMP_MAX_THREADS "256" CACHE STRING "Maximum number of threads supported by LOMP" )
# Assume aarch64 v8.1a architecture by default.
set(LOMP_ARM64_ARCHITECTURE "armv8.1a" CACHE STRING "Detailed aarch64 architecture passed to -march=")
include(CheckCXXCompilerFlag)
# look for Git
find_package(Git)
# Detect unsupported compilers
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Apple Clang does not support OpenMP itself, but should still be able
# to build the runtime. (Just not run the tests)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_definitions(LOMP_GCC_BUILD=1)
else()
message(FATAL_ERROR
"Unknown compiler: " ${CMAKE_CXX_COMPILER_ID} ". Please use clang or Intel compilers instead.")
endif()
# detect the operating system
execute_process(COMMAND uname COMMAND tr -d '\n' OUTPUT_VARIABLE LOMP_TARGET_OS)
message(STATUS "Target system: ${LOMP_TARGET_OS}")
# Detect the machine architecture
execute_process(COMMAND arch COMMAND tr -d '\n' OUTPUT_VARIABLE LOMP_TARGET_ARCH)
message(STATUS "Architecture: ${LOMP_TARGET_ARCH}")
if (${LOMP_TARGET_ARCH} STREQUAL "aarch64")
add_compile_options(-march=${LOMP_ARM64_ARCHITECTURE})
message("-- LOMP_ARM64_ARCHITECTURE=${LOMP_ARM64_ARCHITECTURE} => -march=${LOMP_ARM64_ARCHITECTURE}")
add_compile_definitions(LOMP_ARM64_ARCHITECTURE=${LOMP_ARM64_ARCHITECTURE})
endif()
# find all LOMP source files
file(GLOB_RECURSE LOMP_SOURCE_FILES ${PROJECT_SOURCE_DIR}/*.cc
${PROJECT_SOURCE_DIR}/*.c
${PROJECT_SOURCE_DIR}/*.h)
# find clang-format and enable "format" target if found
find_program(LOMP_CLANG_FORMAT "clang-format")
if(LOMP_CLANG_FORMAT)
message(STATUS "Found clang-format. Enabling \"format\" target.")
add_custom_target(format
COMMAND clang-format -i ${LOMP_SOURCE_FILES})
endif()
# find clang-tidy and enable "check" target if found
find_program(LOMP_CLANG_TIDY "clang-tidy")
if (LOMP_CLANG_TIDY)
message(STATUS "Found clang-tidy. Enabling \"check\" target.")
add_custom_target(check
COMMAND clang-tidy ${LOMP_SOURCE_FILES} -- -std=c++17)
endif()
# add a custom clean target to tidy up the source tree
file(GLOB_RECURSE LOMP_EDITOR_BACKUPS ${PROJECT_SOURCE_DIR}/*.bak
${PROJECT_SOURCE_DIR}/*.~)
add_custom_target(realclean COMMAND rm -vf ${LOMP_EDITOR_BACKUPS})
if(${LOMP_TARGET_ARCH} STREQUAL "x86_64")
# If we are building for a Intel64 machine, check for Intel TSX
check_cxx_compiler_flag("-mrtm" LOMP_HAVE_RTM)
# On X86_64 check for cmpxchg16b support
check_cxx_compiler_flag("-mcx16" LOMP_HAVE_CMPXCHG16B)
endif()
# Determine extension of dynamic libraries
if (${LOMP_TARGET_OS} STREQUAL "Linux")
set(LOMP_SHAREDLIB_SUFFIX ".so")
endif()
if (${LOMP_TARGET_OS} STREQUAL "Darwin")
set(LOMP_SHAREDLIB_SUFFIX ".dylib")
endif()
message(STATUS "Shared-library extension: ${LOMP_SHAREDLIB_SUFFIX}")
# Some macros to ease dealing with compiler flags
macro(add_mrtm_flag target)
if(LOMP_HAVE_RTM)
target_compile_options(${target} BEFORE PRIVATE -mrtm)
target_compile_definitions(${target} PRIVATE -DLOMP_HAVE_RTM=1)
endif()
endmacro(add_mrtm_flag)
macro(add_mcx16_flag target)
if(LOMP_HAVE_CMPXCHG16B)
target_compile_options(${target} BEFORE PRIVATE -mcx16)
target_compile_definitions(${target} PRIVATE -DLOMP_HAVE_CMPXCHG16B=1)
endif()
endmacro(add_mcx16_flag)
# Find libatomic and and define macro to add where we need libatomic
message(STATUS "Looking for libatomic: libatomic${LOMP_SHAREDLIB_SUFFIX} libatomic${LOMP_SHAREDLIB_SUFFIX}.1")
find_library(LOMP_LIBATOMIC NAMES libatomic${LOMP_SHAREDLIB_SUFFIX}
libatomic${LOMP_SHAREDLIB_SUFFIX}.1)
message(STATUS "Found libatomic: ${LOMP_LIBATOMIC}")
macro(add_libatomic target)
if (LOMP_LIBATOMIC)
target_compile_definitions(${target} PRIVATE LOMP_HAVE_LIBATOMIC=1)
target_link_libraries(${target} ${LOMP_LIBATOMIC})
endif()
endmacro(add_libatomic)
# Determine Git commit ID
if(Git_FOUND)
execute_process (
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE LOMP_GIT_COMMIT_ID
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(LOMP_GIT_COMMIT_ID "unknown")
endif()
message(STATUS "LOMP build with Git commit ID: ${LOMP_GIT_COMMIT_ID}")
message(STATUS "Maximum number of threads supported set to ${LOMP_MAX_THREADS}")
message(STATUS "Use LOMP for micro-benchmarks (LOMP_MICROBM_WITH_LOMP): ${LOMP_MICROBM_WITH_LOMP}")
message(STATUS "Warn about missing API entry points (LOMP_WARN_API_STUBS): ${LOMP_WARN_API_STUBS}")
message(STATUS "Warn about missing implementations for arch features (LOMP_WARN_ARCH_FEATURES): ${LOMP_WARN_ARCH_FEATURES}")
message(STATUS "Build example programs: ${LOMP_BUILD_EXAMPLES}")
message(STATUS "Build micro-benchmarks: ${LOMP_BUILD_MICROBM}")
message(STATUS "Build shared-library version of LOMP: " ${LOMP_SHARED_LIB})
# set the CMake flags for static vs shared libraries
set(BUILD_SHARED_LIBS ${LOMP_SHARED_LIB})
# Add our own include directory that contains the omp.h header file
include_directories(./include)
include_directories(./src)
# Build the runtime library
add_subdirectory(src)
add_subdirectory(include)
if(LOMP_BUILD_EXAMPLES)
# Build the example programs
add_subdirectory(examples)
endif()
# Build the tests
add_subdirectory(tests)
if(LOMP_BUILD_MICROBM)
# Build the micro-benchmarks
add_subdirectory(microBM)
endif()