| 3 | | set (LDC_SOURCE_FILES |
|---|
| 4 | | dmd/access.c |
|---|
| 5 | | dmd/array.c |
|---|
| 6 | | dmd/arrayop.c |
|---|
| 7 | | dmd/attrib.c |
|---|
| 8 | | dmd/cast.c |
|---|
| 9 | | dmd/class.c |
|---|
| 10 | | dmd/clone.c |
|---|
| 11 | | dmd/cond.c |
|---|
| 12 | | dmd/constfold.c |
|---|
| 13 | | dmd/dchar.c |
|---|
| 14 | | dmd/declaration.c |
|---|
| 15 | | dmd/delegatize.c |
|---|
| 16 | | dmd/doc.c |
|---|
| 17 | | dmd/dsymbol.c |
|---|
| 18 | | dmd/dump.c |
|---|
| 19 | | dmd/entity.c |
|---|
| 20 | | dmd/enum.c |
|---|
| 21 | | dmd/expression.c |
|---|
| 22 | | dmd/func.c |
|---|
| 23 | | dmd/gnuc.c |
|---|
| 24 | | dmd/hdrgen.c |
|---|
| 25 | | dmd/html.c |
|---|
| 26 | | dmd/identifier.c |
|---|
| 27 | | dmd/import.c |
|---|
| 28 | | dmd/inifile.c |
|---|
| 29 | | dmd/init.c |
|---|
| 30 | | dmd/inline.c |
|---|
| 31 | | dmd/interpret.c |
|---|
| 32 | | dmd/lexer.c |
|---|
| 33 | | dmd/lstring.c |
|---|
| 34 | | dmd/macro.c |
|---|
| 35 | | dmd/man.c |
|---|
| 36 | | dmd/mangle.c |
|---|
| 37 | | dmd/mars.c |
|---|
| 38 | | dmd/mem.c |
|---|
| 39 | | dmd/module.c |
|---|
| 40 | | dmd/mtype.c |
|---|
| 41 | | dmd/opover.c |
|---|
| 42 | | dmd/optimize.c |
|---|
| 43 | | dmd/parse.c |
|---|
| 44 | | dmd/root.c |
|---|
| 45 | | dmd/scope.c |
|---|
| 46 | | dmd/statement.c |
|---|
| 47 | | dmd/staticassert.c |
|---|
| 48 | | dmd/stringtable.c |
|---|
| 49 | | dmd/struct.c |
|---|
| 50 | | dmd/template.c |
|---|
| 51 | | dmd/unialpha.c |
|---|
| 52 | | dmd/utf.c |
|---|
| 53 | | dmd/version.c |
|---|
| 54 | | gen/aa.cpp |
|---|
| 55 | | gen/arrays.cpp |
|---|
| 56 | | gen/asmstmt.cpp |
|---|
| 57 | | gen/binops.cpp |
|---|
| 58 | | gen/classes.cpp |
|---|
| 59 | | gen/complex.cpp |
|---|
| 60 | | gen/dvalue.cpp |
|---|
| 61 | | gen/dwarftypes.cpp |
|---|
| 62 | | gen/functions.cpp |
|---|
| 63 | | gen/irstate.cpp |
|---|
| 64 | | gen/linker.cpp |
|---|
| 65 | | gen/llvmhelpers.cpp |
|---|
| 66 | | gen/logger.cpp |
|---|
| 67 | | gen/optimizer.cpp |
|---|
| 68 | | gen/runtime.cpp |
|---|
| 69 | | gen/statements.cpp |
|---|
| 70 | | gen/structs.cpp |
|---|
| 71 | | gen/tocall.cpp |
|---|
| 72 | | gen/tocsym.cpp |
|---|
| 73 | | gen/todebug.cpp |
|---|
| 74 | | gen/todt.cpp |
|---|
| 75 | | gen/toir.cpp |
|---|
| 76 | | gen/tollvm.cpp |
|---|
| 77 | | gen/toobj.cpp |
|---|
| 78 | | gen/typinf.cpp |
|---|
| 79 | | ir/irfunction.cpp |
|---|
| 80 | | ir/irlandingpad.cpp |
|---|
| 81 | | ir/irmodule.cpp |
|---|
| 82 | | ir/irstruct.cpp |
|---|
| 83 | | ir/irsymbol.cpp |
|---|
| 84 | | ir/irtype.cpp |
|---|
| 85 | | ir/irvar.cpp |
|---|
| | 3 | cmake_minimum_required(VERSION 2.6) |
|---|
| | 4 | # actually, 2.4 will work, with a warning |
|---|
| | 5 | # if we required 2.4, 2.6+ would switch to a compatibility mode and cause problems on 2.6+ specifics |
|---|
| | 6 | |
|---|
| | 7 | include(FindPerl) |
|---|
| | 8 | if(NOT PERL) |
|---|
| | 9 | message(FATAL_ERROR "perl not found") |
|---|
| | 10 | endif(NOT PERL) |
|---|
| | 11 | |
|---|
| | 12 | set(LLVM_INSTDIR CACHE PATH "LLVM installation directory") |
|---|
| | 13 | |
|---|
| | 14 | find_program(LLVM_CONFIG llvm-config ${LLVM_INSTDIR}/bin DOC "path to llvm-config tool") |
|---|
| | 15 | if(NOT LLVM_CONFIG) |
|---|
| | 16 | message(FATAL_ERROR "llvm-config not found") |
|---|
| | 17 | endif(NOT LLVM_CONFIG) |
|---|
| | 18 | |
|---|
| | 19 | execute_process( |
|---|
| | 20 | COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --host-target |
|---|
| | 21 | OUTPUT_VARIABLE HOST_TARGET |
|---|
| | 22 | OUTPUT_STRIP_TRAILING_WHITESPACE |
|---|
| | 23 | ) |
|---|
| | 24 | execute_process( |
|---|
| | 25 | COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags |
|---|
| | 26 | OUTPUT_VARIABLE LLVM_CXXFLAGS |
|---|
| | 27 | OUTPUT_STRIP_TRAILING_WHITESPACE |
|---|
| | 28 | ) |
|---|
| | 29 | execute_process( |
|---|
| | 30 | COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --ldflags |
|---|
| | 31 | OUTPUT_VARIABLE LLVM_LDFLAGS |
|---|
| | 32 | OUTPUT_STRIP_TRAILING_WHITESPACE |
|---|
| | 33 | ) |
|---|
| | 34 | execute_process( |
|---|
| | 35 | COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend |
|---|
| | 36 | OUTPUT_VARIABLE LLVM_LIBS |
|---|
| | 37 | OUTPUT_STRIP_TRAILING_WHITESPACE |
|---|
| | 38 | ) |
|---|
| | 39 | # get llvm's install dir. a little hackish, we could do something like llvm-config --prefix, but this does as well |
|---|
| | 40 | string(REPLACE "/bin/llvm-config" "" LLVM_INSTDIR ${LLVM_CONFIG}) |
|---|
| | 41 | |
|---|
| | 42 | file(MAKE_DIRECTORY |
|---|
| | 43 | ${PROJECT_BINARY_DIR}/bin |
|---|
| | 44 | ${PROJECT_BINARY_DIR}/dmd |
|---|
| 92 | | set (LDC_GENERATED_HEADER_FILES |
|---|
| 93 | | ${CMAKE_CURRENT_BINARY_DIR}/id.h |
|---|
| | 53 | add_executable(idgen dmd/idgen.c) |
|---|
| | 54 | add_executable(impcnvgen dmd/impcnvgen.c) |
|---|
| | 55 | # cmake 2.4 |
|---|
| | 56 | set_target_properties( |
|---|
| | 57 | idgen impcnvgen PROPERTIES |
|---|
| | 58 | LINKER_LANGUAGE CXX |
|---|
| | 59 | ) |
|---|
| | 60 | get_target_property(IDGEN_LOC idgen LOCATION) |
|---|
| | 61 | get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION) |
|---|
| | 62 | # |
|---|
| | 63 | add_custom_command( |
|---|
| | 64 | OUTPUT |
|---|
| | 65 | ${PROJECT_BINARY_DIR}/dmd/id.c |
|---|
| | 66 | ${PROJECT_BINARY_DIR}/dmd/id.h |
|---|
| | 67 | # 2.4 |
|---|
| | 68 | COMMAND ${IDGEN_LOC} |
|---|
| | 69 | #COMMAND idgen |
|---|
| | 70 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/dmd |
|---|
| | 71 | DEPENDS idgen |
|---|
| | 72 | ) |
|---|
| | 73 | add_custom_command( |
|---|
| | 74 | OUTPUT ${PROJECT_BINARY_DIR}/dmd/impcnvtab.c |
|---|
| | 75 | # 2.4 |
|---|
| | 76 | COMMAND ${IMPCNVGEN_LOC} |
|---|
| | 77 | #COMMAND impcnvgen |
|---|
| | 78 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/dmd |
|---|
| | 79 | DEPENDS impcnvgen |
|---|
| | 80 | ) |
|---|
| | 81 | set(LDC_GENERATED |
|---|
| | 82 | ${PROJECT_BINARY_DIR}/dmd/id.c |
|---|
| | 83 | ${PROJECT_BINARY_DIR}/dmd/id.h |
|---|
| | 84 | ${PROJECT_BINARY_DIR}/dmd/impcnvtab.c |
|---|
| | 85 | ) |
|---|
| | 86 | # idgen and impcnvgen done |
|---|
| | 87 | |
|---|
| | 88 | set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target") |
|---|
| | 89 | |
|---|
| | 90 | include_directories(. dmd ${PROJECT_BINARY_DIR}/dmd ${LLVM_INSTDIR}/include) |
|---|
| | 91 | |
|---|
| | 92 | file(GLOB FE_SRC dmd/*.c) |
|---|
| | 93 | file(GLOB GEN_SRC gen/*.cpp) |
|---|
| | 94 | file(GLOB IR_SRC ir/*.cpp) |
|---|
| | 95 | # exclude idgen and impcnvgen and generated sources, just in case |
|---|
| | 96 | list(REMOVE_ITEM FE_SRC |
|---|
| | 97 | ${PROJECT_SOURCE_DIR}/dmd/idgen.c |
|---|
| | 98 | ${PROJECT_SOURCE_DIR}/dmd/impcnvgen.c |
|---|
| | 99 | ${PROJECT_SOURCE_DIR}/dmd/id.c |
|---|
| | 100 | ${PROJECT_SOURCE_DIR}/dmd/impcnvtab.c |
|---|
| | 101 | ) |
|---|
| | 102 | set(LDC_SOURCE_FILES |
|---|
| | 103 | ${LDC_GENERATED} |
|---|
| | 104 | ${FE_SRC} |
|---|
| | 105 | ${GEN_SRC} |
|---|
| | 106 | ${IR_SRC} |
|---|
| | 107 | ) |
|---|
| | 108 | set_source_files_properties( |
|---|
| | 109 | ${LDC_SOURCE_FILES} PROPERTIES |
|---|
| | 110 | LANGUAGE CXX |
|---|
| 103 | | # mark all source as c++ |
|---|
| 104 | | set_source_files_properties ( |
|---|
| 105 | | ${LDC_SOURCE_FILES} ${LDC_GENERATED_SOURCE_FILES} |
|---|
| 106 | | PROPERTIES LANGUAGE CXX |
|---|
| | 123 | if(UNIX) |
|---|
| | 124 | add_definitions(-DPOSIX) |
|---|
| | 125 | #set(CONF_SUFFIX conf) |
|---|
| | 126 | endif(UNIX) |
|---|
| | 127 | |
|---|
| | 128 | if(CMAKE_MINOR_VERSION LESS 6) |
|---|
| | 129 | add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\") |
|---|
| | 130 | else(CMAKE_MINOR_VERSION LESS 6) |
|---|
| | 131 | add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}") |
|---|
| | 132 | endif(CMAKE_MINOR_VERSION LESS 6) |
|---|
| | 133 | |
|---|
| | 134 | add_executable(ldc ${LDC_SOURCE_FILES}) |
|---|
| | 135 | |
|---|
| | 136 | set_target_properties( |
|---|
| | 137 | ldc PROPERTIES |
|---|
| | 138 | RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin |
|---|
| | 139 | COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated" |
|---|
| 109 | | # build and run idgen and impcnvgen |
|---|
| 110 | | set_source_files_properties ( |
|---|
| 111 | | dmd/impcnvgen.c |
|---|
| 112 | | dmd/idgen.c |
|---|
| 113 | | PROPERTIES LANGUAGE CXX |
|---|
| 114 | | ) |
|---|
| 115 | | add_executable (impcnvgen dmd/impcnvgen.c) |
|---|
| 116 | | add_executable (idgen dmd/idgen.c) |
|---|
| 117 | | set_target_properties (impcnvgen idgen PROPERTIES LINKER_LANGUAGE CXX) |
|---|
| 118 | | get_target_property (IMPCNVGEN_EXE impcnvgen LOCATION) |
|---|
| 119 | | get_target_property (IDGEN_EXE idgen LOCATION) |
|---|
| 120 | | add_custom_command ( |
|---|
| 121 | | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/impcnvtab.c |
|---|
| 122 | | COMMAND ${IMPCNVGEN_EXE} |
|---|
| 123 | | DEPENDS impcnvgen |
|---|
| 124 | | ) |
|---|
| 125 | | add_custom_command ( |
|---|
| 126 | | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/id.c ${CMAKE_CURRENT_BINARY_DIR}/id.h |
|---|
| 127 | | COMMAND ${IDGEN_EXE} |
|---|
| 128 | | DEPENDS idgen |
|---|
| 129 | | ) |
|---|
| | 142 | # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems |
|---|
| | 143 | target_link_libraries(ldc "${LLVM_LDFLAGS} ${LLVM_LIBS}") |
|---|
| | 144 | if(WIN32) |
|---|
| | 145 | target_link_libraries(ldc psapi) |
|---|
| | 146 | #set(CONF_SUFFIX ini) |
|---|
| | 147 | endif(WIN32) |
|---|
| 134 | | |
|---|
| 135 | | # setup DEFAULT_TARGET_TRIPLE |
|---|
| 136 | | execute_process (COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/config.guess OUTPUT_VARIABLE DEFAULT_TARGET_TRIPLE_GUESS OUTPUT_STRIP_TRAILING_WHITESPACE) |
|---|
| 137 | | set (DEFAULT_TARGET_TRIPLE ${DEFAULT_TARGET_TRIPLE_GUESS} CACHE STRING "the default target triple LDC should compile for") |
|---|
| 138 | | |
|---|
| 139 | | # setup POSIX |
|---|
| 140 | | if (WIN32) |
|---|
| 141 | | set (POSIX_GUESS 0) |
|---|
| 142 | | else (WIN32) |
|---|
| 143 | | set (POSIX_GUESS 1) |
|---|
| 144 | | endif (WIN32) |
|---|
| 145 | | set (POSIX ${POSIX_GUESS} CACHE BOOL "is LDC build on POSIX?") |
|---|
| 146 | | |
|---|
| 147 | | # setup defines |
|---|
| 148 | | set (LDC_DEFINES |
|---|
| 149 | | -DIN_LLVM |
|---|
| 150 | | -D_DH |
|---|
| 151 | | -DOPAQUE_VTBLS |
|---|
| 152 | | -DUSE_BOEHM_GC=0 |
|---|
| 153 | | -DDMDV1 |
|---|
| 154 | | -DPOSIX=${POSIX} |
|---|
| 155 | | -DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET_TRIPLE}\\" |
|---|
| 156 | | -DX86_REVERSE_PARAMS=1 |
|---|
| 157 | | -DX86_PASS_IN_EAX=1) |
|---|
| 158 | | execute_process (COMMAND llvm-config --cxxflags OUTPUT_VARIABLE LLVM_CXXFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) |
|---|
| 159 | | # passing CXXFLAGS here is not good style |
|---|
| 160 | | add_definitions (${LDC_DEFINES} ${LLVM_CXXFLAGS}) |
|---|
| 161 | | |
|---|
| 162 | | include_directories (. dmd ${CMAKE_CURRENT_BINARY_DIR}) |
|---|
| 163 | | |
|---|
| 164 | | # this is hackish, but works |
|---|
| 165 | | target_link_libraries (ldc "`llvm-config --ldflags` `llvm-config --libs bitwriter linker ipo instrumentation backend`") |
|---|
| 166 | | |
|---|
| 167 | | #TODO: runtime build |
|---|
| | 160 | #configure_file(${PROJECT_SOURCE_DIR}/ldc.conf.in ${PROJECT_BINARY_DIR}/bin/ldc.${CONF_SUFFIX}) |
|---|
| | 161 | |
|---|
| | 162 | # TODO: runtime build |
|---|
| | 163 | # possible problems: |
|---|
| | 164 | # with an oos-build, how to set up a working environment, with conf/ini and tango in place? |
|---|
| | 165 | # patch tango? how to determine if that's already been done? |
|---|
| | 166 | # std but compatible runtime build, or shared, which doesn't yet work on every platform |
|---|
| | 167 | # |
|---|
| | 168 | # TODO: install target |
|---|
| | 169 | # TODO: testrun |
|---|