Commit c7ba64fc authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added automatic setup of additional shared files. This is another...

[ADD] - added automatic setup of additional shared files. This is another example why I sometimes hate cmake.
parent 6e37ecd2
......@@ -284,6 +284,18 @@ ADD_CUSTOM_TARGET( vtest
# Setup everything in ../resources
SETUP_RESOURCES()
SETUP_ADDITIONAL_FILES( ${OW_DOC_DIR_RELATIVE}
"${PROJECT_SOURCE_DIR}/../README"
"${PROJECT_SOURCE_DIR}/../AUTHORS"
"${PROJECT_SOURCE_DIR}/../CONTRIBUTORS"
"${PROJECT_SOURCE_DIR}/../COPYING"
"${PROJECT_SOURCE_DIR}/../COPYING.LESSER"
)
# also copy all the user documentation we have
SETUP_ADDITIONAL_DIRECTORY( ${OW_DOC_DIR_RELATIVE}
${PROJECT_SOURCE_DIR}/../doc/user/
TRUE # this denotes that the contents of doc/user should be copied instead of user directly
)
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
......
......@@ -93,22 +93,11 @@ SETUP_TESTS( "${TARGET_TEST_FILES}" "${BinName}" "" )
# Copy local resources
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Copy the help documents. This is not in the resource directory since it is qt4gui specific, so we need to copy it.
ADD_CUSTOM_TARGET( help
ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/../doc/user/${LibName}/ ${OW_DOC_DIR}/${LibName}/
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/icons/ ${OW_DOC_DIR}/${LibName}/icons
COMMENT "Copy the GUI Documentation"
)
# Also create an install target for this
INSTALL( DIRECTORY ${PROJECT_SOURCE_DIR}/../doc/user/${LibName}/
DESTINATION ${OW_DOC_DIR_RELATIVE}/${LibName}
COMPONENT "RUNTIME"
)
INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/icons
DESTINATION ${OW_DOC_DIR_RELATIVE}/${LibName}
COMPONENT "RUNTIME"
)
# Our user-help needs the icons too. Copy them.
SETUP_ADDITIONAL_DIRECTORY( "${OW_DOC_DIR_RELATIVE}/${LibName}/icons"
"${CMAKE_CURRENT_SOURCE_DIR}/icons"
FALSE # this denoted that the whole directory icons should be copied instead of its contents
)
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Style Checker
......@@ -117,4 +106,4 @@ INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/icons
# setup the stylechecker. Ignore the platform specific stuff.
SETUP_STYLECHECKER( "${BinName}"
"${TARGET_CPP_FILES};${TARGET_H_FILES};${TARGET_TEST_FILES};${TARGET_GLSL_FILES}" # add all these files to the stylechecker
".*/version\\.h" ) # exlude some ugly files
"" ) # exlude some ugly files
......@@ -132,7 +132,8 @@ FUNCTION( SETUP_TESTS _TEST_FILES _TEST_TARGET )
# for each fixture, copy to build dir
FOREACH( FixtureDir ${FixturePaths} )
# we need a unique name for each fixture dir as target
STRING( REGEX REPLACE "[^A-Za-z0-9]" "" FixtureDirEscaped "${FixtureDir}" )
FILE_TO_TARGETSTRING( ${FixtureDir} FixtureDirEscaped )
# finally, create the copy target
ADD_CUSTOM_TARGET( ${_TEST_TARGET}_CopyFixtures_${FixtureDirEscaped}
COMMAND ${CMAKE_COMMAND} -E copy_directory "${FixtureDir}" "${FixtureTargetDirectory}"
......@@ -250,8 +251,69 @@ FUNCTION( SETUP_RESOURCES )
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
ENDFUNCTION( SETUP_RESOURCES )
# This function eases the process of copying and installing additional files which not reside in the resource path.
# It creates a target (ALL is depending on it) AND the INSTALL operation.
# _destination where to put them. This MUST be relative to the build dir and install dir.
# _OTHERS you can add an arbitrary list of additional arguments which represent the files to copy.
FUNCTION( SETUP_ADDITIONAL_FILES _destination )
FOREACH( _file ${ARGN} )
FILE_TO_TARGETSTRING( ${_file} fileTarget )
# add a copy target
ADD_CUSTOM_TARGET( CopyAdditionalFile_${fileTarget}
ALL
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/${_destination}/"
COMMAND ${CMAKE_COMMAND} -E copy "${_file}" "${PROJECT_BINARY_DIR}/${_destination}/"
COMMENT "Copying file ${_file}"
)
# add a INSTALL operation for this file
INSTALL( FILES ${_file} DESTINATION ${_destination}
COMPONENT "RUNTIME"
)
ENDFOREACH()
ENDFUNCTION( SETUP_ADDITIONAL_FILES )
# This function copies a given directory or its contents to the specified destination. Since cmake is quite strange in handling directories
# somehow, we needed to trick here.
# _destination where to put the directory/its contents. Realtive to build dir and install dir.
# _directory the directory to copy
# _contents if TRUE, the contents of _directory are copied into _destination. If FALSE, _destination as-is is copied to _destination/.. (sorry
# for this weird stuff. Complain at cmake mailing list ;-))
FUNCTION( SETUP_ADDITIONAL_DIRECTORY _destination _directory _contents )
# create a nice target name
FILE_TO_TARGETSTRING( ${_directory} directoryTarget )
# add a copy target
# this copies the CONTENTS of the specified directory into the specified destination dir.
# NOTE: cmake -E says, that copying a directory with the copy command is pssible. But on my system it isn't.
ADD_CUSTOM_TARGET( CopyAdditionalDirectory_${directoryTarget}
ALL
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/${_destination}/"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${_directory}" "${PROJECT_BINARY_DIR}/${_destination}"
COMMENT "Copying directory ${_directory}"
)
# we need to distinquish here whether the user wants to copy the contents of the specified directory or the whole directory.
# NOTE: unfortunately, the semantics of cmake -E and INSTALL are different. We need to fix this with this hack.
IF( _contents )
# OK, the user wants us to copy the contents of the specified _directory INTO the dpecified destination
SET( InstallDestination "${_destination}" )
ELSE()
# see "cmake -E " for help. The copy_directory copies its contents and copy copies the directory as is.
SET( InstallDestination "${_destination}/../" )
ENDIF()
# add a INSTALL operation for this file
INSTALL( DIRECTORY ${_directory}
DESTINATION ${InstallDestination}
COMPONENT "RUNTIME"
)
ENDFUNCTION( SETUP_ADDITIONAL_DIRECTORY )
# This function tries to find a proper version string. It therefore uses the file src/../VERSION and mercurial. If the file exists and is not
# empty, the contents of it get combined with the mercurial results if mercurial is installed. If not, only the file content will be used. If
# both methods fail, a default string is used.
......
......@@ -61,3 +61,17 @@ FUNCTION( ASSERT_GE_VERSION _PackageName _ActualVersion _MinimumVersion )
ENDIF()
ENDFUNCTION( ASSERT_GE_VERSION )
# This function converts a given filename to a proper target name. This is very useful if you want to define custom targets for
# files and need a unique name.
# _filename the filename to convert
# _target returns the proper target string
FUNCTION( FILE_TO_TARGETSTRING _filename _target )
# strip the whole path up to src
STRING( REGEX REPLACE "^.*/src" "src" fileExcaped "${_filename}" )
# remove all those ugly chars
STRING( REGEX REPLACE "[^A-Za-z0-9]" "X" fileExcaped "${fileExcaped}" )
# done. Return value
SET( ${_target} "${fileExcaped}" PARENT_SCOPE )
ENDFUNCTION( FILE_TO_TARGETSTRING )
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