Best practice for handling release / debug libraries in cmake find module
I am trying to write a cmake search module for an external library and also make this work under Windows. The library has different paths for compiled versions with debug and release flags (-MD and -MDd), as well as for different compiler versions. For example, the following paths exist:
C:/cplex/lib/x86_windows_vs2012/stat_mda/cplex1262.lib
C:/cplex/lib/x86_windows_vs2012/stat_mdd/cplex1262.lib
C:/cplex/lib/x86_windows_vs2013/stat_mda/cplex1262.lib
C:/cplex/lib/x86_windows_vs2013/stat_mdd/cplex1262.lib
What's the best practice for handling this in the search module?
source to share
There are two ways to unlock and debug versions, depending on whether you provide a library IMPORTED
or just a list of files in a variable CPLEX_LIBRARIES
:
- for the library
IMPORTED
you have to use theinstall(...EXPORT...)
cand commandsinstall(EXPORT ...)
which handle this automatically by setting the appropriate config property to the target objectIMPORTED
(for exampleIMPORTED_LOCATION_DEBUG
andIMPORTED_LOCATION_RELEASE
) -
if your search module only contains variables, for example
CPLEX_LIBRARIES
you can use specifiersdebug
andoptimized
:set(CPLEX_LIBRARIES optimized <path-to-release.lib> debug <path-to-debug.lib>)
To choose between vs2012 and vs2013, your find module must query the variables MSVC11
and MSVC12
.
For other flags, see the Boost lookup module for legends.
I would also recommend writing a config module instead of find-module.
source to share