summaryrefslogtreecommitdiffstats
path: root/cmake/build.cmake
blob: 3043014ccd2fa1bf145418322f91942738a460a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
cmake_minimum_required(VERSION 2.6)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")

find_package(BAZAAR QUIET)

set(PCILIB_BUILD_DATE "")
set(PCILIB_LAST_MODIFICATION "")
set(PCILIB_REVISION "0")
set(PCILIB_REVISION_BRANCH "")
set(PCILIB_REVISION_AUTHOR "")
set(PCILIB_REVISION_MODIFICATIONS "")

execute_process(
    COMMAND date "+%Y/%m/%d %H:%M:%S"
    RESULT_VARIABLE _retcode
    OUTPUT_VARIABLE _output
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (${_retcode} EQUAL 0)
    set(PCILIB_BUILD_DATE ${_output})
endif (${_retcode} EQUAL 0)

execute_process(
    COMMAND find ${CMAKE_SOURCE_DIR} -type f -name *.[ch] -printf "%TY/%Tm/%Td %TH:%TM:%TS  %p\n"
    COMMAND sort -n
    COMMAND grep -E -v "build.h|config.h|CMakeFiles|./apps"
    COMMAND tail -n 1
    COMMAND cut -d " " -f 1-2
    COMMAND cut -d "." -f 1
    RESULT_VARIABLE _retcode
    OUTPUT_VARIABLE _output
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (${_retcode} EQUAL 0)
    set(PCILIB_LAST_MODIFICATION ${_output})
endif (${_retcode} EQUAL 0)

if (BAZAAR_FOUND)
    execute_process(
	COMMAND ${BAZAAR_EXECUTABLE} revno --tree ${CMAKE_SOURCE_DIR}
	RESULT_VARIABLE _retcode
	OUTPUT_VARIABLE _output
	OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    if (${_retcode} EQUAL 0)
	set(PCILIB_REVISION ${_output})

	execute_process(
	    COMMAND ${BAZAAR_EXECUTABLE} log -r${PCILIB_REVISION} ${CMAKE_SOURCE_DIR}
	    RESULT_VARIABLE _retcode
	    OUTPUT_VARIABLE _output
	    OUTPUT_STRIP_TRAILING_WHITESPACE
	)

	if (${_retcode} EQUAL 0)
	    string(REGEX REPLACE "^(.*\n)?committer: ([^\n]+).*"
                    "\\2" PCILIB_REVISION_AUTHOR "${_output}" )
	    string(REGEX REPLACE "^(.*\n)?branch nick: ([^\n]+).*"
                    "\\2" PCILIB_REVISION_BRANCH "${_output}" )
	endif (${_retcode} EQUAL 0)
    endif (${_retcode} EQUAL 0)

    execute_process(
	COMMAND ${BAZAAR_EXECUTABLE} status -SV
	COMMAND cut -c 5-
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	RESULT_VARIABLE _retcode
	OUTPUT_VARIABLE _output
	OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    if (${_retcode} EQUAL 0)
	string(REGEX REPLACE "\n+" ";" PCILIB_REVISION_MODIFICATIONS ${_output})
#	set(PCILIB_REVISION_MODIFICATIONS ${_output})
    endif (${_retcode} EQUAL 0)
endif(BAZAAR_FOUND)

configure_file(${CMAKE_SOURCE_DIR}/pcilib/build.h.in ${CMAKE_BINARY_DIR}/pcilib/build.h)