annotate CMakeLists.txt @ 1651:cb960b882ca3 tip

bindings were moved to dsource.org/projects/bindings/
author Moritz Warning <moritzwarning@web.de>
date Thu, 20 May 2010 20:05:03 +0200
parents 18bbb1436153
children
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
tomas@1103 12 include(FindPkgConfig)
tomas@1103 13 if(NOT PKG_CONFIG_FOUND)
tomas@1103 14 message(FATAL_ERROR "pkg-config not found")
tomas@1103 15 else(NOT PKG_CONFIG_FOUND)
tomas@1103 16 pkg_search_module(LIBCONFIGPP libconfig++)
tomas@1103 17 if(NOT LIBCONFIGPP_FOUND)
tomas@1139 18 set(LIBCONFIG_CXXFLAGS "" CACHE STRING "libconfig++ compiler flags")
tomas@1139 19 set(LIBCONFIG_LDFLAGS "" CACHE STRING "libconfig++ linker flags")
tomas@1139 20 else(NOT LIBCONFIGPP_FOUND)
tomas@1139 21 set(LIBCONFIG_CXXFLAGS ${LIBCONFIGPP_CFLAGS} CACHE STRING "libconfig++ compiler flags")
tomas@1139 22 set(LIBCONFIG_LDFLAGS ${LIBCONFIGPP_LDFLAGS} CACHE STRING "libconfig++ linker flags")
tomas@1103 23 endif(NOT LIBCONFIGPP_FOUND)
tomas@1103 24 endif(NOT PKG_CONFIG_FOUND)
tomas@1103 25
kamm@785 26 find_program(LLVM_CONFIG llvm-config ${LLVM_INSTDIR}/bin DOC "path to llvm-config tool")
kamm@785 27 # get llvm's install dir. a little hackish, we could do something like llvm-config --prefix, but this does as well
kamm@785 28 string(REPLACE "/bin/llvm-config" "" LLVM_DIR ${LLVM_CONFIG})
kamm@753 29
kamm@785 30 set(LLVM_INSTDIR ${LLVM_DIR} CACHE PATH "LLVM installation directory" FORCE)
kamm@785 31 if(NOT LLVM_INSTDIR)
kamm@785 32 message(FATAL_ERROR "llvm not found")
kamm@785 33 endif(NOT LLVM_INSTDIR)
kamm@753 34
kamm@753 35 execute_process(
kamm@753 36 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --host-target
kamm@753 37 OUTPUT_VARIABLE HOST_TARGET
kamm@753 38 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 39 )
kamm@753 40 execute_process(
tomas@1021 41 COMMAND /bin/sh ${PROJECT_SOURCE_DIR}/find-alt-triple.sh ${HOST_TARGET}
tomas@1021 42 OUTPUT_VARIABLE HOST_ALT_TARGET
tomas@1021 43 OUTPUT_STRIP_TRAILING_WHITESPACE
tomas@1021 44 )
tomas@1021 45 execute_process(
kamm@753 46 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags
kamm@753 47 OUTPUT_VARIABLE LLVM_CXXFLAGS
kamm@753 48 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 49 )
kamm@753 50 execute_process(
kamm@753 51 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --ldflags
kamm@753 52 OUTPUT_VARIABLE LLVM_LDFLAGS
kamm@753 53 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@753 54 )
kamm@1519 55 execute_process(
kamm@1519 56 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --includedir
kamm@1519 57 OUTPUT_VARIABLE LLVM_INCLUDEDIR
kamm@1519 58 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@1519 59 )
tomas@1105 60
tomas@758 61 set(D_VERSION 1 CACHE STRING "D language version")
elrood@828 62 set(PROGRAM_PREFIX CACHE STRING "prepended to ldc binary name")
elrood@828 63 set(PROGRAM_SUFFIX CACHE STRING "appended to ldc binary name")
kamm@785 64 option(USE_BOEHM_GC "use the Boehm garbage collector internally")
tomas@821 65 option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
tomas@1558 66 option(USE_METADATA "use metadata and related custom optimization passes")
kamm@785 67
tomas@758 68 if(D_VERSION EQUAL 1)
tomas@758 69 set(DMDFE_PATH dmd)
tomas@758 70 set(LDC_EXE ldc)
robert@1453 71 set(LDMD_EXE ldmd)
tomas@758 72 add_definitions(-DDMDV1)
tomas@758 73 elseif(D_VERSION EQUAL 2)
tomas@758 74 set(DMDFE_PATH dmd2)
tomas@758 75 set(LDC_EXE ldc2)
robert@1453 76 set(LDMD_EXE ldmd2)
tomas@758 77 add_definitions(-DDMDV2)
tomas@758 78 else(D_VERSION EQUAL 1)
tomas@758 79 message(FATAL_ERROR "unsupported D version")
tomas@758 80 endif(D_VERSION EQUAL 1)
tomas@758 81
kamm@753 82 file(MAKE_DIRECTORY
kamm@753 83 ${PROJECT_BINARY_DIR}/bin
tomas@758 84 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
fvbommel@1065 85 ${PROJECT_BINARY_DIR}/gen
kamm@750 86 )
kamm@749 87
kamm@753 88 # idgen and impcnvgen
kamm@753 89 set_source_files_properties(
tomas@758 90 ${DMDFE_PATH}/idgen.c
tomas@758 91 ${DMDFE_PATH}/impcnvgen.c
kamm@753 92 PROPERTIES LANGUAGE CXX
kamm@750 93 )
tomas@758 94 add_executable(idgen ${DMDFE_PATH}/idgen.c)
tomas@758 95 add_executable(impcnvgen ${DMDFE_PATH}/impcnvgen.c)
kamm@753 96 # cmake 2.4
kamm@753 97 set_target_properties(
kamm@753 98 idgen impcnvgen PROPERTIES
kamm@753 99 LINKER_LANGUAGE CXX
kamm@785 100 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@1051 101 COMPILE_FLAGS ${LLVM_CXXFLAGS}
kamm@753 102 )
kamm@753 103 get_target_property(IDGEN_LOC idgen LOCATION)
kamm@753 104 get_target_property(IMPCNVGEN_LOC impcnvgen LOCATION)
kamm@753 105 #
kamm@753 106 add_custom_command(
kamm@753 107 OUTPUT
tomas@758 108 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 109 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
kamm@753 110 # 2.4
kamm@753 111 COMMAND ${IDGEN_LOC}
kamm@753 112 #COMMAND idgen
tomas@758 113 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 114 DEPENDS idgen
kamm@753 115 )
kamm@753 116 add_custom_command(
tomas@758 117 OUTPUT ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 118 # 2.4
kamm@753 119 COMMAND ${IMPCNVGEN_LOC}
kamm@753 120 #COMMAND impcnvgen
tomas@758 121 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${DMDFE_PATH}
kamm@753 122 DEPENDS impcnvgen
kamm@753 123 )
kamm@753 124 set(LDC_GENERATED
tomas@758 125 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.c
tomas@758 126 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/id.h
tomas@758 127 ${PROJECT_BINARY_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 128 )
kamm@753 129 # idgen and impcnvgen done
kamm@753 130
kamm@753 131 set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
tomas@1021 132 set(DEFAULT_ALT_TARGET ${HOST_ALT_TARGET} CACHE STRING "default alt target")
kamm@753 133
kamm@1519 134 include_directories(. ${DMDFE_PATH} ${DMDFE_PATH}/root ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${PROJECT_BINARY_DIR} ${LLVM_INCLUDEDIR})
kamm@753 135
kamm@1518 136 set(EXTRA_LLVM_MODULES "" CACHE STRING "extra llvm components to link in (see llvm-config --components)")
kamm@1518 137 separate_arguments(EXTRA_LLVM_MODULES)
kamm@1518 138 execute_process(
kamm@1518 139 COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES}
kamm@1518 140 OUTPUT_VARIABLE LLVM_LIBS
kamm@1518 141 OUTPUT_STRIP_TRAILING_WHITESPACE
kamm@1518 142 )
kamm@1518 143
kamm@1518 144 # build a define that contains all LLVM targets required and is usable for
kamm@1518 145 # preprocessor code generation. start with the native target.
kamm@1520 146 find_path(LLVM_CONFIG_FILE_PATH config.h PATHS ${LLVM_INCLUDEDIR}/llvm/Config ${LLVM_INCLUDEDIR}/Config NO_DEFAULT_PATH)
kamm@1522 147 if(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
kamm@1522 148 message("Couldn't find your llvm Config.h file in ${LLVM_INCLUDEDIR}, no native target will be initialized.")
kamm@1522 149 else(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
kamm@1522 150 file(STRINGS ${LLVM_CONFIG_FILE_PATH}/config.h LLVM_NATIVE_ARCH REGEX "^#define LLVM_NATIVE_ARCH")
kamm@1522 151 if(LLVM_NATIVE_ARCH)
kamm@1522 152 string(REGEX REPLACE "^#define LLVM_NATIVE_ARCH (.*)Target$" "\\1" LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH})
benny@1547 153 message(STATUS "Found native target ${LLVM_NATIVE_ARCH}")
kamm@1522 154 set(LLVM_MODULES_DEFINE "LLVM_TARGET(${LLVM_NATIVE_ARCH})")
kamm@1522 155 else(LLVM_NATIVE_ARCH)
kamm@1522 156 message("Couldn't find the LLVM_NATIVE_ARCH define in ${LLVM_CONFIG_FILE_PATH}/config.h. Probably you have an older LLVM and can ignore this warning.")
kamm@1522 157 endif(LLVM_NATIVE_ARCH)
kamm@1522 158 endif(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
kamm@1518 159 # chain the extra target list to the define
kamm@1518 160 foreach(EXTRA_TARGET ${EXTRA_LLVM_MODULES})
kamm@1518 161 set(LLVM_MODULES_DEFINE "${LLVM_MODULES_DEFINE} LLVM_TARGET(${EXTRA_TARGET})")
kamm@1518 162 endforeach(EXTRA_TARGET)
kamm@1518 163 set_source_files_properties(
kamm@1518 164 ${PROJECT_SOURCE_DIR}/gen/main.cpp PROPERTIES
kamm@1518 165 COMPILE_DEFINITIONS LDC_TARGETS=${LLVM_MODULES_DEFINE}
kamm@1518 166 )
kamm@1518 167
kamm@1518 168
tomas@758 169 file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
tomas@1194 170 file(GLOB FE_SRC_ROOT ${DMDFE_PATH}/root/*.c)
fvbommel@1275 171 file(GLOB_RECURSE GEN_SRC gen/*.cpp)
kamm@753 172 file(GLOB IR_SRC ir/*.cpp)
kamm@753 173 # exclude idgen and impcnvgen and generated sources, just in case
kamm@753 174 list(REMOVE_ITEM FE_SRC
tomas@758 175 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
tomas@758 176 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvgen.c
tomas@758 177 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
tomas@758 178 ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
kamm@753 179 )
kamm@753 180 set(LDC_SOURCE_FILES
kamm@753 181 ${LDC_GENERATED}
kamm@753 182 ${FE_SRC}
tomas@1194 183 ${FE_SRC_ROOT}
kamm@753 184 ${GEN_SRC}
kamm@753 185 ${IR_SRC}
kamm@753 186 )
kamm@753 187 set_source_files_properties(
kamm@753 188 ${LDC_SOURCE_FILES} PROPERTIES
kamm@753 189 LANGUAGE CXX
kamm@750 190 )
kamm@749 191
kamm@753 192 add_definitions(
kamm@753 193 -DIN_LLVM
kamm@753 194 -D_DH
kamm@753 195 -DOPAQUE_VTBLS
kamm@750 196 )
kamm@749 197
kamm@753 198 if(UNIX)
kamm@753 199 add_definitions(-DPOSIX)
elrood@829 200 set(CONF_INST_DIR bin)
kamm@753 201 endif(UNIX)
kamm@753 202
kamm@785 203 if(USE_BOEHM_GC)
kamm@883 204 add_definitions(-DREDIRECT_MALLOC=GC_malloc -DIGNORE_FREE)
kamm@785 205 endif(USE_BOEHM_GC)
kamm@785 206
tomas@821 207 if(GENERATE_OFFTI)
tomas@821 208 add_definitions(-DGENERATE_OFFTI)
tomas@821 209 endif(GENERATE_OFFTI)
tomas@821 210
tomas@1558 211 if(USE_METADATA)
tomas@1558 212 add_definitions(-DUSE_METADATA)
tomas@1558 213 endif(USE_METADATA)
tomas@1558 214
kamm@753 215 if(CMAKE_MINOR_VERSION LESS 6)
kamm@785 216 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables")
kamm@785 217 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries")
kamm@753 218 add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
tomas@1021 219 add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE=\\"${DEFAULT_ALT_TARGET}\\")
tomas@1103 220 add_definitions(-DLDC_INSTALL_PREFIX=\\"${CMAKE_INSTALL_PREFIX}\\")
kamm@753 221 else(CMAKE_MINOR_VERSION LESS 6)
kamm@753 222 add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
tomas@1021 223 add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE="${DEFAULT_ALT_TARGET}")
tomas@1103 224 add_definitions(-DLDC_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
kamm@753 225 endif(CMAKE_MINOR_VERSION LESS 6)
kamm@753 226
tomas@758 227 add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})
kamm@753 228
kamm@853 229 # generate revision info
fvbommel@1064 230 configure_file(
fvbommel@1064 231 ${PROJECT_SOURCE_DIR}/revisions.pl.in
fvbommel@1064 232 ${PROJECT_BINARY_DIR}/revisions.pl
fvbommel@1064 233 @ONLY
fvbommel@1064 234 )
fvbommel@1074 235 add_custom_target(
fvbommel@1074 236 gen_revs_h
kamm@853 237 COMMAND ${PERL_EXECUTABLE} ${PROJECT_BINARY_DIR}/revisions.pl
fvbommel@1074 238 DEPENDS ${PROJECT_BINARY_DIR}/revisions.pl
fvbommel@1113 239 COMMENT "Generating revisions.h and llvm-version.h"
fvbommel@1064 240 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/gen
kamm@853 241 )
kamm@853 242 add_dependencies(${LDC_EXE} gen_revs_h)
kamm@853 243 #
kamm@853 244
elrood@828 245 set(LDC_EXE_NAME ${PROGRAM_PREFIX}${LDC_EXE}${PROGRAM_SUFFIX})
elrood@828 246
kamm@753 247 set_target_properties(
tomas@758 248 ${LDC_EXE} PROPERTIES
elrood@828 249 OUTPUT_NAME ${LDC_EXE_NAME}
kamm@753 250 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
tomas@1103 251 COMPILE_FLAGS "${LLVM_CXXFLAGS} ${LIBCONFIG_CXXFLAGS} -Wno-deprecated -Wno-write-strings"
kamm@750 252 )
kamm@750 253
kamm@753 254 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
fvbommel@1107 255 target_link_libraries(${LDC_EXE} "${LLVM_LDFLAGS} ${LLVM_LIBS}" ${LIBCONFIG_LDFLAGS})
kamm@753 256 if(WIN32)
wilsonk@1256 257 target_link_libraries(${LDC_EXE} config++ imagehlp psapi)
elrood@828 258 set(CONF_INST_DIR bin)
kamm@753 259 endif(WIN32)
kamm@750 260
kamm@785 261 if(USE_BOEHM_GC)
kamm@883 262 target_link_libraries(${LDC_EXE} ${PROJECT_SOURCE_DIR}/libgc.a)
kamm@785 263 endif(USE_BOEHM_GC)
kamm@750 264
kamm@785 265 get_target_property(LDC_LOC ${LDC_EXE} LOCATION)
kamm@785 266
kamm@753 267 # TODO: testrun
kamm@785 268
elrood@828 269 install(TARGETS ${LDC_EXE} DESTINATION bin)
robert@1453 270 install(FILES ${PROJECT_SOURCE_DIR}/bin/${LDMD_EXE} DESTINATION bin)
elrood@829 271 install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.conf DESTINATION ${CONF_INST_DIR})
kamm@1129 272 install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.rebuild.conf DESTINATION ${CONF_INST_DIR})
elrood@829 273 install(DIRECTORY ${PROJECT_BINARY_DIR}/lib DESTINATION . USE_SOURCE_PERMISSIONS)
elrood@828 274
elrood@829 275 add_subdirectory(runtime EXCLUDE_FROM_ALL)