Paste: clay compiler version info and some cmake improvements

Author: elrood
Mode: patch
Date: Fri, 30 Jul 2010 18:17:21
Plain Text |
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,10 @@
 project(clay)
 cmake_minimum_required(VERSION 2.6)
 
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+find_package(Subversion)
+find_package(Mercurial)
+
 include(FindPythonInterp)
 
 if(UNIX)
@@ -33,10 +37,15 @@
         OUTPUT_VARIABLE LLVM_LIBS
         OUTPUT_STRIP_TRAILING_WHITESPACE
     )
+    execute_process(
+        COMMAND ${LLVM_CONFIG} --src-root
+        OUTPUT_VARIABLE LLVM_DIR
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
 elseif(MSVC)
-    set(LLVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)
-    set(LLVM_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-build)
-    set(CLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/tools/clang)
+    set(LLVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm CACHE PATH "llvm source path")
+    set(LLVM_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-build CACHE PATH "llvm build path")
+    set(CLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/tools/clang CACHE PATH "clang source path")
 
     if(IS_DIRECTORY ${LLVM_BUILD_DIR})
         link_directories(${LLVM_BUILD_DIR}/lib/Release)
@@ -77,7 +86,11 @@
 
 set(CMAKE_OSX_ARCHITECTURES x86_64)
 
-install(DIRECTORY lib-clay DESTINATION lib)
+if(UNIX)
+    install(DIRECTORY lib-clay DESTINATION lib)
+else(UNIX)
+    install(DIRECTORY lib-clay DESTINATION .)
+endif(UNIX)
 
 add_subdirectory(compiler)
 add_subdirectory(misc)
diff --git a/cmake/FindMercurial.cmake b/cmake/FindMercurial.cmake
new file mode 100644
--- /dev/null
+++ b/cmake/FindMercurial.cmake
@@ -0,0 +1,36 @@
+SET(Mercurial_FOUND FALSE)
+
+FIND_PROGRAM(Mercurial_EXECUTABLE hg DOC "Mercurial command line client")
+MARK_AS_ADVANCED(Mercurial_EXECUTABLE)
+
+IF(Mercurial_EXECUTABLE)
+    SET(Mercurial_FOUND TRUE)
+
+    EXECUTE_PROCESS(COMMAND ${Mercurial_EXECUTABLE} version
+        OUTPUT_VARIABLE Mercurial_VERSION
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+    STRING(REGEX REPLACE ".*version ([.0-9]+).*"
+        "\\1" Mercurial_VERSION "${Mercurial_VERSION}")
+
+    MACRO(Mercurial_WC_INFO dir prefix)
+        EXECUTE_PROCESS(COMMAND ${Mercurial_EXECUTABLE} log -l1 ${dir}
+            OUTPUT_VARIABLE ${prefix}_WC_INFO
+            ERROR_VARIABLE Mercurial_info_error
+            RESULT_VARIABLE Mercurial_info_result
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+        IF(Mercurial_info_result EQUAL 0)
+            STRING(REGEX REPLACE "^(.*\n)?changeset: *([^\n]+).*"
+                "\\2" ${prefix}_WC_CHANGESET "${${prefix}_WC_INFO}")
+            STRING(REGEX REPLACE "^(.*\n)?tag: *([^\n]+).*"
+                "\\2" ${prefix}_WC_TAG "${${prefix}_WC_INFO}")
+            STRING(REGEX REPLACE "^(.*\n)?user: *([^\n]+).*"
+                "\\2" ${prefix}_WC_USER "${${prefix}_WC_INFO}")
+            STRING(REGEX REPLACE "^(.*\n)?date: *([^\n]+).*"
+                "\\2" ${prefix}_WC_DATE "${${prefix}_WC_INFO}")
+        ELSE()
+            MESSAGE(SEND_ERROR "\"${Mercurial_EXECUTABLE} log -l1 ${dir}\" failed with output:\n${Mercurial_info_error}")
+        ENDIF()
+    ENDMACRO()
+ENDIF()
diff --git a/compiler/src/CMakeLists.txt b/compiler/src/CMakeLists.txt
--- a/compiler/src/CMakeLists.txt
+++ b/compiler/src/CMakeLists.txt
@@ -21,14 +21,28 @@
     types.cpp
 )
 
+# version info is only updated when cmake is run
+if(Subversion_FOUND AND EXISTS "${LLVM_DIR}/.svn")
+    Subversion_WC_INFO(${LLVM_DIR} SVN)
+    set_property(SOURCE main.cpp APPEND PROPERTY
+        COMPILE_DEFINITIONS "SVN_REVISION=\"${SVN_WC_REVISION}\"")
+endif()
+
+if(Mercurial_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.hg")
+    Mercurial_WC_INFO(${PROJECT_SOURCE_DIR} HG)
+    set_property(SOURCE main.cpp APPEND PROPERTY
+        COMPILE_DEFINITIONS "HG_CHANGESET=\"${HG_WC_CHANGESET}\";HG_DATE=\"${HG_WC_DATE}\"")
+endif()
+
 add_executable(clay ${SOURCES})
 
 set_target_properties(clay PROPERTIES COMPILE_FLAGS "${LLVM_CXXFLAGS}")
 
 if (UNIX)
     set_target_properties(clay PROPERTIES LINK_FLAGS ${LLVM_LDFLAGS})
+    install(TARGETS clay RUNTIME DESTINATION bin)
+else(UNIX)
+    install(TARGETS clay RUNTIME DESTINATION .)
 endif(UNIX)
 
 target_link_libraries(clay ${LLVM_LIBS})
-
-install(TARGETS clay RUNTIME DESTINATION bin)
diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp
--- a/compiler/src/main.cpp
+++ b/compiler/src/main.cpp
@@ -248,6 +248,7 @@
 #endif
     cerr << "  -L<dir>           - add <dir> to library search path\n";
     cerr << "  -l<lib>           - link with library <lib>\n";
+    cerr << "  -v                - display version info\n";
 }
 
 int main(int argc, char **argv) {
@@ -391,6 +392,17 @@
             }
             clayFile = argv[i];
         }
+        else if (strstr(argv[i], "-v") == argv[i]) {
+            cerr << "clay compiler ("
+#ifdef HG_CHANGESET
+                << "hg r" << HG_CHANGESET << ", "
+#endif
+#ifdef SVN_REVISION
+                << "llvm r" << SVN_REVISION << ", "
+#endif
+                << __DATE__ << ")\n";
+                return 0;
+        }
         else {
             cerr << "error: unrecognized option " << argv[i] << '\n';
             return -1;
diff --git a/lib-clay/random/platform/platform.win32.clay b/lib-clay/random/platform/platform.windows.clay
rename from lib-clay/random/platform/platform.win32.clay
rename to lib-clay/random/platform/platform.windows.clay
diff --git a/misc/bindgen/src/CMakeLists.txt b/misc/bindgen/src/CMakeLists.txt
--- a/misc/bindgen/src/CMakeLists.txt
+++ b/misc/bindgen/src/CMakeLists.txt
@@ -10,10 +10,12 @@
 
 if (UNIX)
     set_target_properties(clay-bindgen PROPERTIES LINK_FLAGS ${LLVM_LDFLAGS})
+    install(TARGETS clay-bindgen RUNTIME DESTINATION bin)
+else(UNIX)
+    install(TARGETS clay-bindgen RUNTIME DESTINATION .)
 endif (UNIX)
 
 target_link_libraries(clay-bindgen 
     "clangFrontend" "clangSema" "clangChecker" "clangAnalysis" 
     "clangAST" "clangParse" "clangLex" "clangBasic" ${LLVM_LIBS})
 
-install(TARGETS clay-bindgen RUNTIME DESTINATION bin) 

New Annotation

Summary:
Author:
Mode:
Body: