forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
349 lines (308 loc) · 10.2 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
project(ldc)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
#
# Locate LLVM.
#
# We need to find exactly the right LLVM version, our code usually does not
# work across LLVM »minor« releases.
find_package(LLVM 3.0 REQUIRED
all-targets bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES})
math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
#
# Locate libconfig++.
#
find_package(LibConfig++ REQUIRED)
#
# Main configuration.
#
# Generally, we want to install everything into CMAKE_INSTALL_PREFIX, but when
# it is /usr, put the config files into /etc to meet common practice.
if (NOT DEFINED SYSCONF_INSTALL_DIR)
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
set(SYSCONF_INSTALL_DIR "/etc")
else(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
set(SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc")
endif(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
endif (NOT DEFINED SYSCONF_INSTALL_DIR)
set(D_VERSION 2 CACHE STRING "D language version")
set(PROGRAM_PREFIX "" CACHE STRING "Prepended to ldc/ldmd binary names")
set(PROGRAM_SUFFIX "" CACHE STRING "Appended to ldc/ldmd binary names")
set(CONF_INST_DIR ${SYSCONF_INSTALL_DIR} CACHE PATH "Directory ldc.conf is installed to")
# The following flags are currently not well tested, expect the build to fail.
option(USE_BOEHM_GC "use the Boehm garbage collector internally")
option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
option(USE_METADATA "use metadata and related custom optimization passes")
mark_as_advanced(USE_BOEHM_GC GENERATE_OFFTI USE_METADATA)
if(D_VERSION EQUAL 1)
set(DMDFE_PATH dmd)
set(LDC_EXE ldc)
set(LDMD_EXE ldmd)
set(RUNTIME runtime)
add_definitions(-DDMDV1)
elseif(D_VERSION EQUAL 2)
set(DMDFE_PATH dmd2)
set(LDC_EXE ldc2)
set(LDMD_EXE ldmd2)
set(RUNTIME druntime)
add_definitions(-DDMDV2)
else(D_VERSION EQUAL 1)
message(FATAL_ERROR "unsupported D version")
endif(D_VERSION EQUAL 1)
set(LDC_EXE_NAME ${PROGRAM_PREFIX}${LDC_EXE}${PROGRAM_SUFFIX})
set(LDMD_EXE_NAME ${PROGRAM_PREFIX}${LDMD_EXE}${PROGRAM_SUFFIX})
file(MAKE_DIRECTORY
${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/${DMDFE_PATH}
${PROJECT_BINARY_DIR}/gen
)
if(MSVC)
ENABLE_LANGUAGE(ASM_MASM)
endif(MSVC)
#
# Run idgen and impcnvgen.
#
set_source_files_properties(
${DMDFE_PATH}/idgen.c
${DMDFE_PATH}/impcnvgen.c
PROPERTIES LANGUAGE CXX
)
add_executable(idgen ${DMDFE_PATH}/idgen.c)
add_executable(impcnvgen ${DMDFE_PATH}/impcnvgen.c)
# cmake 2.4
set_target_properties(
idgen impcnvgen PROPERTIES
LINKER_LANGUAGE CXX
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
COMPILE_FLAGS "${LLVM_CXXFLAGS}"
)
get_target_property(IDGEN_LOC idgen LOCATION)
get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
#
add_custom_command(
OUTPUT
${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
# 2.4
COMMAND ${IDGEN_LOC}
#COMMAND idgen
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
DEPENDS idgen
)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
# 2.4
COMMAND ${IMPCNVGEN_LOC}
#COMMAND impcnvgen
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
DEPENDS impcnvgen
)
set(LDC_GENERATED
${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
)
#
# Gather source files.
#
# Also add the header files to the build so that they are available in IDE
# project files generated via CMake.
file(GLOB_RECURSE FE_SRC ${DMDFE_PATH}/*.c)
file(GLOB_RECURSE FE_HDR ${DMDFE_PATH}/*.h)
file(GLOB_RECURSE GEN_SRC gen/*.cpp)
file(GLOB_RECURSE GEN_HDR gen/*.h)
file(GLOB IR_SRC ir/*.cpp)
file(GLOB IR_HDR ir/*.h)
set(DRV_SRC
driver/cl_options.cpp
driver/configfile.cpp
driver/toobj.cpp
driver/linker.cpp
driver/main.cpp
)
set(DRV_HDR
driver/linker.h
driver/cl_options.h
driver/configfile.h
driver/toobj.h
)
# exclude idgen and impcnvgen and generated sources, just in case
list(REMOVE_ITEM FE_SRC
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvgen.c
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
)
# Add/remove files for MSVC
if(MSVC)
list(REMOVE_ITEM FE_SRC
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/root/gnuc.c
)
list(REMOVE_ITEM FE_HDR
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/root/gnuc.h
)
list(APPEND FE_SRC
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c
# See below why this don't work
# if(CMAKE_CL_64)
# ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
# endif(CMAKE_CL_64)
)
if(CMAKE_CL_64)
# MASM support does not work yet!
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
COMMAND ${CMAKE_ASM_MASM_COMPILER} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
DEPENDS ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
COMMENT "generate ldfpu.obj")
list(APPEND FE_SRC
${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
)
endif()
endif(MSVC)
# disable dmd gc
list(REMOVE_ITEM FE_SRC ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/root/dmgcmem.c)
set(LDC_SOURCE_FILES
${LDC_GENERATED}
${FE_SRC}
${FE_HDR}
${GEN_SRC}
${GEN_HDR}
${IR_SRC}
${IR_HDR}
)
# DMD source files have a .c extension, but are actually C++ code.
foreach(file ${LDC_SOURCE_FILES})
if(file MATCHES ".*\\.c$")
set_source_files_properties(${file} PROPERTIES LANGUAGE CXX)
endif()
endforeach()
source_group("Source Files\\${DMDFE_PATH}" FILES ${FE_SRC})
source_group("Header Files\\${DMDFE_PATH}" FILES ${FE_HDR})
source_group("Source Files\\gen" FILES ${GEN_SRC})
source_group("Header Files\\gen" FILES ${GEN_HDR})
source_group("Source Files\\ir" FILES ${IR_SRC})
source_group("Header Files\\ir" FILES ${IR_HDR})
source_group("Generated Files" REGULAR_EXPRESSION "(id\\.[ch]|impcnvtab\\.c)$")
#
# Includes, defines.
#
include_directories(
.
${DMDFE_PATH}
${DMDFE_PATH}/root
${PROJECT_BINARY_DIR}/${DMDFE_PATH}
${PROJECT_SOURCE_DIR}
${LLVM_INCLUDE_DIRS}
${LIBCONFIG++_INCLUDE_DIR}
)
if(MSVC)
include_directories(${PROJECT_SOURCE_DIR}/vcbuild)
endif()
add_definitions(
-DIN_LLVM
-DOPAQUE_VTBLS
-DLDC_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
-DLDC_LLVM_VER=${LDC_LLVM_VER}
-DLDC_LLVM_VERSION_STRING="${LLVM_VERSION_STRING}"
)
if(UNIX)
add_definitions(-DPOSIX)
endif(UNIX)
if(USE_BOEHM_GC)
add_definitions(-DREDIRECT_MALLOC=GC_malloc -DIGNORE_FREE)
endif(USE_BOEHM_GC)
if(GENERATE_OFFTI)
add_definitions(-DGENERATE_OFFTI)
endif(GENERATE_OFFTI)
if(USE_METADATA)
add_definitions(-DUSE_METADATA)
endif(USE_METADATA)
if(MSVC)
set(EXTRA_CXXFLAGS "/W0 /wd4996 /GF /GR- /RTC1")
else()
set(EXTRA_CXXFLAGS "-Wno-deprecated -Wno-write-strings -fexceptions")
endif()
#
# Set up the main ldc/ldc2 target.
#
if(BUILD_SHARED)
set(LDC_LIB_TYPE SHARED)
else(BUILD_SHARED)
set(LDC_LIB_TYPE STATIC)
endif(BUILD_SHARED)
set(LDC_LIB LDCShared)
add_library(${LDC_LIB} ${LDC_LIB_TYPE} ${LDC_SOURCE_FILES})
set_target_properties(
${LDC_LIB} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
ARCHIVE_OUTPUT_NAME ldc
LIBRARY_OUTPUT_NAME ldc
RUNTIME_OUTPUT_NAME ldc
COMPILE_FLAGS "${LLVM_CXXFLAGS} ${EXTRA_CXXFLAGS}"
)
# LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
target_link_libraries(${LDC_LIB} "${LLVM_LDFLAGS}" ${LLVM_LIBRARIES})
if(WIN32)
target_link_libraries(${LDC_LIB} imagehlp psapi)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${LDC_LIB} dl)
endif(WIN32)
if(USE_BOEHM_GC)
target_link_libraries(${LDC_LIB} ${PROJECT_SOURCE_DIR}/libgc.a)
endif(USE_BOEHM_GC)
add_executable(${LDC_EXE} ${DRV_SRC} ${DRV_HDR})
set_target_properties(
${LDC_EXE} PROPERTIES
OUTPUT_NAME ${LDC_EXE_NAME}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
COMPILE_FLAGS "${LLVM_CXXFLAGS} ${EXTRA_CXXFLAGS}"
)
target_link_libraries(${LDC_EXE} ${LDC_LIB} ${LIBCONFIG++_LIBRARY})
# For use by the druntime/Phobos build system.
get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
#
# LDMD
#
include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
if (HAVE_SC_ARG_MAX)
add_definitions(-DHAVE_SC_ARG_MAX)
endif()
set_source_files_properties(dmd2/root/response.c dmd2/root/man.c PROPERTIES LANGUAGE CXX)
add_executable(${LDMD_EXE} dmd2/root/response.c dmd2/root/man.c driver/ldmd.cpp)
set_target_properties(${LDMD_EXE} PROPERTIES
COMPILE_DEFINITIONS LDC_EXE_NAME="${LDC_EXE_NAME}"
COMPILE_FLAGS "${LLVM_CXXFLAGS}"
OUTPUT_NAME "${LDMD_EXE_NAME}"
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
# Same as above, LLVM_LDFLAGS should really be in LINK_FLAGS, but the LLVM libs
# use symbols from libdl, ..., so LLVM_LDFLAGS must come _after_ them in the
# command line. Maybe this could be improved using library groups, at least with
# GNU ld.
target_link_libraries(${LDMD_EXE} "${LLVM_LDFLAGS}" ${LLVM_LIBRARIES} "${LLVM_LDFLAGS}")
#
# Install target.
#
add_subdirectory(runtime)
install(TARGETS ${LDC_EXE} ${LDMD_EXE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
if(${BUILD_SHARED})
# For now, only install libldc if explicitely building the shared library.
# While it might theoretically be possible to use LDC as a static library
# as well, for the time being this just bloats the normal packages.
install(TARGETS ${LDC_LIB} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif()
install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}_install.conf DESTINATION ${CONF_INST_DIR} RENAME ${LDC_EXE}.conf)
install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}_install.rebuild.conf DESTINATION ${CONF_INST_DIR} RENAME ${LDC_EXE}.rebuild.conf)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(DIRECTORY bash_completion.d DESTINATION ${CONF_INST_DIR})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
#
# Test targets.
#
enable_testing()
if(D_VERSION EQUAL 2)
add_subdirectory(tests/d2)
endif()