From 36e0adfcc1cea7532bb7f1c5a843ab3a662ff154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Mayer?= Date: Thu, 10 Oct 2013 13:37:15 +0000 Subject: [PATCH] Generate setpath.bat to set the paths necessary for running the generated binaries inside the build dir. svn path=/trunk/; revision=52492 --- CMakeLists.txt | 3 +++ cmake/modules/FindWSWinLibs.cmake | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d13c4233c..f4978a3309 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,6 +475,9 @@ endforeach() # Provide Windows system lib names include( UseWinLibs ) +# Create file to set paths to run binaries from build dir +WSExtendPath( "${WS_ALL_LIBS}" "${CMAKE_BINARY_DIR}/setpath.bat" ) + #packaging include(CPackConfig.txt) diff --git a/cmake/modules/FindWSWinLibs.cmake b/cmake/modules/FindWSWinLibs.cmake index f98f58c1a8..208d626ea0 100644 --- a/cmake/modules/FindWSWinLibs.cmake +++ b/cmake/modules/FindWSWinLibs.cmake @@ -22,5 +22,34 @@ function(FindWSWinLibs _WS_LIB_SEARCH_PATH _LIB_HINT_VAR) endif() endforeach() endif() -endfunction(FindWSWinLibs) +endfunction() +function(WSExtendPath _LIB_PATH_LIST _PATH_FILE) + if (WIN32) + #message( STATUS "All libs: ${_LIB_PATH_LIST}." ) + foreach( THIS_LIB_PATH ${_LIB_PATH_LIST} ) + get_filename_component( LIB_PATH ${THIS_LIB_PATH} PATH ) + #message( STATUS "Raw path ${THIS_LIB_PATH} processed to ${LIB_PATH}." ) + set( WS_LOCAL_LIB_PATHS "${WS_LOCAL_LIB_PATHS}" ${LIB_PATH} ) + endforeach() + list( REMOVE_DUPLICATES WS_LOCAL_LIB_PATHS ) + # All generated libs go here, so start our libsearch in this place + set( WS_LOCAL_LIB_PATHS "${CMAKE_BINARY_DIR}/lib" "${WS_LOCAL_LIB_PATHS}" ) + file( TO_NATIVE_PATH "${WS_LOCAL_LIB_PATHS}" WS_NATIVE_LIB_PATHS ) + if ( EXISTS ${_PATH_FILE} ) + file( READ ${_PATH_FILE} OLD_FILE_CONTENT ) + else() + set( OLD_FILE_CONTENT " " ) + endif() + #message( STATUS "Searching for ${WS_NATIVE_LIB_PATHS}\nin ${OLD_FILE_CONTENT}" ) + string( FIND "${OLD_FILE_CONTENT}" "${WS_NATIVE_LIB_PATHS}" PATH_FOUND_AT ) + #message( STATUS "Location of substr: ${PATH_FOUND_AT}" ) + if( PATH_FOUND_AT GREATER -1 ) + message( "\n${_PATH_FILE} is up to date.\n" ) + else() + #message( STATUS "Native paths: ${WS_NATIVE_LIB_PATHS}" ) + file( WRITE ${_PATH_FILE} "set PATH=%PATH%;${WS_NATIVE_LIB_PATHS}" ) + message( "\n${_PATH_FILE} is new/updated, please run it.\n" ) + endif() + endif() +endfunction()