comparison 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
comparison
equal deleted inserted replaced
789:9433bcc45837 791:3e0b643090f1
1 project(runtime) 1 project(runtime)
2 2
3 cmake_minimum_required(VERSION 2.6) 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 4
8 find_program(GCC_EXE gcc DOC "path to gcc binary") 5 find_program(GCC_EXE gcc DOC "path to gcc binary")
9 if(NOT GCC_EXE) 6 if(NOT GCC_EXE)
10 message(STATUS "gcc needs to be on your path to build the runtime") 7 message(STATUS "gcc needs to be on your path to build the runtime")
11 endif(NOT GCC_EXE) 8 endif(NOT GCC_EXE)
13 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)")
14 option(BUILD_BC_LIBS "build the runtime as bytecode libraries") 11 option(BUILD_BC_LIBS "build the runtime as bytecode libraries")
15 option(BUILD_SINGLE_LIB "build single runtime library" ON) 12 option(BUILD_SINGLE_LIB "build single runtime library" ON)
16 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 ;")
17 14
18 get_directory_property(PROJECT_PARENT_DIR DIRECTORY ${PROJECT_SOURCE_DIR} PARENT_DIRECTORY)
19 if(D_VERSION EQUAL 1) 15 if(D_VERSION EQUAL 1)
20 set(RUNTIME tango) 16 set(RUNTIME tango)
21 set(LDC_EXE ldc)
22 elseif(D_VERSION EQUAL 2) 17 elseif(D_VERSION EQUAL 2)
23 set(RUNTIME druntime) 18 set(RUNTIME druntime)
24 set(LDC_EXE ldc2)
25 else(D_VERSION EQUAL 1) 19 else(D_VERSION EQUAL 1)
26 message(FATAL_ERROR "set d version to 1 or 2") 20 message(FATAL_ERROR "set d version to 1 or 2")
27 endif(D_VERSION EQUAL 1) 21 endif(D_VERSION EQUAL 1)
22 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 24
29 set(RUNTIME_DIR ${PROJECT_PARENT_DIR}/${RUNTIME} CACHE PATH "runtime source dir" FORCE) 25 if(D_VERSION EQUAL 1)
26 # build tango for D1, druntime for D2
27 set(LDC_EXE ldc)
28 # copy imports to runtime dir
29 add_custom_command(
30 OUTPUT ldc-imports
31 COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/import/ldc ${RUNTIME_DIR}/ldc
32 COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/internal/ldc/bitmanip.d ${RUNTIME_DIR}/ldc
33 COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/internal/ldc/vararg.d ${RUNTIME_DIR}/ldc
34 )
35 set(LDC_IMPORTS ldc-imports)
36 # library names
37 set(RUNTIME_CC tango-cc-tango)
38 set(RUNTIME_GC tango-gc-basic)
39 set(RUNTIME_DC ldc-runtime)
40 set(RUNTIME_AIO tango-ldc)
41 # set paths to source files, or fill lists directly
42 set(RUNTIME_DC_DIR ${PROJECT_SOURCE_DIR}/internal)
43 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/lib/gc/basic)
44 file(GLOB CORE_D ${RUNTIME_DIR}/lib/common/tango/core/*.d)
45 file(GLOB CORE_C ${RUNTIME_DIR}/lib/common/tango/stdc/*.c)
46 elseif(D_VERSION EQUAL 2)
47 set(LDC_EXE ldc2)
48 set(RUNTIME_CC druntime-core)
49 set(RUNTIME_GC druntime-gc-basic)
50 set(RUNTIME_DC druntime-rt-ldc)
51 set(RUNTIME_AIO druntime-ldc)
52 set(RUNTIME_DC_DIR ${RUNTIME_DIR}/src/compiler/ldc)
53 set(RUNTIME_GC_DIR ${RUNTIME_DIR}/src/gc/basic)
54 file(GLOB CORE_D ${RUNTIME_DIR}/src/common/core/*.d)
55 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)
30 59
31 # should only be necessary if run independently from ldc cmake project 60 # should only be necessary if run independently from ldc cmake project
32 if(NOT LDC_LOC) 61 if(NOT LDC_LOC)
33 if(NOT LDC_EXE) 62 if(NOT LDC_EXE)
34 if(D_VERSION EQUAL 1) 63 if(D_VERSION EQUAL 1)
41 find_program(LDC_LOC ${LDC_EXE} ../bin DOC "path to ldc binary") 70 find_program(LDC_LOC ${LDC_EXE} ../bin DOC "path to ldc binary")
42 if(NOT LDC_LOC) 71 if(NOT LDC_LOC)
43 message(SEND_ERROR "ldc not found") 72 message(SEND_ERROR "ldc not found")
44 endif(NOT LDC_LOC) 73 endif(NOT LDC_LOC)
45 endif(NOT LDC_LOC) 74 endif(NOT LDC_LOC)
46 #
47 75
48 configure_file(${PROJECT_PARENT_DIR}/${LDC_EXE}.conf.in ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}.conf) 76 configure_file(${PROJECT_PARENT_DIR}/${LDC_EXE}.conf.in ${PROJECT_BINARY_DIR}/../bin/${LDC_EXE}.conf)
49 77
50 # patch runtime source, uses LDC_EXE for ldc / ldc2 78 # patch runtime source, uses LDC_EXE for ldc / ldc2
51 find_program(PATCH_EXE patch DOC "path to patch tool") 79 find_program(PATCH_EXE patch DOC "path to patch tool")
55 add_custom_command( 83 add_custom_command(
56 OUTPUT patch-runtime 84 OUTPUT patch-runtime
57 COMMAND ${PATCH_EXE} -t -N -p0 -i ${PROJECT_SOURCE_DIR}/${LDC_EXE}.diff 85 COMMAND ${PATCH_EXE} -t -N -p0 -i ${PROJECT_SOURCE_DIR}/${LDC_EXE}.diff
58 WORKING_DIRECTORY ${RUNTIME_DIR} 86 WORKING_DIRECTORY ${RUNTIME_DIR}
59 ) 87 )
60 add_custom_target(patch DEPENDS patch-runtime) 88 add_custom_command(
89 OUTPUT recache
90 COMMAND ${CMAKE_COMMAND} -H${PROJECT_PARENT_DIR} -B${PROJECT_BINARY_DIR}/..
91 )
92 add_custom_target(patch DEPENDS patch-runtime recache ${LDC_IMPORTS})
61 endif(NOT PATCH_EXE) 93 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 94
95 file(GLOB GC_D ${RUNTIME_GC_DIR}/*.d) 95 file(GLOB GC_D ${RUNTIME_GC_DIR}/*.d)
96 file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) 96 file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d)
97 file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c) 97 file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c)
98 98
110 COMMAND ${LDC_LOC} -c -I${INCDIR} -output-bc ${INPUT_D} -of${OUTPUT_O} ${D_FLAGS} 110 COMMAND ${LDC_LOC} -c -I${INCDIR} -output-bc ${INPUT_D} -of${OUTPUT_O} ${D_FLAGS}
111 DEPENDS ${LDC_LOC} 111 DEPENDS ${LDC_LOC}
112 ) 112 )
113 endmacro(dc) 113 endmacro(dc)
114 114
115 # dc_dir include for core and gc only necessary with druntime
115 foreach(f ${CORE_D}) 116 foreach(f ${CORE_D})
116 dc(${f} CORE_O CORE_BC core .) 117 dc(${f} CORE_O CORE_BC core ${RUNTIME_DC_DIR})
117 endforeach(f) 118 endforeach(f)
118 119
119 foreach(f ${GC_D}) 120 foreach(f ${GC_D})
120 dc(${f} GC_O GC_BC gc ${RUNTIME_GC_DIR}) 121 dc(${f} GC_O GC_BC gc "${RUNTIME_GC_DIR} ${RUNTIME_DC_DIR}")
121 endforeach(f) 122 endforeach(f)
122 123
123 foreach(f ${DCRT_D}) 124 foreach(f ${DCRT_D})
124 dc(${f} DCRT_O DCRT_BC dcrt ${RUNTIME_DC_DIR}) 125 dc(${f} DCRT_O DCRT_BC dcrt ${RUNTIME_DC_DIR})
125 endforeach(f) 126 endforeach(f)