Commit decfc5aa by Sebastian Eichelbaum

[CHANGE #199] the version header is not setup correctly and gets searched when…

[CHANGE #199] the version header is not setup correctly and gets searched when using these scripts externally.
parent 2209824d
......@@ -61,6 +61,21 @@ ENDIF()
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# 1: some needed path setup for version headers. This is needed for searching OW.
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# where to put the header
SET( OW_VERSION_HEADER_DIRECTORY_RELATIVE "versionHeader" )
# this is the name of the INTERNAL OpenWalnut version header. It is needed for searching OW. Do not mix this up with the version header filename
# you use for the toolbox (external module building).
SET( OW_INTERNAL_VERSION_HEADER_FILENAME "core/WVersion.h" )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# 2: start build system and either search OW or use it internally.
# ---------------------------------------------------------------------------------------------------------------------------------------------------
MESSAGE( STATUS "----------------------------------------------------------------------" )
MESSAGE( STATUS "Welcome! This is OpenWalnut Build System." )
......@@ -69,7 +84,7 @@ IF( NOT ${OW_EXTERNAL_MODULE} )
# to allow non-core code to access core and ext absolutely
INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR} )
ELSE()
MESSAGE( STATUS "NOTE: configuring for external use." )
MESSAGE( STATUS "Searching OpenWalnut ..." )
FIND_PATH( OPENWALNUT_INCLUDE_DIR core/kernel/WKernel.h ${OPENWALNUT_INCLUDEDIR} $ENV{OPENWALNUT_INCLUDEDIR} /usr/include/openwalnut /usr/local/include/openwalnut )
FIND_LIBRARY( OPENWALNUT_LIBRARIES NAMES ${OW_LIB_OPENWALNUT} lib${OW_LIB_OPENWALNUT} HINTS
......@@ -83,10 +98,22 @@ ELSE()
/usr/local/OpenWalnut
$ENV{PROGRAMFILES}/OpenWalnut )
# find the version header. There are two possibilities here:
# 1: we find it inside the include dir -- this is the case if we found an installed OW
# 2: we find it inside the lib/../versionHeader dir -- this is the case if we found a local build of OW
# NOTE: this relies on OPENWALNUT_INCLUDE_DIR which is filled above. If it is empty, no OW was found so it is not bad to not find the version
# header.
FIND_PATH( OPENWALNUT_VERSIONHEADER_DIR ${OW_INTERNAL_VERSION_HEADER_FILENAME}
# 1: we search in the hopefully found include dir:
${OPENWALNUT_INCLUDE_DIR}
# 2: we search in the build dir
"$ENV{OPENWALNUT_LIBDIR}/../${OW_VERSION_HEADER_DIRECTORY_RELATIVE}"
)
SET( OPENWALNUT_FOUND FALSE )
# do not confuse the user with this
MARK_AS_ADVANCED( FORCE OPENWALNUT_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OPENWALNUT_VERSIONHEADER_DIR )
MARK_AS_ADVANCED( FORCE OPENWALNUT_LIBRARIES )
MARK_AS_ADVANCED( FORCE OPENWALNUT_FOUND )
......@@ -94,50 +121,54 @@ ELSE()
IF( OPENWALNUT_INCLUDE_DIR )
MESSAGE( STATUS "Found OpenWalnut include files in ${OPENWALNUT_INCLUDE_DIR}." )
ENDIF()
IF( OPENWALNUT_VERSIONHEADER_DIR )
MESSAGE( STATUS "Found OpenWalnut version header in ${OPENWALNUT_VERSIONHEADER_DIR}." )
ENDIF()
IF( OPENWALNUT_LIBRARIES )
MESSAGE( STATUS "Found OpenWalnut libs in ${OPENWALNUT_LIBRARIES}." )
ENDIF()
# really found?
IF( OPENWALNUT_INCLUDE_DIR AND OPENWALNUT_LIBRARIES )
IF( OPENWALNUT_INCLUDE_DIR AND OPENWALNUT_LIBRARIES AND OPENWALNUT_VERSIONHEADER_DIR )
SET( OPENWALNUT_FOUND TRUE )
MESSAGE( STATUS "Found OpenWalnut." )
ELSE()
MESSAGE( FATAL_ERROR "Could not find OpenWalnut." )
MESSAGE( FATAL_ERROR "Could not find OpenWalnut. You can use the environment variables OPENWALNUT_INCLUDEDIR and OPENWALNUT_LIBDIR to point to your OpenWalnut installation." )
ENDIF()
# include
INCLUDE_DIRECTORIES( ${OPENWALNUT_INCLUDE_DIR} )
INCLUDE_DIRECTORIES( ${OPENWALNUT_VERSIONHEADER_DIR} )
SET( OW_LIB_OPENWALNUT ${OPENWALNUT_LIBRARIES} )
ENDIF()
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# The openwalnut executable should print the revision/tag
# 3: version header setup for the external module or OpenWalnut (depending on OW_EXTERNAL_MODULE)
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Generate needed headers
# NOTE: add a line ADD_DEPENDENCIES( XYZ OW_generate_version_header ) to your target XYZ if you need the header!
# where to put the header
SET( OW_VERSION_HEADER_DIRECTORY ${PROJECT_BINARY_DIR}/versionHeader )
# Call the file differently depending on internal or external build
IF( NOT ${OW_EXTERNAL_MODULE} )
# if we build OW, we want the version header to be placed in core later on
SET( OW_VERSION_HEADER_FILENAME "core/WVersion.h" )
# if we build OW, we want the version header to be placed in core later on. We use the internal version header filename directly
SET( OW_VERSION_HEADER_FILENAME ${OW_INTERNAL_VERSION_HEADER_FILENAME} )
SET( OW_VERSION_HEADER_PREFIX "W" )
ELSE()
# if this is for external use, the module might want to use its own version header
# if we build OW, we want the version header to be placed in core later on
SET( OW_VERSION_HEADER_FILENAME "WToolboxVersion.h" )
SET( OW_VERSION_HEADER_PREFIX "WTOOLBOX" )
ENDIF()
# the complete header filename:
SET( OW_VERSION_HEADER_DIRECTORY ${PROJECT_BINARY_DIR}/${OW_VERSION_HEADER_DIRECTORY_RELATIVE} )
SET( OW_VERSION_HEADER ${OW_VERSION_HEADER_DIRECTORY}/${OW_VERSION_HEADER_FILENAME} )
# to allow all those targets to find the header:
INCLUDE_DIRECTORIES( ${OW_VERSION_HEADER_DIRECTORY} )
# Setup the target
SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} )
SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} ${OW_VERSION_HEADER_PREFIX} )
# Set the OW version string. This can be used by others for setting target versions during compilation.
GET_VERSION_STRING( OW_VERSION OW_LIB_VERSION )
......
......@@ -585,7 +585,8 @@ ENDFUNCTION( GET_VERSION_STRING )
# as the target is. If not, an additional target needs to be defined and CMake needs information about generated files.
#
# _OW_VERSION_HEADER the filename where to store the header. Should be absolute.
FUNCTION( SETUP_VERSION_HEADER _OW_VERSION_HEADER )
# _PREFIX the string used as prefix in the header. Useful if you have multiple version headers.
FUNCTION( SETUP_VERSION_HEADER _OW_VERSION_HEADER _PREFIX )
# This ensures that an nonexisting .hg/dirstate file won't cause a compile error (do not know how to make target)
SET( HG_DEP "" )
IF( EXISTS ${PROJECT_SOURCE_DIR}/../.hg/dirstate )
......@@ -595,7 +596,7 @@ FUNCTION( SETUP_VERSION_HEADER _OW_VERSION_HEADER )
# The file WVersion.* needs the version definition.
ADD_CUSTOM_COMMAND( OUTPUT ${_OW_VERSION_HEADER}
DEPENDS ${PROJECT_SOURCE_DIR}/../VERSION ${HG_DEP}
COMMAND ${CMAKE_COMMAND} -D PROJECT_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -D HEADER_FILENAME:STRING=${_OW_VERSION_HEADER} -P OpenWalnutVersion.cmake
COMMAND ${CMAKE_COMMAND} -D PROJECT_SOURCE_DIR:STRING=${PROJECT_SOURCE_DIR} -D HEADER_FILENAME:STRING=${_OW_VERSION_HEADER} -D PREFIX:STRING=${_PREFIX} -P OpenWalnutVersion.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../tools/cmake/
COMMENT "Creating Version Header ${_OW_VERSION_HEADER}."
)
......
......@@ -29,4 +29,4 @@
INCLUDE( OpenWalnutUtils.cmake )
GET_VERSION_STRING( OW_VERSION OW_API_VERSION )
FILE( WRITE ${HEADER_FILENAME} "// generated by CMake. Do not modify.\n#define W_VERSION \"${OW_VERSION}\"\n#define W_LIB_VERSION \"${OW_API_VERSION}\"\n" )
FILE( WRITE ${HEADER_FILENAME} "// generated by CMake. Do not modify.\n#define ${PREFIX}_VERSION \"${OW_VERSION}\"\n#define ${PREFIX}_LIB_VERSION \"${OW_API_VERSION}\"\n" )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment