[CMake] [WINDOWS] POST_BUILD event troubles
Tristan Carel
tristan.carel at gmail.com
Sun Aug 12 10:15:41 EDT 2007
Hi,
I have a target, which produce 2 files:
Release configuration:
- iniparser.py
- _iniparser.dll
Debug configuration:
- iniparser.py
- _iniparserd.dll
(Note the `d' suffix on the shared library name in debug.)
For testing purpose, I need the shared library to be in the same
directory than the Python wrapper.
With the `NMake Makefiles' generators, they are both generated in the
same directory, so no problem. But with Visual Studio generators, the
shared library is built in a subdirectory relative to the current
build type. So I chosed to add a POST_BUILD target to the initial
target which just copy the shared library in the parent directory.
the variables involved here are:
- shared library output directory (configuration dependant, and fully
expanded at build time):
GET_TARGET_PROPERTY(__dll_path mytarget LOCATION)
- destination directory: ${CMAKE_CURRENT_BINARY_DIR}
- shared library name: ?????
I can't figure out how to get the name of the library at build-time. I
previously set `CMAKE_DEBUG_POSTFIX' to "d" so that the library name
is build-type-dependant.
The workaround I use is the one below:
# -----------------------------------------------------------------------
IF(MSVC_IDE)
# Under Visual Studio, the shared library is built in a
subdirectory, relative
# to the current build configuration (Release, Debug, ...)
# whereas the Python module is built in the current binary directory.
# In order to properly runs the Python tests, they both have to be in the
# same directory. The workaround is to copy the shared library in the
# current binary directory.
GET_TARGET_PROPERTY(__dll_path ${SWIG_MODULE_iniparser_REAL_NAME}
RELEASE_LOCATION)
GET_TARGET_PROPERTY(__dll_debug_path ${SWIG_MODULE_iniparser_REAL_NAME}
DEBUG_LOCATION)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/post-copy.bat
"@echo off
set dll=\"${__dll_path}\"
if \"%1%\"==\"Release\" goto copy
set dll=\"${__dll_debug_path}\"
:copy
\"${CMAKE_COMMAND}\" -E copy \"%dll%\" \"${CMAKE_CURRENT_BINARY_DIR}\"
")
ADD_CUSTOM_COMMAND(TARGET ${SWIG_MODULE_iniparser_REAL_NAME} POST_BUILD
COMMAND post-copy.bat ${CMAKE_CFG_INTDIR}
"${CMAKE_CURRENT_BINARY_DIR}")
ENDIF(MSVC_IDE)
# -----------------------------------------------------------------------
but I really wish to find a clean solution.
Thank you by advance.
--
Tristan Carel
Music with dinner is an insult both to the cook and the violinist.
More information about the CMake
mailing list