annotate runtime/CMakeLists.txt @ 791:3e0b643090f1

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