forked from keystone-enclave/keystone-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
117 lines (98 loc) · 3.39 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
include(macros.cmake)
cmake_minimum_required(VERSION 3.10)
enable_language(C CXX ASM)
#-------------------------------------------------------------------------------
# BASIC SETUP
#-------------------------------------------------------------------------------
if(RISCV32)
message(STATUS "riscv32")
set(BITS 32)
else()
message(STATUS "riscv64")
set(BITS 64)
endif()
set(prog_name keystone-sdk)
set(src_dir ${CMAKE_CURRENT_LIST_DIR})
set(scripts_dir ${src_dir}/scripts)
if (DEFINED ENV{KEYSTONE_SDK_DIR})
set(KEYSTONE_SDK_DIR $ENV{KEYSTONE_SDK_DIR})
if (NOT IS_ABSOLUTE ${KEYSTONE_SDK_DIR})
message(FATAL_ERROR "KEYSTONE_SDK_DIR needs to be absolute path")
endif()
get_filename_component(KEYSTONE_SDK_DIR ${KEYSTONE_SDK_DIR} ABSOLUTE)
set(out_dir ${KEYSTONE_SDK_DIR})
else()
message(FATAL_ERROR " * Set KEYSTONE_SDK_DIR to the path you want to install the SDK.\n"
" * Try `export KEYSTONE_SDK_DIR=<path/to/SDK>`")
set(out_dir ${CMAKE_BINARY_DIR})
endif()
if (${out_dir} STREQUAL ${CMAKE_SOURCE_DIR})
message(FATAL_ERROR "OUTPUT_DIR must be different from the source path")
endif()
message(" *** Install path: ${out_dir}")
#-------------------------------------------------------------------------------
# Program and flags
#-------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
else()
if ((NOT CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Release"))
message(FATAL_ERROR "CMAKE_BUILD_TYPE must either be Debug or Release instead of ${CMAKE_BUILD_TYPE}")
endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -g)
endif()
use_riscv_toolchain(${BITS})
################################################################################
# BUILD PROJECTS
################################################################################
include_directories(include)
add_subdirectory(src)
install(FILES macros.cmake DESTINATION ${out_dir}/cmake/)
################################################################################
# Auto Formatting
################################################################################
file(GLOB_RECURSE
CHECK_CXX_SOURCE_FILES
src/*.cpp include/*.hpp
example/*.cpp tests/*.cpp
example/*.hpp tests/*.hpp
)
# remove external cpp sources from cpplint checking
list(FILTER CHECK_CXX_SOURCE_FILES EXCLUDE REGEX ".*/json11.cpp$")
list(FILTER CHECK_CXX_SOURCE_FILES EXCLUDE REGEX ".*/json11.h$")
file(GLOB_RECURSE
CHECK_C_SOURCE_FILES
src/*.c include/*.h
example/*.c tests/*.c
example/*.h tests/*.h
)
find_program(CLANG_FORMAT "clang-format")
find_program(CPPLINT "cpplint")
if(CLANG_FORMAT AND CPPLINT)
add_custom_target(
format
COMMAND
${CLANG_FORMAT}
-i
-style=file
${CHECK_CXX_SOURCE_FILES} ${CHECK_C_SOURCE_FILES}
COMMAND
${CPPLINT}
${CHECK_CXX_SOURCE_FILES}
COMMENT "Auto-formatting"
)
endif()
################################################################################
# Uninstall
################################################################################
add_custom_target("uninstall"
COMMAND
rm -rf ${out_dir}/lib
rm -rf ${out_dir}/include
rm -rf ${out_dir}/cmake)
add_subdirectory(examples EXCLUDE_FROM_ALL)
add_subdirectory(tests EXCLUDE_FROM_ALL)
add_subdirectory(.post-install)