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