annotate CMakeLists.txt @ 828:03b0c817a1a3

added install target and possibility to pre- and suffix ldc's executable name to cmake scripts
author elrood
date Thu, 04 Dec 2008 22:09:24 +0100
parents 8f0b24bc55f0
children 0a31c60a6bc1
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@828 142 set(CONF_INST_DIR etc)
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
elrood@828 163 set(LDC_EXE_NAME ${PROGRAM_PREFIX}${LDC_EXE}${PROGRAM_SUFFIX})
elrood@828 164
kamm@753 165 set_target_properties(
tomas@758 166 ${LDC_EXE} PROPERTIES
elrood@828 167 OUTPUT_NAME ${LDC_EXE_NAME}
kamm@753 168 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
tomas@758 169 COMPILE_FLAGS "${LLVM_CXXFLAGS} -Wno-deprecated -Wno-write-strings"
kamm@750 170 )
kamm@750 171
kamm@753 172 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
tomas@758 173 target_link_libraries(${LDC_EXE} "${LLVM_LDFLAGS} ${LLVM_LIBS}")
kamm@753 174 if(WIN32)
tomas@758 175 target_link_libraries(${LDC_EXE} psapi)
elrood@828 176 set(CONF_INST_DIR bin)
kamm@753 177 endif(WIN32)
kamm@750 178
kamm@785 179 if(USE_BOEHM_GC)
kamm@785 180 target_link_libraries(${LDC_EXE} gc)
kamm@785 181 endif(USE_BOEHM_GC)
kamm@750 182
kamm@785 183 get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
kamm@785 184
kamm@753 185 # TODO: testrun
kamm@785 186
elrood@828 187 install(TARGETS ${LDC_EXE} DESTINATION bin)
elrood@828 188
elrood@828 189 install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE_NAME}.conf DESTINATION ${CONF_INST_DIR})
elrood@828 190
elrood@828 191 add_subdirectory(runtime)