Fixed: revision.h error when hg executable not found
This commit is contained in:
parent
bced63993b
commit
2e6361ebfe
2 changed files with 53 additions and 21 deletions
|
@ -3,6 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)
|
|||
# ROOT_DIR should be set to root of the repository (where to find the .svn or .hg directory)
|
||||
# SOURCE_DIR should be set to root of your code (where to find CMakeLists.txt)
|
||||
|
||||
IF(SOURCE_DIR)
|
||||
# Replace spaces by semi-columns
|
||||
IF(CMAKE_MODULE_PATH)
|
||||
STRING(REPLACE " " ";" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
|
||||
|
@ -17,6 +18,9 @@ ENDIF(NOT ROOT_DIR AND SOURCE_DIR)
|
|||
IF(NOT SOURCE_DIR AND ROOT_DIR)
|
||||
SET(SOURCE_DIR ${ROOT_DIR})
|
||||
ENDIF(NOT SOURCE_DIR AND ROOT_DIR)
|
||||
ELSE(SOURCE_DIR)
|
||||
SET(ROOT_DIR ${CMAKE_SOURCE_DIR})
|
||||
ENDIF(SOURCE_DIR)
|
||||
|
||||
MACRO(NOW RESULT)
|
||||
IF (WIN32)
|
||||
|
@ -53,10 +57,11 @@ IF(EXISTS "${ROOT_DIR}/.hg/")
|
|||
ENDIF(MERCURIAL_FOUND)
|
||||
ENDIF(EXISTS "${ROOT_DIR}/.hg/")
|
||||
|
||||
IF(DEFINED REVISION)
|
||||
IF(SOURCE_DIR AND DEFINED REVISION)
|
||||
IF(EXISTS ${SOURCE_DIR}/revision.h.in)
|
||||
MESSAGE(STATUS "Revision: ${REVISION}")
|
||||
NOW(BUILD_DATE)
|
||||
CONFIGURE_FILE(${SOURCE_DIR}/revision.h.in revision.h.txt)
|
||||
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy revision.h.txt revision.h) # copy_if_different
|
||||
ENDIF(EXISTS ${SOURCE_DIR}/revision.h.in)
|
||||
ENDIF(DEFINED REVISION)
|
||||
ENDIF(SOURCE_DIR AND DEFINED REVISION)
|
||||
|
|
|
@ -22,22 +22,39 @@ ENDMACRO(NL_GEN_PC)
|
|||
###
|
||||
MACRO(NL_GEN_REVISION_H)
|
||||
IF(EXISTS ${CMAKE_SOURCE_DIR}/revision.h.in)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
|
||||
ADD_DEFINITIONS(-DHAVE_REVISION_H)
|
||||
SET(HAVE_REVISION_H ON)
|
||||
SET(TOOL_FOUND OFF)
|
||||
|
||||
IF(EXISTS "${CMAKE_SOURCE_DIR}/../.svn/")
|
||||
FIND_PACKAGE(Subversion)
|
||||
|
||||
IF(SUBVERSION_FOUND)
|
||||
SET(TOOL_FOUND ON)
|
||||
ENDIF(SUBVERSION_FOUND)
|
||||
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/../.svn/")
|
||||
|
||||
IF(EXISTS "${CMAKE_SOURCE_DIR}/../.hg/")
|
||||
FIND_PACKAGE(Mercurial)
|
||||
|
||||
IF(MERCURIAL_FOUND)
|
||||
SET(TOOL_FOUND ON)
|
||||
ENDIF(MERCURIAL_FOUND)
|
||||
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/../.hg/")
|
||||
|
||||
# if already generated
|
||||
IF(EXISTS ${CMAKE_SOURCE_DIR}/revision.h)
|
||||
# copy it
|
||||
MESSAGE(STATUS "Copying provided revision.h...")
|
||||
FILE(COPY ${CMAKE_SOURCE_DIR}/revision.h DESTINATION ${CMAKE_BINARY_DIR})
|
||||
ELSE(EXISTS ${CMAKE_SOURCE_DIR}/revision.h)
|
||||
SET(HAVE_REVISION_H ON)
|
||||
ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/revision.h)
|
||||
|
||||
IF(TOOL_FOUND)
|
||||
# a custom target that is always built
|
||||
ADD_CUSTOM_TARGET(revision ALL
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/revision.h)
|
||||
ADD_CUSTOM_TARGET(revision ALL)
|
||||
|
||||
# creates revision.h using cmake script
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_BINARY_DIR}/revision.h
|
||||
ADD_CUSTOM_COMMAND(TARGET revision
|
||||
PRE_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-DROOT_DIR=${CMAKE_SOURCE_DIR}/..
|
||||
|
@ -47,7 +64,13 @@ MACRO(NL_GEN_REVISION_H)
|
|||
SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/revision.h
|
||||
PROPERTIES GENERATED TRUE
|
||||
HEADER_FILE_ONLY TRUE)
|
||||
ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/revision.h)
|
||||
SET(HAVE_REVISION_H ON)
|
||||
ENDIF(TOOL_FOUND)
|
||||
|
||||
IF(HAVE_REVISION_H)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
|
||||
ADD_DEFINITIONS(-DHAVE_REVISION_H)
|
||||
ENDIF(HAVE_REVISION_H)
|
||||
ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/revision.h.in)
|
||||
ENDMACRO(NL_GEN_REVISION_H)
|
||||
|
||||
|
@ -922,6 +945,10 @@ MACRO(SETUP_EXTERNAL)
|
|||
IF(WIN32)
|
||||
FIND_PACKAGE(External REQUIRED)
|
||||
|
||||
IF(NOT VC_DIR)
|
||||
SET(VC_DIR $ENV{VC_DIR})
|
||||
ENDIF(NOT VC_DIR)
|
||||
|
||||
IF(MSVC10)
|
||||
IF(NOT MSVC10_REDIST_DIR)
|
||||
# If you have VC++ 2010 Express, put x64/Microsoft.VC100.CRT/*.dll in ${EXTERNAL_PATH}/redist
|
||||
|
|
Loading…
Reference in a new issue