From ca0a9b8036469629ef9410676663122e699214d3 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 22 Oct 2012 14:56:25 +0200 Subject: [PATCH] Fixed: revision.h error when hg executable not found --- code/CMakeModules/GetRevision.cmake | 31 ++++++++++++--------- code/CMakeModules/nel.cmake | 43 +++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/code/CMakeModules/GetRevision.cmake b/code/CMakeModules/GetRevision.cmake index 52f443d5f..18e997af2 100644 --- a/code/CMakeModules/GetRevision.cmake +++ b/code/CMakeModules/GetRevision.cmake @@ -3,20 +3,24 @@ 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) -# Replace spaces by semi-columns -IF(CMAKE_MODULE_PATH) - STRING(REPLACE " " ";" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) -ENDIF(CMAKE_MODULE_PATH) +IF(SOURCE_DIR) + # Replace spaces by semi-columns + IF(CMAKE_MODULE_PATH) + STRING(REPLACE " " ";" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) + ENDIF(CMAKE_MODULE_PATH) -SET(CMAKE_MODULE_PATH ${SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH}) + SET(CMAKE_MODULE_PATH ${SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH}) -IF(NOT ROOT_DIR AND SOURCE_DIR) - SET(ROOT_DIR ${SOURCE_DIR}) -ENDIF(NOT ROOT_DIR AND SOURCE_DIR) + IF(NOT ROOT_DIR AND SOURCE_DIR) + SET(ROOT_DIR ${SOURCE_DIR}) + 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) + 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) diff --git a/code/CMakeModules/nel.cmake b/code/CMakeModules/nel.cmake index b8f74e4de..e1b204690 100644 --- a/code/CMakeModules/nel.cmake +++ b/code/CMakeModules/nel.cmake @@ -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