-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
211 lines (180 loc) · 7.25 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#
# Copyright (c) 2015-2017, Lawrence Livermore National Security, LLC.
#
# Produced at the Lawrence Livermore National Laboratory
#
# Written by Simone Atzeni ([email protected]), Joachim Protze
# ([email protected]), Jonas Hahnfeld
# ([email protected]), Ganesh Gopalakrishnan, Zvonimir
# Rakamaric, Dong H. Ahn, Gregory L. Lee, Ignacio Laguna, and Martin
# Schulz.
#
# LLNL-CODE-727057
#
# All rights reserved.
#
# This file is part of Sword. For details, see
# https://pruners.github.io/sword. Please also read
# https://github.com/PRUNERS/sword/blob/master/LICENSE.
#
# 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 disclaimer below.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the disclaimer (as noted below)
# in the documentation and/or other materials provided with the
# distribution.
#
# Neither the name of the LLNS/LLNL nor the names of its contributors
# may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# 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 LAWRENCE
# LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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.
#
cmake_minimum_required(VERSION 3.4.3)
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()
set(COMPRESSION "LZO" CACHE STRING "Set the compression algorithm to use.")
if(${COMPRESSION} STREQUAL "LZO")
add_definitions(-D LZO)
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/rtl/lzo/minilzo.c)
elseif(${COMPRESSION} STREQUAL "SNAPPY")
add_definitions(-D SNAPPY)
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/rtl/snappy/snappy.cc ${CMAKE_CURRENT_SOURCE_DIR}/rtl/snappy-sinksource.cc)
elseif(${COMPRESSION} STREQUAL "LZ4")
add_definitions(-D LZ4)
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/rtl/lz4/lz4.c)
else()
add_definitions(-D LZO)
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/rtl/lzo/minilzo.c)
# add_definitions(-D HUFFMAN)
# add_definitions(-D ARITHMETIC)
# add_definitions(-D TCGEN)
endif()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
# Add cmake directory to search for custom cmake functions
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# Standalone build or part of LLVM?
set(LIBSWORD_STANDALONE_BUILD FALSE)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
project(sword C CXX)
set(LIBSWORD_STANDALONE_BUILD TRUE)
endif()
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
# require at least clang 3.9
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9)
message(FATAL_ERROR "Clang version must be at least 3.9!")
endif()
else()
message(FATAL_ERROR "You are using an unsupported compiler! The required compiler is Clang version >= 3.9.")
endif()
string(SUBSTRING ${CMAKE_CXX_COMPILER_VERSION} 0 3 LLVM_VERSION)
string(REPLACE "." "" LLVM_VERSION ${LLVM_VERSION})
add_definitions(-DLLVM_VERSION=${LLVM_VERSION})
# These include files are in the cmake/ subdirectory
include(LibswordUtils)
# Check is OSX or Linux (for lib extension)
if(${APPLE})
set(EXT .dylib)
elseif(${UNIX})
set(EXT .so)
endif()
if(${LIBSWORD_STANDALONE_BUILD})
# LLVM detection part
set(LLVM_ROOT "" CACHE PATH "Root of LLVM install.")
find_package(LLVM MODULE REQUIRED)
# Sanity check
if(NOT EXISTS ${LLVM_ROOT}/include/llvm)
message(FATAL_ERROR "LLVM_ROOT (${LLVM_ROOT}) is not a valid LLVM install")
endif()
# Incorporate the CMake features provided by LLVM:
if (EXISTS ${LLVM_ROOT}/lib/cmake/llvm)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/lib/cmake/llvm")
elseif (EXISTS ${LLVM_ROOT}/lib64/cmake/llvm)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT}/lib64/cmake/llvm")
else ()
message(FATAL_ERROR "LLVM cmake module dir could not be found")
endif ()
include(LLVMConfig)
include(HandleLLVMOptions)
include(AddLLVM)
# Group test settings.
set(LIBSWORD_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
"C compiler to use for testing Sword runtime libraries.")
set(LIBSWORD_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
"C++ compiler to use for testing Sword runtime libraries.")
set(LIBSWORD_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
else()
set(LLVM_ROOT ${CMAKE_INSTALL_PREFIX} CACHE PATH "Root of LLVM install.")
endif()
# Look for OpenMP runtime
if(${LIBSWORD_STANDALONE_BUILD})
set(OMP_PREFIX /usr/local CACHE PATH "Root of OpenMP runtime install")
if(NOT EXISTS ${OMP_PREFIX}/include/omp.h)
message(FATAL_ERROR "OMP_PREFIX (${OMP_PREFIX}) is not a valid OpenMP runtime install")
endif()
else()
set(OMP_PREFIX ${LLVM_ROOT} CACHE PATH "Root of OpenMP runtime install")
endif()
find_package(Boost 1.58.0 COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
endif()
find_package(GLPK REQUIRED)
if(GLPK_FOUND)
include_directories(${GLPK_INCLUDE_DIRS})
link_directories(${GLPK_LIBRARIES})
endif()
find_package(Omp)
include_directories(${OMP_INCLUDE_PATH})
link_directories(${OMP_LIB_PATH})
if(NOT ${LLVM_NATIVE_ARCH} STREQUAL "PowerPC")
find_package(Ompt)
include_directories(${OMPT_INCLUDE_PATH})
endif()
include(config-ix)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
has_ompt_support("${OMP_LIB_PATH}" "libomp.so" "ompt_start_tool" LIBSWORD_OMPT_SUPPORT)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
has_ompt_support("${OMP_LIB_PATH}" "libomp.dylib" "_ompt_callbacks" LIBSWORD_OMPT_SUPPORT)
endif()
# Set up testing infrastructure.
include(SwordTesting)
set(LIBSWORD_TEST_FLAGS "" CACHE STRING
"Extra compiler flags to send to the test compiler.")
set(LIBSWORD_TEST_SWORD_FLAGS ${LIBSWORD_TEST_COMPILER_SWORD_FLAGS} CACHE STRING
"Sword compiler flag to use for testing Sword runtime libraries.")
# Setting directory names
set(LIBSWORD_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBSWORD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBSWORD_RUNTIME_PATH ${CMAKE_BINARY_DIR}/rtl)
set(LIBSWORD_RTL libsword${EXT})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
endif()
set(LIBSWORD_LIB_PATH ${CMAKE_BINARY_DIR}/lib)
set(LIBSWORD_LIB LLVMSword${EXT})
set(LIBSWORD_TOOLS_DIR ${CMAKE_BINARY_DIR}/tools)
add_subdirectory(lib)
add_subdirectory(rtl)
add_subdirectory(test)
add_subdirectory(tools)