[llvm-commits] [PATCH] [dragonegg][CMake] Introduce CMakeFiles in dragonegg
NAKAMURA Takumi
geek4civic at gmail.com
Wed Jan 16 00:23:42 PST 2013
Hi baldrick, chandlerc,
FYI, it works for me.
* Test stuff is removed for now. (I have a patchset)
* Standalone (w/o llvm) is not supported.
CMake doesn't like dynamic controlled like $(shell) in GNU make. It was hard to emulate gmake's behavior.
- Triple -- Uses gcc's in config time.
- OS -- Uses "TargetInfo -o". include/dragonegg/${OS}/OS.h is copied to ${CMAKE_BUILD_DIR}/include/dragonegg/OS.h in compile time, before Backend.cpp is compiled.
- Arch -- is inducted from gcc's triple, not using TargetInfo -p, in config time.
[TODO]
- Add test stuff
- Add a few missing stuff, version info, etc.
- Add "standalone" configuration.
http://llvm-reviews.chandlerc.com/D300
Files:
dragonegg/CMakeLists.txt
dragonegg/utils/CMakeLists.txt
llvm/projects/CMakeLists.txt
Index: dragonegg/CMakeLists.txt
===================================================================
--- /dev/null
+++ dragonegg/CMakeLists.txt
@@ -0,0 +1,113 @@
+message(STATUS "Configuring DragonEgg...")
+
+add_definitions(-DIN_GCC)
+
+set(DRAGONEGG_TARGET_GCC ${CMAKE_CXX_COMPILER} CACHE PATH "plugin --print-file-name=plugin")
+message(STATUS "Target GCC is ${DRAGONEGG_TARGET_GCC}")
+
+function(get_gcc_prop prop OUTVAR)
+ execute_process(
+ COMMAND ${DRAGONEGG_TARGET_GCC} "-${prop}"
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE gcc_prop
+ )
+ set(${OUTVAR} ${gcc_prop} PARENT_SCOPE)
+endfunction()
+
+function(get_gcc_version)
+ get_gcc_prop(dumpversion VER)
+ set(VER__ "${VER}.0.0")
+
+ string(REGEX MATCHALL "[0-9]+" VERS ${VER__})
+
+ list(GET VERS 0 V0)
+ set(GCC_MAJOR ${V0} PARENT_SCOPE)
+ list(GET VERS 1 V1)
+ set(GCC_MINOR ${V1} PARENT_SCOPE)
+ list(GET VERS 2 V2)
+ set(GCC_MICRO ${V2} PARENT_SCOPE)
+
+ message(STATUS "The version is ${VER} (major=${V0}, minor=${V1}, micro=${V2})")
+endfunction()
+
+function(add_backend_header FLAG FILE)
+ get_target_property(TARGET_UTIL TargetInfo LOCATION)
+ set(DST ${CMAKE_BINARY_DIR}/include/dragonegg/${FILE})
+ add_custom_command(
+ OUTPUT ${DST}
+ COMMAND mkdir -p ${CMAKE_BINARY_DIR}/include/dragonegg
+ COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/include/`${TARGET_UTIL} ${FLAG}`/dragonegg/${FILE} ${DST}
+ DEPENDS
+ include/*/dragonegg/${FILE}
+ ${TARGET_UTIL}
+ COMMENT "Updating include/dragonegg/${FILE}"
+ )
+ set_source_files_properties(${DST} PROPERTIES GENERATED 1)
+ add_file_dependencies(src/Backend.cpp ${DST})
+endfunction()
+
+function(add_target_source FILE)
+ get_target_property(TARGET_UTIL TargetInfo LOCATION)
+ set(DST ${CMAKE_CURRENT_BINARY_DIR}/${FILE})
+ add_custom_command(
+ OUTPUT ${DST}
+ COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/src/`${TARGET_UTIL} -p`/${FILE} ${DST}
+ DEPENDS
+ src/*/${FILE}
+ ${TARGET_UTIL}
+ COMMENT "Updating ${FILE}"
+ )
+ set_source_files_properties(${DST} PROPERTIES GENERATED 1)
+endfunction()
+
+get_gcc_prop("-print-file-name=plugin" GCC_PLUGIN_DIR)
+message(STATUS "GCC's plugin directory is ${GCC_PLUGIN_DIR}")
+include_directories(SYSTEM "${GCC_PLUGIN_DIR}/include")
+
+get_gcc_prop(dumpmachine TARGET_TRIPLE)
+message(STATUS "Target triple is ${TARGET_TRIPLE}")
+add_definitions(-DTARGET_TRIPLE="${TARGET_TRIPLE}")
+
+get_gcc_version()
+add_definitions(
+ -DGCC_MAJOR=${GCC_MAJOR}
+ -DGCC_MINOR=${GCC_MINOR}
+ -DGCC_MICRO=${GCC_MICRO}
+ )
+
+# TODO: Put appropriate version string.
+add_definitions(-DLLVM_VERSION="")
+
+include_directories(include)
+
+add_subdirectory(utils)
+
+add_backend_header(-o OS.h)
+
+# add_backend_header(-p Target.h)
+string(REGEX MATCH "^(i[3-6]86|x86_64)-" TARGET_X86 ${TARGET_TRIPLE})
+string(REGEX MATCH "^(arm|thumb)" TARGET_ARM ${TARGET_TRIPLE})
+if (TARGET_ARM)
+ set(TARGET_ARCH "ARM")
+elseif (TARGET_X86)
+ set(TARGET_ARCH "X86")
+else ()
+ message(FATAL_ERROR "Target architecture is unknown")
+endif ()
+
+message(STATUS "Target architecture is ${TARGET_ARCH}")
+string(TOLOWER ${TARGET_ARCH} TARGET_arch_dir)
+include_directories("include/${TARGET_arch_dir}")
+
+file(GLOB SRC src/*.cpp)
+set(LLVM_LINK_COMPONENTS ipo scalaropts X86)
+
+add_llvm_loadable_module(
+ dragonegg
+ ${SRC}
+ src/${TARGET_arch_dir}/Target.cpp
+ )
+
+add_dependencies(dragonegg
+ intrinsics_gen
+ )
Index: dragonegg/utils/CMakeLists.txt
===================================================================
--- /dev/null
+++ dragonegg/utils/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_llvm_utility(TargetInfo
+ TargetInfo.cpp
+ )
+
+target_link_libraries(TargetInfo LLVMSupport)
Index: llvm/projects/CMakeLists.txt
===================================================================
--- llvm/projects/CMakeLists.txt
+++ llvm/projects/CMakeLists.txt
@@ -5,6 +5,7 @@
foreach(entry ${entries})
if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
if((NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt) AND
+ (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/dragonegg) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxx))
add_subdirectory(${entry})
endif()
@@ -17,3 +18,5 @@
${LLVM_BUILD_RUNTIME})
add_llvm_external_project(compiler-rt)
endif()
+
+add_llvm_external_project(dragonegg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D300.1.patch
Type: text/x-patch
Size: 4381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130116/fb0db32e/attachment.bin>
More information about the llvm-commits
mailing list