annotate CMakeLists.txt @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents 405e40f20ef9
children ac39e5449ca5
rev   line source
kamm@753 1 project(ldc)
kamm@749 2
kamm@753 3 cmake_minimum_required(VERSION 2.6)
kamm@753 4 # actually, 2.4 will work, with a warning
kamm@753 5 # if we required 2.4, 2.6+ would switch to a compatibility mode and cause problems on 2.6+ specifics
kamm@753 6
kamm@753 7 include(FindPerl)
kamm@753 8 if(NOT PERL)
kamm@753 9 message(FATAL_ERROR "perl not found")
kamm@753 10 endif(NOT PERL)
kamm@753 11
kamm@753 12 set(LLVM_INSTDIR CACHE PATH "LLVM installation directory")
kamm@753 13
kamm@753 14 find_program(LLVM_CONFIG llvm-config ${LLVM_INSTDIR}/bin DOC "path to llvm-config tool")
kamm@753 15 if(NOT LLVM_CONFIG)
kamm@753 16 message(FATAL_ERROR "llvm-config not found")
kamm@753 17 endif(NOT LLVM_CONFIG)
kamm@753 18
kamm@753 19 execute_process(
kamm@753 20 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --host-target
kamm@753 21 OUTPUT_VARIABLE HOST_TARGET
kamm@753 22 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 23 )
kamm@753 24 execute_process(
kamm@753 25 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags
kamm@753 26 OUTPUT_VARIABLE LLVM_CXXFLAGS
kamm@753 27 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 28 )
kamm@753 29 execute_process(
kamm@753 30 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --ldflags
kamm@753 31 OUTPUT_VARIABLE LLVM_LDFLAGS
kamm@753 32 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 33 )
kamm@753 34 execute_process(
kamm@753 35 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend
kamm@753 36 OUTPUT_VARIABLE LLVM_LIBS
kamm@753 37 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 38 )
kamm@753 39 # get llvm's install dir. a little hackish, we could do something like llvm-config --prefix, but this does as well
kamm@753 40 string(REPLACE "/bin/llvm-config" "" LLVM_INSTDIR ${LLVM_CONFIG})
kamm@753 41
tomas@758 42 set(D_VERSION 1 CACHE STRING "D language version")
tomas@758 43 if(D_VERSION EQUAL 1)
tomas@758 44 set(DMDFE_PATH dmd)
tomas@758 45 set(LDC_EXE ldc)
tomas@758 46 add_definitions(-DDMDV1)
tomas@758 47 elseif(D_VERSION EQUAL 2)
tomas@758 48 set(DMDFE_PATH dmd2)
tomas@758 49 set(LDC_EXE ldc2)
tomas@758 50 add_definitions(-DDMDV2)
tomas@758 51 else(D_VERSION EQUAL 1)
tomas@758 52 message(FATAL_ERROR "unsupported D version")
tomas@758 53 endif(D_VERSION EQUAL 1)
tomas@758 54
kamm@753 55 file(MAKE_DIRECTORY
kamm@753 56 ${PROJECT_BINARY_DIR}/bin
tomas@758 57 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@750 58 )
kamm@749 59
kamm@753 60 # idgen and impcnvgen
kamm@753 61 set_source_files_properties(
tomas@758 62 ${DMDFE_PATH}/idgen.c
tomas@758 63 ${DMDFE_PATH}/impcnvgen.c
kamm@753 64 PROPERTIES LANGUAGE CXX
kamm@750 65 )
tomas@758 66 add_executable(idgen ${DMDFE_PATH}/idgen.c)
tomas@758 67 add_executable(impcnvgen ${DMDFE_PATH}/impcnvgen.c)
kamm@753 68 # cmake 2.4
kamm@753 69 set_target_properties(
kamm@753 70 idgen impcnvgen PROPERTIES
kamm@753 71 LINKER_LANGUAGE CXX
kamm@753 72 )
kamm@753 73 get_target_property(IDGEN_LOC idgen LOCATION)
kamm@753 74 get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
kamm@753 75 #
kamm@753 76 add_custom_command(
kamm@753 77 OUTPUT
tomas@758 78 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 79 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
kamm@753 80 # 2.4
kamm@753 81 COMMAND ${IDGEN_LOC}
kamm@753 82 #COMMAND idgen
tomas@758 83 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 84 DEPENDS idgen
kamm@753 85 )
kamm@753 86 add_custom_command(
tomas@758 87 OUTPUT ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 88 # 2.4
kamm@753 89 COMMAND ${IMPCNVGEN_LOC}
kamm@753 90 #COMMAND impcnvgen
tomas@758 91 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 92 DEPENDS impcnvgen
kamm@753 93 )
kamm@753 94 set(LDC_GENERATED
tomas@758 95 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 96 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
tomas@758 97 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 98 )
kamm@753 99 # idgen and impcnvgen done
kamm@753 100
kamm@753 101 set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
kamm@753 102
tomas@758 103 include_directories(. ${DMDFE_PATH} ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${LLVM_INSTDIR}/include)
kamm@753 104
tomas@758 105 file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
kamm@753 106 file(GLOB GEN_SRC gen/*.cpp)
kamm@753 107 file(GLOB IR_SRC ir/*.cpp)
kamm@753 108 # exclude idgen and impcnvgen and generated sources, just in case
kamm@753 109 list(REMOVE_ITEM FE_SRC
tomas@758 110 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
tomas@758 111 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvgen.c
tomas@758 112 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
tomas@758 113 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 114 )
kamm@753 115 set(LDC_SOURCE_FILES
kamm@753 116 ${LDC_GENERATED}
kamm@753 117 ${FE_SRC}
kamm@753 118 ${GEN_SRC}
kamm@753 119 ${IR_SRC}
kamm@753 120 )
kamm@753 121 set_source_files_properties(
kamm@753 122 ${LDC_SOURCE_FILES} PROPERTIES
kamm@753 123 LANGUAGE CXX
kamm@750 124 )
kamm@749 125
kamm@753 126 add_definitions(
kamm@753 127 -DIN_LLVM
kamm@753 128 -D_DH
kamm@753 129 -DOPAQUE_VTBLS
kamm@753 130 -DUSE_BOEHM_GC=0
kamm@753 131 -DX86_REVERSE_PARAMS
kamm@753 132 -DX86_PASS_IN_EAX
kamm@750 133 )
kamm@749 134
kamm@753 135 if(UNIX)
kamm@753 136 add_definitions(-DPOSIX)
kamm@753 137 #set(CONF_SUFFIX conf)
kamm@753 138 endif(UNIX)
kamm@753 139
kamm@753 140 if(CMAKE_MINOR_VERSION LESS 6)
kamm@753 141 add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
kamm@753 142 else(CMAKE_MINOR_VERSION LESS 6)
kamm@753 143 add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
kamm@753 144 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@753 145
tomas@758 146 add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})
kamm@753 147
kamm@753 148 set_target_properties(
tomas@758 149 ${LDC_EXE} PROPERTIES
kamm@753 150 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
tomas@758 151 COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated -Wno-write-strings"
kamm@750 152 )
kamm@750 153
kamm@753 154 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
tomas@758 155 target_link_libraries(${LDC_EXE} "${LLVM_LDFLAGS} ${LLVM_LIBS}")
kamm@753 156 if(WIN32)
tomas@758 157 target_link_libraries(${LDC_EXE} psapi)
kamm@753 158 #set(CONF_SUFFIX ini)
kamm@753 159 endif(WIN32)
kamm@750 160
kamm@753 161 # cmake pre 2.6 doesn't support the RUNTIME_OUTPUT_DIRECTORY target property
kamm@753 162 if(CMAKE_MINOR_VERSION LESS 6)
tomas@758 163 get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
kamm@753 164 add_custom_command(
tomas@758 165 TARGET ${LDC_EXE}
kamm@753 166 POST_BUILD
kamm@753 167 COMMAND ${CMAKE_COMMAND} -E copy ${LDC_LOC} ${PROJECT_BINARY_DIR}/bin/
kamm@753 168 COMMAND ${CMAKE_COMMAND} -E remove ${LDC_LOC}
kamm@753 169 )
kamm@753 170 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@750 171
kamm@753 172 #configure_file(${PROJECT_SOURCE_DIR}/ldc.conf.in ${PROJECT_BINARY_DIR}/bin/ldc.${CONF_SUFFIX})
kamm@753 173
kamm@753 174 # TODO: runtime build
kamm@753 175 # possible problems:
kamm@753 176 # with an oos-build, how to set up a working environment, with conf/ini and tango in place?
kamm@753 177 # patch tango? how to determine if that's already been done?
kamm@753 178 # std but compatible runtime build, or shared, which doesn't yet work on every platform
kamm@753 179 #
kamm@753 180 # TODO: install target
kamm@753 181 # TODO: testrun