annotate CMakeLists.txt @ 853:82ad6c0c601c

Add Elrood's patch to output LDC and LLVM source revs.
author Christian Kamm <kamm incasoftware de>
date Sun, 14 Dec 2008 16:51:36 +0100
parents 0a31c60a6bc1
children b52d5de7783f
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@785 12 find_program(LLVM_CONFIG llvm-config ${LLVM_INSTDIR}/bin DOC "path to llvm-config tool")
kamm@785 13 # get llvm's install dir. a little hackish, we could do something like llvm-config --prefix, but this does as well
kamm@785 14 string(REPLACE "/bin/llvm-config" "" LLVM_DIR ${LLVM_CONFIG})
kamm@753 15
kamm@785 16 set(LLVM_INSTDIR ${LLVM_DIR} CACHE PATH "LLVM installation directory" FORCE)
kamm@785 17 if(NOT LLVM_INSTDIR)
kamm@785 18 message(FATAL_ERROR "llvm not found")
kamm@785 19 endif(NOT LLVM_INSTDIR)
kamm@753 20
kamm@753 21 execute_process(
kamm@753 22 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --host-target
kamm@753 23 OUTPUT_VARIABLE HOST_TARGET
kamm@753 24 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 25 )
kamm@753 26 execute_process(
kamm@753 27 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags
kamm@753 28 OUTPUT_VARIABLE LLVM_CXXFLAGS
kamm@753 29 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 30 )
kamm@753 31 execute_process(
kamm@753 32 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --ldflags
kamm@753 33 OUTPUT_VARIABLE LLVM_LDFLAGS
kamm@753 34 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 35 )
kamm@753 36 execute_process(
kamm@753 37 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend
kamm@753 38 OUTPUT_VARIABLE LLVM_LIBS
kamm@753 39 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 40 )
kamm@753 41
tomas@758 42 set(D_VERSION 1 CACHE STRING "D language version")
elrood@828 43 set(PROGRAM_PREFIX CACHE STRING "prepended to ldc binary name")
elrood@828 44 set(PROGRAM_SUFFIX CACHE STRING "appended to ldc binary name")
kamm@785 45 option(USE_BOEHM_GC "use the Boehm garbage collector internally")
tomas@821 46 option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
kamm@785 47
tomas@758 48 if(D_VERSION EQUAL 1)
tomas@758 49 set(DMDFE_PATH dmd)
tomas@758 50 set(LDC_EXE ldc)
tomas@758 51 add_definitions(-DDMDV1)
tomas@758 52 elseif(D_VERSION EQUAL 2)
tomas@758 53 set(DMDFE_PATH dmd2)
tomas@758 54 set(LDC_EXE ldc2)
tomas@758 55 add_definitions(-DDMDV2)
tomas@758 56 else(D_VERSION EQUAL 1)
tomas@758 57 message(FATAL_ERROR "unsupported D version")
tomas@758 58 endif(D_VERSION EQUAL 1)
tomas@758 59
kamm@753 60 file(MAKE_DIRECTORY
kamm@753 61 ${PROJECT_BINARY_DIR}/bin
tomas@758 62 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@750 63 )
kamm@749 64
kamm@753 65 # idgen and impcnvgen
kamm@753 66 set_source_files_properties(
tomas@758 67 ${DMDFE_PATH}/idgen.c
tomas@758 68 ${DMDFE_PATH}/impcnvgen.c
kamm@753 69 PROPERTIES LANGUAGE CXX
kamm@750 70 )
tomas@758 71 add_executable(idgen ${DMDFE_PATH}/idgen.c)
tomas@758 72 add_executable(impcnvgen ${DMDFE_PATH}/impcnvgen.c)
kamm@753 73 # cmake 2.4
kamm@753 74 set_target_properties(
kamm@753 75 idgen impcnvgen PROPERTIES
kamm@753 76 LINKER_LANGUAGE CXX
kamm@785 77 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 78 )
kamm@753 79 get_target_property(IDGEN_LOC idgen LOCATION)
kamm@753 80 get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
kamm@753 81 #
kamm@753 82 add_custom_command(
kamm@753 83 OUTPUT
tomas@758 84 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 85 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
kamm@753 86 # 2.4
kamm@753 87 COMMAND ${IDGEN_LOC}
kamm@753 88 #COMMAND idgen
tomas@758 89 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 90 DEPENDS idgen
kamm@753 91 )
kamm@753 92 add_custom_command(
tomas@758 93 OUTPUT ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 94 # 2.4
kamm@753 95 COMMAND ${IMPCNVGEN_LOC}
kamm@753 96 #COMMAND impcnvgen
tomas@758 97 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 98 DEPENDS impcnvgen
kamm@753 99 )
kamm@753 100 set(LDC_GENERATED
tomas@758 101 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 102 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
tomas@758 103 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 104 )
kamm@753 105 # idgen and impcnvgen done
kamm@753 106
kamm@753 107 set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
kamm@753 108
tomas@758 109 include_directories(. ${DMDFE_PATH} ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${LLVM_INSTDIR}/include)
kamm@753 110
tomas@758 111 file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
kamm@753 112 file(GLOB GEN_SRC gen/*.cpp)
kamm@753 113 file(GLOB IR_SRC ir/*.cpp)
kamm@753 114 # exclude idgen and impcnvgen and generated sources, just in case
kamm@753 115 list(REMOVE_ITEM FE_SRC
tomas@758 116 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
tomas@758 117 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvgen.c
tomas@758 118 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
tomas@758 119 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 120 )
kamm@753 121 set(LDC_SOURCE_FILES
kamm@753 122 ${LDC_GENERATED}
kamm@753 123 ${FE_SRC}
kamm@753 124 ${GEN_SRC}
kamm@753 125 ${IR_SRC}
kamm@753 126 )
kamm@753 127 set_source_files_properties(
kamm@753 128 ${LDC_SOURCE_FILES} PROPERTIES
kamm@753 129 LANGUAGE CXX
kamm@750 130 )
kamm@749 131
kamm@753 132 add_definitions(
kamm@753 133 -DIN_LLVM
kamm@753 134 -D_DH
kamm@753 135 -DOPAQUE_VTBLS
kamm@753 136 -DX86_REVERSE_PARAMS
kamm@753 137 -DX86_PASS_IN_EAX
kamm@750 138 )
kamm@749 139
kamm@753 140 if(UNIX)
kamm@753 141 add_definitions(-DPOSIX)
elrood@829 142 set(CONF_INST_DIR bin)
kamm@753 143 endif(UNIX)
kamm@753 144
kamm@785 145 if(USE_BOEHM_GC)
kamm@785 146 add_definitions(-DUSE_BOEHM_GC)
kamm@785 147 endif(USE_BOEHM_GC)
kamm@785 148
tomas@821 149 if(GENERATE_OFFTI)
tomas@821 150 add_definitions(-DGENERATE_OFFTI)
tomas@821 151 endif(GENERATE_OFFTI)
tomas@821 152
kamm@753 153 if(CMAKE_MINOR_VERSION LESS 6)
kamm@785 154 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables")
kamm@785 155 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries")
kamm@753 156 add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
kamm@753 157 else(CMAKE_MINOR_VERSION LESS 6)
kamm@753 158 add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
kamm@753 159 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@753 160
tomas@758 161 add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})
kamm@753 162
kamm@853 163 # generate revision info
kamm@853 164 configure_file(revisions.pl.in revisions.pl)
kamm@853 165 add_custom_command(
kamm@853 166 OUTPUT revisions.h
kamm@853 167 COMMAND ${PERL_EXECUTABLE} ${PROJECT_BINARY_DIR}/revisions.pl
kamm@853 168 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@853 169 )
kamm@853 170 add_custom_target(gen_revs_h ALL DEPENDS revisions.h)
kamm@853 171 add_dependencies(${LDC_EXE} gen_revs_h)
kamm@853 172 #
kamm@853 173
elrood@828 174 set(LDC_EXE_NAME ${PROGRAM_PREFIX}${LDC_EXE}${PROGRAM_SUFFIX})
elrood@828 175
kamm@753 176 set_target_properties(
tomas@758 177 ${LDC_EXE} PROPERTIES
elrood@828 178 OUTPUT_NAME ${LDC_EXE_NAME}
kamm@753 179 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
tomas@758 180 COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated -Wno-write-strings"
kamm@750 181 )
kamm@750 182
kamm@753 183 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
tomas@758 184 target_link_libraries(${LDC_EXE} "${LLVM_LDFLAGS} ${LLVM_LIBS}")
kamm@753 185 if(WIN32)
tomas@758 186 target_link_libraries(${LDC_EXE} psapi)
elrood@828 187 set(CONF_INST_DIR bin)
kamm@753 188 endif(WIN32)
kamm@750 189
kamm@785 190 if(USE_BOEHM_GC)
kamm@785 191 target_link_libraries(${LDC_EXE} gc)
kamm@785 192 endif(USE_BOEHM_GC)
kamm@750 193
kamm@785 194 get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
kamm@785 195
kamm@753 196 # TODO: testrun
kamm@785 197
elrood@828 198 install(TARGETS ${LDC_EXE} DESTINATION bin)
elrood@829 199 install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.conf DESTINATION ${CONF_INST_DIR})
elrood@829 200 install(DIRECTORY ${PROJECT_BINARY_DIR}/lib DESTINATION . USE_SOURCE_PERMISSIONS)
elrood@828 201
elrood@829 202 add_subdirectory(runtime EXCLUDE_FROM_ALL)