Mercurial > projects > ldc
comparison runtime/CMakeLists.txt @ 808:4ad1e7b10378
when building the runtime pass -fPIC for shared libs and -disable-invariants for gc
author | elrood |
---|---|
date | Sun, 30 Nov 2008 19:19:39 +0100 |
parents | 3e0b643090f1 |
children | 03b0c817a1a3 |
comparison
equal
deleted
inserted
replaced
807:d92acb81a583 | 808:4ad1e7b10378 |
---|---|
10 option(BUILD_SHARED_LIBS "build the runtime as shared libraries (linux only)") | 10 option(BUILD_SHARED_LIBS "build the runtime as shared libraries (linux only)") |
11 option(BUILD_BC_LIBS "build the runtime as bytecode libraries") | 11 option(BUILD_BC_LIBS "build the runtime as bytecode libraries") |
12 option(BUILD_SINGLE_LIB "build single runtime library" ON) | 12 option(BUILD_SINGLE_LIB "build single runtime library" ON) |
13 set(D_FLAGS -g -w -d CACHE STRING "runtime build flags, separated by ;") | 13 set(D_FLAGS -g -w -d CACHE STRING "runtime build flags, separated by ;") |
14 | 14 |
15 if(BUILD_SHARED_LIBS) | |
16 list(APPEND D_FLAGS -fPIC) | |
17 endif(BUILD_SHARED_LIBS) | |
18 | |
19 # build tango for D1, druntime for D2 | |
15 if(D_VERSION EQUAL 1) | 20 if(D_VERSION EQUAL 1) |
16 set(RUNTIME tango) | 21 set(RUNTIME tango) |
17 elseif(D_VERSION EQUAL 2) | 22 elseif(D_VERSION EQUAL 2) |
18 set(RUNTIME druntime) | 23 set(RUNTIME druntime) |
19 else(D_VERSION EQUAL 1) | 24 else(D_VERSION EQUAL 1) |
21 endif(D_VERSION EQUAL 1) | 26 endif(D_VERSION EQUAL 1) |
22 get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY) | 27 get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY) |
23 set(RUNTIME_DIR ${PROJECT_PARENT_DIR}/${RUNTIME} CACHE PATH "runtime source dir" FORCE) | 28 set(RUNTIME_DIR ${PROJECT_PARENT_DIR}/${RUNTIME} CACHE PATH "runtime source dir" FORCE) |
24 | 29 |
25 if(D_VERSION EQUAL 1) | 30 if(D_VERSION EQUAL 1) |
26 # build tango for D1, druntime for D2 | |
27 set(LDC_EXE ldc) | 31 set(LDC_EXE ldc) |
28 # copy imports to runtime dir | 32 # copy imports to runtime dir |
29 add_custom_command( | 33 add_custom_command( |
30 OUTPUT ldc-imports | 34 OUTPUT ldc-imports |
31 COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/import/ldc ${RUNTIME_DIR}/ldc | 35 COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/import/ldc ${RUNTIME_DIR}/ldc |
51 set(RUNTIME_AIO druntime-ldc) | 55 set(RUNTIME_AIO druntime-ldc) |
52 set(RUNTIME_DC_DIR ${RUNTIME_DIR}/src/compiler/ldc) | 56 set(RUNTIME_DC_DIR ${RUNTIME_DIR}/src/compiler/ldc) |
53 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/src/gc/basic) | 57 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/src/gc/basic) |
54 file(GLOB CORE_D ${RUNTIME_DIR}/src/common/core/*.d) | 58 file(GLOB CORE_D ${RUNTIME_DIR}/src/common/core/*.d) |
55 file(GLOB CORE_C ${RUNTIME_DIR}/src/common/core/stdc/*.c) | 59 file(GLOB CORE_C ${RUNTIME_DIR}/src/common/core/stdc/*.c) |
56 else(D_VERSION EQUAL 1) | |
57 message(FATAL_ERROR "set d version to 1 or 2") | |
58 endif(D_VERSION EQUAL 1) | 60 endif(D_VERSION EQUAL 1) |
59 | 61 |
60 # should only be necessary if run independently from ldc cmake project | 62 # should only be necessary if run independently from ldc cmake project |
61 if(NOT LDC_LOC) | 63 if(NOT LDC_LOC) |
62 if(NOT LDC_EXE) | 64 if(NOT LDC_EXE) |
83 add_custom_command( | 85 add_custom_command( |
84 OUTPUT patch-runtime | 86 OUTPUT patch-runtime |
85 COMMAND ${PATCH_EXE} -t -N -p0 -i ${PROJECT_SOURCE_DIR}/${LDC_EXE}.diff | 87 COMMAND ${PATCH_EXE} -t -N -p0 -i ${PROJECT_SOURCE_DIR}/${LDC_EXE}.diff |
86 WORKING_DIRECTORY ${RUNTIME_DIR} | 88 WORKING_DIRECTORY ${RUNTIME_DIR} |
87 ) | 89 ) |
90 # rebuild cache to include sources added by patch | |
88 add_custom_command( | 91 add_custom_command( |
89 OUTPUT recache | 92 OUTPUT recache |
90 COMMAND ${CMAKE_COMMAND} -H${PROJECT_PARENT_DIR} -B${PROJECT_BINARY_DIR}/.. | 93 COMMAND ${CMAKE_COMMAND} -H${PROJECT_PARENT_DIR} -B${PROJECT_BINARY_DIR}/.. |
91 ) | 94 ) |
92 add_custom_target(patch DEPENDS patch-runtime recache ${LDC_IMPORTS}) | 95 add_custom_target(patch DEPENDS patch-runtime recache ${LDC_IMPORTS}) |
95 file(GLOB GC_D ${RUNTIME_GC_DIR}/*.d) | 98 file(GLOB GC_D ${RUNTIME_GC_DIR}/*.d) |
96 file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) | 99 file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) |
97 file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c) | 100 file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c) |
98 | 101 |
99 # compile d file into outdir, include incdir, and append names of generated .o and .bc to outlist_o and _bc | 102 # 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) | 103 macro(dc INPUT_D OUTLIST_O OUTLIST_BC OUTDIR INCDIR MOREFLAGS) |
101 get_filename_component(BASENAME ${INPUT_D} NAME_WE) | 104 get_filename_component(BASENAME ${INPUT_D} NAME_WE) |
102 set(OUTPUT_O ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.o) | 105 set(OUTPUT_O ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.o) |
103 set(OUTPUT_BC ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.bc) | 106 set(OUTPUT_BC ${PROJECT_BINARY_DIR}/${OUTDIR}/${BASENAME}.bc) |
104 list(APPEND ${OUTLIST_O} ${OUTPUT_O}) | 107 list(APPEND ${OUTLIST_O} ${OUTPUT_O}) |
105 list(APPEND ${OUTLIST_BC} ${OUTPUT_BC}) | 108 list(APPEND ${OUTLIST_BC} ${OUTPUT_BC}) |
106 add_custom_command( | 109 add_custom_command( |
107 OUTPUT | 110 OUTPUT |
108 ${OUTPUT_O} | 111 ${OUTPUT_O} |
109 ${OUTPUT_BC} | 112 ${OUTPUT_BC} |
110 COMMAND ${LDC_LOC} -c -I${INCDIR} -output-bc ${INPUT_D} -of${OUTPUT_O} ${D_FLAGS} | 113 COMMAND ${LDC_LOC} -c -I${INCDIR} -output-bc ${INPUT_D} -of${OUTPUT_O} ${D_FLAGS} ${MOREFLAGS} |
111 DEPENDS ${LDC_LOC} | 114 DEPENDS ${LDC_LOC} |
112 ) | 115 ) |
113 endmacro(dc) | 116 endmacro(dc) |
114 | 117 |
115 # dc_dir include for core and gc only necessary with druntime | 118 # dc_dir include for core and gc only necessary with druntime |
116 foreach(f ${CORE_D}) | 119 foreach(f ${CORE_D}) |
117 dc(${f} CORE_O CORE_BC core ${RUNTIME_DC_DIR}) | 120 dc(${f} CORE_O CORE_BC core ${RUNTIME_DC_DIR} "") |
118 endforeach(f) | 121 endforeach(f) |
119 | 122 |
120 foreach(f ${GC_D}) | 123 foreach(f ${GC_D}) |
121 dc(${f} GC_O GC_BC gc "${RUNTIME_GC_DIR} ${RUNTIME_DC_DIR}") | 124 dc(${f} GC_O GC_BC gc "${RUNTIME_GC_DIR} ${RUNTIME_DC_DIR}" "-disable-invariants") |
122 endforeach(f) | 125 endforeach(f) |
123 | 126 |
124 foreach(f ${DCRT_D}) | 127 foreach(f ${DCRT_D}) |
125 dc(${f} DCRT_O DCRT_BC dcrt ${RUNTIME_DC_DIR}) | 128 dc(${f} DCRT_O DCRT_BC dcrt ${RUNTIME_DC_DIR} "") |
126 endforeach(f) | 129 endforeach(f) |
127 | 130 |
128 if(BUILD_SINGLE_LIB) | 131 if(BUILD_SINGLE_LIB) |
129 add_library(${RUNTIME_AIO} ${CORE_O} ${CORE_C} ${GC_O} ${DCRT_O} ${DCRT_C}) | 132 add_library(${RUNTIME_AIO} ${CORE_O} ${CORE_C} ${GC_O} ${DCRT_O} ${DCRT_C}) |
130 set(LIBS ${RUNTIME_AIO}) | 133 set(LIBS ${RUNTIME_AIO}) |