[CMake] Target 'copy-construction'/'fork'
Parag Chandra
parag at ionicsecurity.com
Thu Dec 11 09:47:40 EST 2014
I¹m not aware of any means to clone a target, but for what you are
describing, custom configurations will work better. For the specific use
case you mention below, start by seeding the new configurations like this:
set (CMAKE_CONFIGURATION_TYPES
Debug;Release;RelWithDebInfo;MinSizeRel;Debug_Clone;Release_Clone;RelWithDe
bInfo_Clone;MinSizeRel_Clone CACHE INTERNAL "Configuration types" FORCE)
foreach (cfg "DEBUG" "RELEASE" "MINSIZEREL" "RELWITHDEBINFO")
foreach (flag "CXX" "C" "EXE_LINKER" "MODULE_LINKER" "SHARED_LINKER"
"STATIC_LINKER")
set (CMAKE_${flag}_FLAGS_${cfg}_Clone ${CMAKE_${flag}_FLAGS_${cfg}}
CACHE STRING "${flag} flags for ${cfg}_Clone" FORCE)
endforeach ()
endforeach ()
So you essentially start with a clone of the default configurations that
CMake gives you. Then you can adjust the new configurations as you see
fit. The following block will adjust all the _Clone configurations to link
with /MT rather than the default /MD:
foreach (cfg "DEBUG" "RELEASE" "MINSIZEREL" "RELWITHDEBINFO")
foreach (flag_var CMAKE_C_FLAGS_${cfg}_Clone
CMAKE_CXX_FLAGS_${cfg}_Clone)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif ()
endforeach ()
endforeach ()
Hope this helps.
Parag Chandra
Software Engineer, Mobile Team
Mobile: +1.919.824.1410
<https://ionic.com>
Ionic Security Inc.
1170 Peachtree St. NE STE 2285, Atlanta, GA 30309
On 12/10/14, 8:58 AM, "Domagoj Saric" <domagoj.saric at littleendian.com>
wrote:
>Hi,
>
>Given a target named Foo, is there a simple/builtin way to create a copy
>of that
>target named Bar so that it retains all the properties of Foo but can be
>independently changed from that point onward i.e. is there a way for
>CMake
>targets to follow the semantics of standard C++ objects with
>copy-constructors..?
>This would be useful for creating targets which are essentially the same
>but
>differ only in a few properties (e.g. creating /MD and /MT versions of a
>MSVC
>DLL)...
>
>
>--
>Domagoj Saric
>Software Architect
>www.LittleEndian.com
>--
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For more
>information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake
More information about the CMake
mailing list