-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
133 lines (101 loc) · 3.61 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
cmake_minimum_required(VERSION 3.12)
project(SolverGen)
include(FetchContent)
FetchContent_Declare(hrdata
GIT_REPOSITORY https://github.com/am-ivanov/hrdata.git
GIT_TAG 9bb7a8334065801f503bdbc4b11ce03921fc0bee
)
FetchContent_GetProperties(hrdata)
if(NOT hrdata_POPULATED)
FetchContent_Populate(hrdata)
add_subdirectory(${hrdata_SOURCE_DIR} ${hrdata_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(llvm
URL https://releases.llvm.org/8.0.0/llvm-8.0.0.src.tar.xz
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/llvm
)
FetchContent_GetProperties(llvm)
if(NOT llvm_POPULATED)
FetchContent_Populate(llvm)
endif()
FetchContent_Declare(clang
URL https://releases.llvm.org/8.0.0/cfe-8.0.0.src.tar.xz
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/llvm/tools/clang
)
FetchContent_GetProperties(clang)
if(NOT clang_POPULATED)
FetchContent_Populate(clang)
endif()
function(add_llvm)
set(CMAKE_BUILD_TYPE Release)
message("INSIDE:" ${CMAKE_BUILD_TYPE})
set(LLVM_ENABLE_RTTI ON) # otherwise it is impossible to inherit from llvm classess
set(BUILD_SHARED_LIBS ON) # enables shared shibraries to link with
#set(LLVM_LINK_LLVM_DYLIB ON)
#set(LLVM_BUILD_LLVM_DYLIB ON)
add_subdirectory(${llvm_SOURCE_DIR} ${llvm_BINARY_DIR} EXCLUDE_FROM_ALL)
#add_subdirectory(${llvm_SOURCE_DIR} ${llvm_BINARY_DIR})
endfunction()
message("BEFORE:" ${CMAKE_BUILD_TYPE})
add_llvm()
message("AFTER:" ${CMAKE_BUILD_TYPE})
# create compilation database (compile_commands.json) to process later
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(solver_generator src/generator/generator.cpp)
# because LLVM itself doesn't define include dirs
target_include_directories(solver_generator PRIVATE
${llvm_SOURCE_DIR}/include
${clang_SOURCE_DIR}/include
${llvm_BINARY_DIR}/tools/clang/include
${llvm_BINARY_DIR}/include
)
# it makes headers visible for libTooling based tools in build dir
add_dependencies(solver_generator clang-headers)
target_link_libraries(solver_generator PRIVATE
LLVMOption
LLVMSupport
clangAST
clangASTMatchers
clangBasic
clangDriver
clangFrontend
clangLex
clangRewrite
clangRewriteFrontend
clangSerialization
clangStaticAnalyzerFrontend
clangTooling
clangSema
)
set_target_properties(solver_generator PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${llvm_BINARY_DIR}/bin"
)
add_subdirectory(src/solverlib)
function(add_solver solver)
# add entry to compilation database
add_executable(${solver}-dummy "${CMAKE_CURRENT_SOURCE_DIR}/src/solvers/${solver}.cpp")
target_link_libraries(${solver}-dummy hrdata solver_lib)
target_compile_options(${solver}-dummy PRIVATE -march=native) # enables vector instructions
add_custom_command(
OUTPUT ${solver}.gen.cpp
COMMAND ${llvm_BINARY_DIR}/bin/solver_generator
${CMAKE_CURRENT_SOURCE_DIR}/src/solvers/${solver}.cpp
-o ${solver}.gen.cpp
-p ${CMAKE_CURRENT_BINARY_DIR}
-lv
# next line forces regeneration if generator or source are changed
DEPENDS solver_generator ${solver}-dummy
VERBATIM
)
add_executable(${solver} ${solver}.gen.cpp)
target_link_libraries(${solver} hrdata solver_lib)
target_compile_options(${solver} PRIVATE -march=native) # enables vector instructions
endfunction()
add_solver(gc_elastic_2d)
add_solver(gc_elastic_2d_from_le2d)
add_solver(fd_scalar_wave_2d)
add_executable(gc_elastic_2d_tiled
../solvergen/testscripts/gc_elastic_2d_tiled.cpp
)
target_link_libraries(gc_elastic_2d_tiled hrdata solver_lib)
target_compile_options(gc_elastic_2d_tiled PRIVATE -march=native) # enables vector instructions