annotate CMakeLists.txt @ 785:ac39e5449ca5

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