forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaichiCore.cmake
179 lines (150 loc) · 5.88 KB
/
TaichiCore.cmake
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
set(CORE_LIBRARY_NAME taichi_core)
option(USE_STDCPP "Use -stdlib=libc++" OFF)
option(TI_WITH_CUDA "Build with the CUDA backend" ON)
option(TI_WITH_OPENGL "Build with the OpenGL backend" ON)
option(TI_WITH_CC "Build with the C backend" ON)
if (APPLE)
if (TI_WITH_CUDA)
set(TI_WITH_CUDA OFF)
message(WARNING "CUDA backend not supported on OS X. Setting TI_WITH_CUDA to OFF.")
endif()
if (TI_WITH_OPENGL)
set(TI_WITH_OPENGL OFF)
message(WARNING "OpenGL backend not supported on OS X. Setting TI_WITH_OPENGL to OFF.")
endif()
if (TI_WITH_CC)
set(TI_WITH_CC OFF)
message(WARNING "C backend not supported on OS X. Setting TI_WITH_CC to OFF.")
endif()
endif()
if (WIN32)
if (TI_WITH_CC)
set(TI_WITH_CC OFF)
message(WARNING "C backend not supported on Windows. Setting TI_WITH_CC to OFF.")
endif()
endif()
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/glad/src/glad.c")
set(TI_WITH_OPENGL OFF)
message(WARNING "external/glad submodule not detected. Settings TI_WITH_OPENGL to OFF.")
endif()
file(GLOB TAICHI_CORE_SOURCE
"taichi/*/*/*/*.cpp" "taichi/*/*/*.cpp" "taichi/*/*.cpp" "taichi/*.cpp"
"taichi/*/*/*/*.h" "taichi/*/*/*.h" "taichi/*/*.h" "taichi/*.h" "tests/cpp/*.cpp")
file(GLOB TAICHI_BACKEND_SOURCE "taichi/backends/**/*.cpp" "taichi/backends/**/*.h")
file(GLOB TAICHI_CPU_SOURCE "taichi/backends/cpu/*.cpp" "taichi/backends/cpu/*.h")
file(GLOB TAICHI_CUDA_SOURCE "taichi/backends/cuda/*.cpp" "taichi/backends/cuda/*.h")
file(GLOB TAICHI_METAL_SOURCE "taichi/backends/metal/*.h" "taichi/backends/metal/*.cpp" "taichi/backends/metal/shaders/*")
file(GLOB TAICHI_OPENGL_SOURCE "taichi/backends/opengl/*.h" "taichi/backends/opengl/*.cpp" "taichi/backends/opengl/shaders/*")
file(GLOB TAICHI_CC_SOURCE "taichi/backends/cc/*.h" "taichi/backends/cc/*.cpp")
list(REMOVE_ITEM TAICHI_CORE_SOURCE ${TAICHI_BACKEND_SOURCE})
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_CPU_SOURCE})
if (TI_WITH_CUDA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_CUDA")
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_CUDA_SOURCE})
endif()
if(NOT CUDA_VERSION)
set(CUDA_VERSION 10.0)
endif()
# TODO(#529) include Metal source only on Apple MacOS, and OpenGL only when TI_WITH_OPENGL is ON
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_METAL_SOURCE})
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_OPENGL_SOURCE})
if (TI_WITH_OPENGL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_OPENGL")
# Q: Why not external/glad/src/*.c?
# A: To ensure glad submodule exists when TI_WITH_OPENGL is ON.
file(GLOB TAICHI_GLAD_SOURCE "external/glad/src/glad.c")
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_GLAD_SOURCE})
endif()
if (TI_WITH_CC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_CC")
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_CC_SOURCE})
endif()
add_library(${CORE_LIBRARY_NAME} SHARED ${TAICHI_CORE_SOURCE} ${PROJECT_SOURCES})
if (APPLE)
# Ask OS X to minic Linux dynamic linking behavior
target_link_libraries(${CORE_LIBRARY_NAME} "-undefined dynamic_lookup")
endif()
include_directories(${CMAKE_SOURCE_DIR})
include_directories(external/include)
include_directories(external/spdlog/include)
if (TI_WITH_OPENGL)
include_directories(external/glad/include)
endif()
set(LIBRARY_NAME ${CORE_LIBRARY_NAME})
if (TI_WITH_OPENGL)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
message("Building with GLFW")
add_subdirectory(external/glfw)
target_link_libraries(${LIBRARY_NAME} glfw)
endif()
# http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
if(${LLVM_PACKAGE_VERSION} VERSION_LESS "10.0")
message(FATAL_ERROR "LLVM version < 10 is not supported")
endif()
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
message("LLVM include dirs ${LLVM_INCLUDE_DIRS}")
message("LLVM library dirs ${LLVM_LIBRARY_DIRS}")
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs
Core
ExecutionEngine
InstCombine
OrcJIT
RuntimeDyld
TransformUtils
BitReader
BitWriter
Object
ScalarOpts
Support
native
Linker
Target
MC
Passes
ipo
Analysis
)
target_link_libraries(${LIBRARY_NAME} ${llvm_libs})
if (TI_WITH_CUDA)
llvm_map_components_to_libnames(llvm_ptx_libs NVPTX)
target_link_libraries(${LIBRARY_NAME} ${llvm_ptx_libs})
endif()
# Optional dependencies
if (APPLE)
target_link_libraries(${CORE_LIBRARY_NAME} "-framework Cocoa -framework Metal")
endif ()
if (NOT WIN32)
target_link_libraries(${CORE_LIBRARY_NAME} pthread stdc++)
if (APPLE)
# OS X
else()
# Linux
target_link_libraries(${CORE_LIBRARY_NAME} stdc++fs X11)
target_link_libraries(${CORE_LIBRARY_NAME} -static-libgcc -static-libstdc++)
target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/misc/linker.map)
target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--wrap=log2f) # Avoid glibc dependencies
endif()
else()
# windows
target_link_libraries(${CORE_LIBRARY_NAME} Winmm)
endif ()
message("PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
foreach (source IN LISTS TAICHI_CORE_SOURCE)
file(RELATIVE_PATH source_rel ${CMAKE_CURRENT_LIST_DIR} ${source})
get_filename_component(source_path "${source_rel}" PATH)
string(REPLACE "/" "\\" source_path_msvc "${source_path}")
source_group("${source_path_msvc}" FILES "${source}")
endforeach ()
if (MSVC)
set_property(TARGET ${CORE_LIBRARY_NAME} APPEND PROPERTY LINK_FLAGS /DEBUG)
endif ()
if (WIN32)
set_target_properties(${CORE_LIBRARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/runtimes")
endif ()