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