Mercurial > projects > ldc
comparison runtime/CMakeLists.txt @ 786:45d9c218fd32
Add missing CMakeList, apply conf changes to dmd2 frontend.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Mon, 24 Nov 2008 20:02:59 +0100 |
parents | |
children | 3e0b643090f1 |
comparison
equal
deleted
inserted
replaced
785:ac39e5449ca5 | 786:45d9c218fd32 |
---|---|
1 project(runtime) | |
2 | |
3 cmake_minimum_required(VERSION 2.6) | |
4 | |
5 # not working, gcc has to be on the path before invoking make | |
6 #set(ENV{PATH} ENV{PATH} CMAKE_C_COMPILER:FILEPATH) | |
7 | |
8 find_program(GCC_EXE gcc DOC "path to gcc binary") | |
9 if(NOT GCC_EXE) | |
10 message(STATUS "gcc needs to be on your path to build the runtime") | |
11 endif(NOT GCC_EXE) | |
12 | |
13 option(BUILD_SHARED_LIBS "build the runtime as shared libraries (linux only)") | |
14 option(BUILD_BC_LIBS "build the runtime as bytecode libraries") | |
15 option(BUILD_SINGLE_LIB "build single runtime library" ON) | |
16 set(D_FLAGS -g -w -d CACHE STRING "runtime build flags, separated by ;") | |
17 | |
18 get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY) | |
19 if(D_VERSION EQUAL 1) | |
20 set(RUNTIME tango) | |
21 set(LDC_EXE ldc) | |
22 elseif(D_VERSION EQUAL 2) | |
23 set(RUNTIME druntime) | |
24 set(LDC_EXE ldc2) | |
25 else(D_VERSION EQUAL 1) | |
26 message(FATAL_ERROR "set d version to 1 or 2") | |
27 endif(D_VERSION EQUAL 1) | |
28 | |
29 set(RUNTIME_DIR ${PROJECT_PARENT_DIR}/${RUNTIME} CACHE PATH "runtime source dir" FORCE) | |
30 | |
31 # should only be necessary if run independently from ldc cmake project | |
32 if(NOT LDC_LOC) | |
33 if(NOT LDC_EXE) | |
34 if(D_VERSION EQUAL 1) | |
35 set(LDC_EXE ldc) | |
36 elseif(D_VERSION EQUAL 2) | |
37 set(LDC_EXE ldc2) | |
38 endif(D_VERSION EQUAL 1) | |
39 endif(NOT LDC_EXE) | |
40 | |
41 find_program(LDC_LOC ${LDC_EXE} ../bin DOC "path to ldc binary") | |
42 if(NOT LDC_LOC) | |
43 message(SEND_ERROR "ldc not found") | |
44 endif(NOT LDC_LOC) | |
45 endif(NOT LDC_LOC) | |
46 # | |
47 | |
48 configure_file(${PROJECT_PARENT_DIR}/${LDC_EXE}.conf.in ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}.conf) | |
49 | |
50 # patch runtime source, uses LDC_EXE for ldc / ldc2 | |
51 find_program(PATCH_EXE patch DOC "path to patch tool") | |
52 if(NOT PATCH_EXE) | |
53 message(STATUS "patch tool not found, can't automatically patch runtime sources for ldc") | |
54 else(NOT PATCH_EXE) | |
55 add_custom_command( | |
56 OUTPUT patch-runtime | |
57 COMMAND ${PATCH_EXE} -t -N -p0 -i ${PROJECT_SOURCE_DIR}/${LDC_EXE}.diff | |
58 WORKING_DIRECTORY ${RUNTIME_DIR} | |
59 ) | |
60 add_custom_target(patch DEPENDS patch-runtime) | |
61 endif(NOT PATCH_EXE) | |
62 # | |
63 | |
64 # build tango for D1, druntime for D2 | |
65 if(D_VERSION EQUAL 1) | |
66 # library names | |
67 set(RUNTIME_CC tango-cc-tango) | |
68 set(RUNTIME_GC tango-gc-basic) | |
69 set(RUNTIME_DC ldc-runtime) | |
70 set(RUNTIME_AIO tango-ldc) | |
71 # set paths to source files, or fill lists directly | |
72 set(RUNTIME_DC_DIR ${PROJECT_SOURCE_DIR}/internal) | |
73 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/lib/gc/basic) | |
74 file(GLOB CORE_D ${RUNTIME_DIR}/lib/common/tango/core/*.d) | |
75 file(GLOB CORE_C ${RUNTIME_DIR}/lib/common/tango/stdc/*.c) | |
76 # copy imports to runtime dir | |
77 add_custom_command( | |
78 TARGET ldc-runtime | |
79 POST_BUILD | |
80 COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/import/ldc ${RUNTIME_DIR}/ldc | |
81 COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/internal/ldc/bitmanip.d ${RUNTIME_DIR}/ldc | |
82 COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/internal/ldc/vararg.d ${RUNTIME_DIR}/ldc | |
83 ) | |
84 elseif(D_VERSION EQUAL 2) | |
85 set(RUNTIME_CC druntime-core) | |
86 set(RUNTIME_GC druntime-gc-basic) | |
87 set(RUNTIME_DC druntime-rt-ldc) | |
88 set(RUNTIME_AIO druntime-ldc) | |
89 set(RUNTIME_DC_DIR ${RUNTIME_DIR}/src/compiler/ldc) | |
90 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/src/gc/basic) | |
91 file(GLOB CORE_D ${RUNTIME_DIR}/src/common/core/*.d) | |
92 file(GLOB CORE_C ${RUNTIME_DIR}/src/common/core/stdc/*.c) | |
93 endif(D_VERSION EQUAL 1) | |
94 | |
95 file(GLOB GC_D ${RUNTIME_GC_DIR}/*.d) | |
96 file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) | |
97 file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c) | |
98 | |
99 # compile d file into outdir, include incdir, and append names of generated .o and .bc to outlist_o and _bc | |
100 macro(dc INPUT_D OUTLIST_O OUTLIST_BC OUTDIR INCDIR) | |
101 get_filename_component(BASENAME ${INPUT_D} NAME_WE) | |
102 set(OUTPUT_O ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.o) | |
103 set(OUTPUT_BC ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.bc) | |
104 list(APPEND ${OUTLIST_O} ${OUTPUT_O}) | |
105 list(APPEND ${OUTLIST_BC} ${OUTPUT_BC}) | |
106 add_custom_command( | |
107 OUTPUT | |
108 ${OUTPUT_O} | |
109 ${OUTPUT_BC} | |
110 COMMAND ${LDC_LOC} -c -I${INCDIR} -output-bc ${INPUT_D} -of${OUTPUT_O} ${D_FLAGS} | |
111 DEPENDS ${LDC_LOC} | |
112 ) | |
113 endmacro(dc) | |
114 | |
115 foreach(f ${CORE_D}) | |
116 dc(${f} CORE_O CORE_BC core .) | |
117 endforeach(f) | |
118 | |
119 foreach(f ${GC_D}) | |
120 dc(${f} GC_O GC_BC gc ${RUNTIME_GC_DIR}) | |
121 endforeach(f) | |
122 | |
123 foreach(f ${DCRT_D}) | |
124 dc(${f} DCRT_O DCRT_BC dcrt ${RUNTIME_DC_DIR}) | |
125 endforeach(f) | |
126 | |
127 if(BUILD_SINGLE_LIB) | |
128 add_library(${RUNTIME_AIO} ${CORE_O} ${CORE_C} ${GC_O} ${DCRT_O} ${DCRT_C}) | |
129 set(LIBS ${RUNTIME_AIO}) | |
130 else(BUILD_SINGLE_LIB) | |
131 add_library(${RUNTIME_CC} ${CORE_O} ${CORE_C}) | |
132 add_library(${RUNTIME_GC} ${GC_O}) | |
133 add_library(${RUNTIME_DC} ${DCRT_O} ${DCRT_C}) | |
134 set(LIBS | |
135 ${RUNTIME_CC} | |
136 ${RUNTIME_GC} | |
137 ${RUNTIME_DC} | |
138 ) | |
139 endif(BUILD_SINGLE_LIB) | |
140 | |
141 if(BUILD_BC_LIBS) | |
142 find_program(LLVM_AR_EXE llvm-ar ${LLVM_INSTDIR}/bin DOC "path to llvm-ar tool") | |
143 if(NOT LLVM_AR_EXE) | |
144 message(SEND_ERROR "llvm-ar not found") | |
145 endif(NOT LLVM_AR_EXE) | |
146 | |
147 add_library(${RUNTIME_CC}-c ${CORE_C}) | |
148 add_library(${RUNTIME_DC}-c ${DCRT_C}) | |
149 list(APPEND LIBS | |
150 ${RUNTIME_CC}-c | |
151 ${RUNTIME_DC}-c | |
152 ) | |
153 add_custom_command( | |
154 OUTPUT bclibs | |
155 COMMAND ${LLVM_AR_EXE} rs lib${RUNTIME_CC}-bc.a ${CORE_BC} | |
156 COMMAND ${LLVM_AR_EXE} rs lib${RUNTIME_GC}-bc.a ${GC_BC} | |
157 # cannot parse genobj.bc if built with -g | |
158 # COMMAND ${LLVM_AR_EXE} rs lib${RUNTIME_DC}-bc.a ${DCRT_BC} | |
159 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/../lib | |
160 DEPENDS | |
161 ${CORE_BC} | |
162 ${GC_BC} | |
163 ${DCRT_BC} | |
164 ) | |
165 set(BCLIBS bclibs) | |
166 endif(BUILD_BC_LIBS) | |
167 | |
168 set_target_properties( | |
169 ${LIBS} PROPERTIES | |
170 LINKER_LANGUAGE C | |
171 ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib | |
172 LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib | |
173 ) | |
174 | |
175 # BCLIBS is empty if BUILD_BC_LIBS is not selected | |
176 add_custom_target(runtime DEPENDS ${LIBS} ${BCLIBS}) |