annotate CMakeLists.txt @ 753:405e40f20ef9

Switch to Elrood's rewritten CMakeLists.txt.
author Christian Kamm <kamm incasoftware de>
date Wed, 05 Nov 2008 16:53:03 +0100
parents d05fc504a3a0
children f04dde6e882c
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
kamm@753 42 file(MAKE_DIRECTORY
kamm@753 43 ${PROJECT_BINARY_DIR}/bin
kamm@753 44 ${PROJECT_BINARY_DIR}/dmd
kamm@750 45 )
kamm@749 46
kamm@753 47 # idgen and impcnvgen
kamm@753 48 set_source_files_properties(
kamm@753 49 dmd/idgen.c
kamm@753 50 dmd/impcnvgen.c
kamm@753 51 PROPERTIES LANGUAGE CXX
kamm@750 52 )
kamm@753 53 add_executable(idgen dmd/idgen.c)
kamm@753 54 add_executable(impcnvgen dmd/impcnvgen.c)
kamm@753 55 # cmake 2.4
kamm@753 56 set_target_properties(
kamm@753 57 idgen impcnvgen PROPERTIES
kamm@753 58 LINKER_LANGUAGE CXX
kamm@753 59 )
kamm@753 60 get_target_property(IDGEN_LOC idgen LOCATION)
kamm@753 61 get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
kamm@753 62 #
kamm@753 63 add_custom_command(
kamm@753 64 OUTPUT
kamm@753 65 ${PROJECT_BINARY_DIR}/dmd/id.c
kamm@753 66 ${PROJECT_BINARY_DIR}/dmd/id.h
kamm@753 67 # 2.4
kamm@753 68 COMMAND ${IDGEN_LOC}
kamm@753 69 #COMMAND idgen
kamm@753 70 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/dmd
kamm@753 71 DEPENDS idgen
kamm@753 72 )
kamm@753 73 add_custom_command(
kamm@753 74 OUTPUT ${PROJECT_BINARY_DIR}/dmd/impcnvtab.c
kamm@753 75 # 2.4
kamm@753 76 COMMAND ${IMPCNVGEN_LOC}
kamm@753 77 #COMMAND impcnvgen
kamm@753 78 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/dmd
kamm@753 79 DEPENDS impcnvgen
kamm@753 80 )
kamm@753 81 set(LDC_GENERATED
kamm@753 82 ${PROJECT_BINARY_DIR}/dmd/id.c
kamm@753 83 ${PROJECT_BINARY_DIR}/dmd/id.h
kamm@753 84 ${PROJECT_BINARY_DIR}/dmd/impcnvtab.c
kamm@753 85 )
kamm@753 86 # idgen and impcnvgen done
kamm@753 87
kamm@753 88 set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
kamm@753 89
kamm@753 90 include_directories(. dmd ${PROJECT_BINARY_DIR}/dmd ${LLVM_INSTDIR}/include)
kamm@753 91
kamm@753 92 file(GLOB FE_SRC dmd/*.c)
kamm@753 93 file(GLOB GEN_SRC gen/*.cpp)
kamm@753 94 file(GLOB IR_SRC ir/*.cpp)
kamm@753 95 # exclude idgen and impcnvgen and generated sources, just in case
kamm@753 96 list(REMOVE_ITEM FE_SRC
kamm@753 97 ${PROJECT_SOURCE_DIR}/dmd/idgen.c
kamm@753 98 ${PROJECT_SOURCE_DIR}/dmd/impcnvgen.c
kamm@753 99 ${PROJECT_SOURCE_DIR}/dmd/id.c
kamm@753 100 ${PROJECT_SOURCE_DIR}/dmd/impcnvtab.c
kamm@753 101 )
kamm@753 102 set(LDC_SOURCE_FILES
kamm@753 103 ${LDC_GENERATED}
kamm@753 104 ${FE_SRC}
kamm@753 105 ${GEN_SRC}
kamm@753 106 ${IR_SRC}
kamm@753 107 )
kamm@753 108 set_source_files_properties(
kamm@753 109 ${LDC_SOURCE_FILES} PROPERTIES
kamm@753 110 LANGUAGE CXX
kamm@750 111 )
kamm@749 112
kamm@753 113 add_definitions(
kamm@753 114 -DIN_LLVM
kamm@753 115 -D_DH
kamm@753 116 -DOPAQUE_VTBLS
kamm@753 117 -DUSE_BOEHM_GC=0
kamm@753 118 -DDMDV1
kamm@753 119 -DX86_REVERSE_PARAMS
kamm@753 120 -DX86_PASS_IN_EAX
kamm@750 121 )
kamm@749 122
kamm@753 123 if(UNIX)
kamm@753 124 add_definitions(-DPOSIX)
kamm@753 125 #set(CONF_SUFFIX conf)
kamm@753 126 endif(UNIX)
kamm@753 127
kamm@753 128 if(CMAKE_MINOR_VERSION LESS 6)
kamm@753 129 add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
kamm@753 130 else(CMAKE_MINOR_VERSION LESS 6)
kamm@753 131 add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
kamm@753 132 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@753 133
kamm@753 134 add_executable(ldc ${LDC_SOURCE_FILES})
kamm@753 135
kamm@753 136 set_target_properties(
kamm@753 137 ldc PROPERTIES
kamm@753 138 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
kamm@753 139 COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated"
kamm@750 140 )
kamm@750 141
kamm@753 142 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
kamm@753 143 target_link_libraries(ldc "${LLVM_LDFLAGS} ${LLVM_LIBS}")
kamm@753 144 if(WIN32)
kamm@753 145 target_link_libraries(ldc psapi)
kamm@753 146 #set(CONF_SUFFIX ini)
kamm@753 147 endif(WIN32)
kamm@750 148
kamm@753 149 # cmake pre 2.6 doesn't support the RUNTIME_OUTPUT_DIRECTORY target property
kamm@753 150 if(CMAKE_MINOR_VERSION LESS 6)
kamm@753 151 get_target_property(LDC_LOC ldc LOCATION)
kamm@753 152 add_custom_command(
kamm@753 153 TARGET ldc
kamm@753 154 POST_BUILD
kamm@753 155 COMMAND ${CMAKE_COMMAND} -E copy ${LDC_LOC} ${PROJECT_BINARY_DIR}/bin/
kamm@753 156 COMMAND ${CMAKE_COMMAND} -E remove ${LDC_LOC}
kamm@753 157 )
kamm@753 158 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@750 159
kamm@753 160 #configure_file(${PROJECT_SOURCE_DIR}/ldc.conf.in ${PROJECT_BINARY_DIR}/bin/ldc.${CONF_SUFFIX})
kamm@753 161
kamm@753 162 # TODO: runtime build
kamm@753 163 # possible problems:
kamm@753 164 # with an oos-build, how to set up a working environment, with conf/ini and tango in place?
kamm@753 165 # patch tango? how to determine if that's already been done?
kamm@753 166 # std but compatible runtime build, or shared, which doesn't yet work on every platform
kamm@753 167 #
kamm@753 168 # TODO: install target
kamm@753 169 # TODO: testrun