annotate CMakeLists.txt @ 821:8f0b24bc55f0

Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 02 Dec 2008 01:44:17 +0100
parents ac39e5449ca5
children 03b0c817a1a3
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")
kamm@785 43 option(USE_BOEHM_GC "use the Boehm garbage collector internally")
tomas@821 44 option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
kamm@785 45
tomas@758 46 if(D_VERSION EQUAL 1)
tomas@758 47 set(DMDFE_PATH dmd)
tomas@758 48 set(LDC_EXE ldc)
tomas@758 49 add_definitions(-DDMDV1)
tomas@758 50 elseif(D_VERSION EQUAL 2)
tomas@758 51 set(DMDFE_PATH dmd2)
tomas@758 52 set(LDC_EXE ldc2)
tomas@758 53 add_definitions(-DDMDV2)
tomas@758 54 else(D_VERSION EQUAL 1)
tomas@758 55 message(FATAL_ERROR "unsupported D version")
tomas@758 56 endif(D_VERSION EQUAL 1)
tomas@758 57
kamm@753 58 file(MAKE_DIRECTORY
kamm@753 59 ${PROJECT_BINARY_DIR}/bin
tomas@758 60 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@750 61 )
kamm@749 62
kamm@753 63 # idgen and impcnvgen
kamm@753 64 set_source_files_properties(
tomas@758 65 ${DMDFE_PATH}/idgen.c
tomas@758 66 ${DMDFE_PATH}/impcnvgen.c
kamm@753 67 PROPERTIES LANGUAGE CXX
kamm@750 68 )
tomas@758 69 add_executable(idgen ${DMDFE_PATH}/idgen.c)
tomas@758 70 add_executable(impcnvgen ${DMDFE_PATH}/impcnvgen.c)
kamm@753 71 # cmake 2.4
kamm@753 72 set_target_properties(
kamm@753 73 idgen impcnvgen PROPERTIES
kamm@753 74 LINKER_LANGUAGE CXX
kamm@785 75 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 76 )
kamm@753 77 get_target_property(IDGEN_LOC idgen LOCATION)
kamm@753 78 get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
kamm@753 79 #
kamm@753 80 add_custom_command(
kamm@753 81 OUTPUT
tomas@758 82 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 83 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
kamm@753 84 # 2.4
kamm@753 85 COMMAND ${IDGEN_LOC}
kamm@753 86 #COMMAND idgen
tomas@758 87 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 88 DEPENDS idgen
kamm@753 89 )
kamm@753 90 add_custom_command(
tomas@758 91 OUTPUT ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 92 # 2.4
kamm@753 93 COMMAND ${IMPCNVGEN_LOC}
kamm@753 94 #COMMAND impcnvgen
tomas@758 95 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 96 DEPENDS impcnvgen
kamm@753 97 )
kamm@753 98 set(LDC_GENERATED
tomas@758 99 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 100 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
tomas@758 101 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 102 )
kamm@753 103 # idgen and impcnvgen done
kamm@753 104
kamm@753 105 set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
kamm@753 106
tomas@758 107 include_directories(. ${DMDFE_PATH} ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${LLVM_INSTDIR}/include)
kamm@753 108
tomas@758 109 file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
kamm@753 110 file(GLOB GEN_SRC gen/*.cpp)
kamm@753 111 file(GLOB IR_SRC ir/*.cpp)
kamm@753 112 # exclude idgen and impcnvgen and generated sources, just in case
kamm@753 113 list(REMOVE_ITEM FE_SRC
tomas@758 114 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
tomas@758 115 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvgen.c
tomas@758 116 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
tomas@758 117 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 118 )
kamm@753 119 set(LDC_SOURCE_FILES
kamm@753 120 ${LDC_GENERATED}
kamm@753 121 ${FE_SRC}
kamm@753 122 ${GEN_SRC}
kamm@753 123 ${IR_SRC}
kamm@753 124 )
kamm@753 125 set_source_files_properties(
kamm@753 126 ${LDC_SOURCE_FILES} PROPERTIES
kamm@753 127 LANGUAGE CXX
kamm@750 128 )
kamm@749 129
kamm@753 130 add_definitions(
kamm@753 131 -DIN_LLVM
kamm@753 132 -D_DH
kamm@753 133 -DOPAQUE_VTBLS
kamm@753 134 -DX86_REVERSE_PARAMS
kamm@753 135 -DX86_PASS_IN_EAX
kamm@750 136 )
kamm@749 137
kamm@753 138 if(UNIX)
kamm@753 139 add_definitions(-DPOSIX)
kamm@753 140 endif(UNIX)
kamm@753 141
kamm@785 142 if(USE_BOEHM_GC)
kamm@785 143 add_definitions(-DUSE_BOEHM_GC)
kamm@785 144 endif(USE_BOEHM_GC)
kamm@785 145
tomas@821 146 if(GENERATE_OFFTI)
tomas@821 147 add_definitions(-DGENERATE_OFFTI)
tomas@821 148 endif(GENERATE_OFFTI)
tomas@821 149
kamm@753 150 if(CMAKE_MINOR_VERSION LESS 6)
kamm@785 151 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables")
kamm@785 152 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries")
kamm@753 153 add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
kamm@753 154 else(CMAKE_MINOR_VERSION LESS 6)
kamm@753 155 add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
kamm@753 156 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@753 157
tomas@758 158 add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})
kamm@753 159
kamm@753 160 set_target_properties(
tomas@758 161 ${LDC_EXE} PROPERTIES
kamm@753 162 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
tomas@758 163 COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated -Wno-write-strings"
kamm@750 164 )
kamm@750 165
kamm@753 166 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
tomas@758 167 target_link_libraries(${LDC_EXE} "${LLVM_LDFLAGS} ${LLVM_LIBS}")
kamm@753 168 if(WIN32)
tomas@758 169 target_link_libraries(${LDC_EXE} psapi)
kamm@753 170 endif(WIN32)
kamm@750 171
kamm@785 172 if(USE_BOEHM_GC)
kamm@785 173 target_link_libraries(${LDC_EXE} gc)
kamm@785 174 endif(USE_BOEHM_GC)
kamm@750 175
kamm@785 176 get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
kamm@785 177
kamm@753 178 # TODO: install target
kamm@753 179 # TODO: testrun
kamm@785 180
kamm@785 181 add_subdirectory(runtime EXCLUDE_FROM_ALL)