-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·119 lines (96 loc) · 3.54 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
cmake_minimum_required(VERSION 3.16.3)
set(CMAKE_CXX_STANDARD 14)
option(USE_LSTINGX "Use the lstingx main function" OFF)
if(USE_LSTINGX)
add_definitions(-DUSE_LSTINGX_MAIN)
endif()
project(PowerInv)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
set(COPY_COMPILE_COMMANDS "${CMAKE_SOURCE_DIR}/compile_commands.json")
add_compile_options(-fexceptions)
add_executable(Inv ${CMAKE_SOURCE_DIR}/main.cpp)
add_executable(Inv_NoProp ${CMAKE_SOURCE_DIR}/main.cpp)
set_target_properties(Inv_NoProp PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}")
include_directories(${CMAKE_SOURCE_DIR})
message("C++ compiler ID: " ${CMAKE_CXX_COMPILER_ID})
message("C++ compiler version: " ${CMAKE_CXX_COMPILER_VERSION})
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
add_custom_command(
OUTPUT ${COPY_COMPILE_COMMANDS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${COPY_COMPILE_COMMANDS}
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json
COMMENT "Copying compile_commands.json to project root directory"
)
foreach(target Inv)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${COPY_COMPILE_COMMANDS}
COMMENT "Copying compile_commands.json to project root directory"
)
endforeach()
#Adjust LLVM_CONFIG
set(LLVM_CONFIG "llvm-config-10" CACHE PATH "Path to llvm-config-10 executable")
find_program(LLVM_CONFIG_EXECUTABLE ${LLVM_CONFIG})
if(NOT LLVM_CONFIG_EXECUTABLE)
message(FATAL_ERROR "llvm-config executable not found. Set LLVM_CONFIG to the path to llvm-config executable.")
endif()
set(CLANG_LIBS
-Wl,--start-group
-lclang
-lclangAST
-lclangAnalysis
-lclangBasic
-lclangDriver
-lclangEdit
-lclangIndex
-lclangFrontend
-lclangFrontendTool
-lclangLex
-lclangParse
-lclangSema
-lclangEdit
-lclangASTMatchers
-lclangRewrite
-lclangRewriteFrontend
-lclangStaticAnalyzerFrontend
-lclangStaticAnalyzerCheckers
-lclangStaticAnalyzerCore
-lclangSerialization
-lclangToolingCore
-lclangTooling
-lLLVM-10
-lLLVMSupport
-Wl,--end-group
)
execute_process(COMMAND ${LLVM_CONFIG} --libs --system-libs --ldflags OUTPUT_VARIABLE LLVM_LD_FLAGS)
execute_process(COMMAND ${LLVM_CONFIG} --cxxflags OUTPUT_VARIABLE LLVM_CXX_FLAGS)
execute_process(COMMAND ${LLVM_CONFIG} --includedir OUTPUT_VARIABLE LLVM_INCLUDE_FLAGS)
string(REPLACE "\n" "" LLVM_INCLUDE_FLAGS ${LLVM_INCLUDE_FLAGS})
string(REPLACE "\n" "" LLVM_CXX_FLAGS ${LLVM_CXX_FLAGS})
string(REPLACE "\n" "" LLVM_LD_FLAGS ${LLVM_LD_FLAGS})
string(REPLACE "-L" "" LLVM_LD_PATH ${LLVM_LD_FLAGS})
set(LLVM_INCLUDE_FLAGS ${LLVM_INCLUDE_FLAGS} CACHE INTERNAL "LLVM include flags")
link_directories(${LLVM_LD_PATH})
include_directories(${LLVM_INCLUDE_FLAGS})
target_link_libraries(Inv ${CLANG_LIBS})
add_subdirectory(Frontend)
include_directories(${CMAKE_SOURCE_DIR}/Frontend)
include_directories(${CMAKE_SOURCE_DIR}/Stingx)
add_subdirectory(Stingx)
target_link_libraries(Inv lstingx)
target_link_libraries(Inv_NoProp ${CLANG_LIBS})
target_link_libraries(Inv_NoProp lstingx)
target_link_libraries(Inv_NoProp Frontend_NoProp)
target_link_libraries(Inv Frontend)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -DENABLE_LLVM_SHARED=1 ${LLVM_CXX_FLAGS}")
#Frontend commands