[CMake] Different targets for different configurations
Mike Krus
mike at mve.com
Thu Mar 22 19:16:58 EDT 2012
Hi
I would like run a script with different options for debug and release
builds. I can do this easily for Makefiles but am struggling to get it
to work for Visual Studio.
I basically:
- add a custom command the output of which depends on the configuration
- add a custom target for that command
- add that target as a dependency of my other targets (I want the
script to run first)
Here's the CMake code below...
My problem is that for Visual Studio ${CMAKE_BUILD_TYPE} is not set
(normal) and CMake doesn't know about $(CONFIGURATION) since it's a
build time thing (again, normal).
So as it stands, the scripts always runs at every build because it's not
picking up the correct output file.
Any suggestions on how I should go about to make this work?
I was looking for a way of specifying different dependencies for
different configurations (a bit like TARGET_LINK_LIBRARIES lets me
specify different libs)
Cheers,
Mike
ADD_CUSTOM_COMMAND(
OUTPUT
${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}$(CONFIGURATION)setupdone.txt
COMMENT "Preparing build environment"
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/SetupScript.py
--build-type=${CMAKE_BUILD_TYPE}$(CONFIGURATION)
--debug-dir=${LIBRARY_OUTPUT_PATH_DEBUG}
--release-dir=${LIBRARY_OUTPUT_PATH_RELEASE}
--output=${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}$(CONFIGURATION)setupdone.txt
DEPENDS ${PROJECT_BINARY_DIR}/SetupScript.py
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
ADD_CUSTOM_TARGET(MoveBuildSetup DEPENDS
${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}$(CONFIGURATION)setupdone.txt)
And I add the MoveBuildSetup as a dependency to others..
--
Mike Krus (PhD) - Principal Software Engineer
Midland Valley Exploration
144 West George Street
Glasgow G2 2HG, UK
Tel: +44 141 332 2681
Fax: +44 141 332 6792
More information about the CMake
mailing list