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?

+3


source to share


1 answer


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 the install(...EXPORT...)

    cand commands install(EXPORT ...)

    which handle this automatically by setting the appropriate config property to the target object IMPORTED

    (for example IMPORTED_LOCATION_DEBUG

    and IMPORTED_LOCATION_RELEASE

    )
  • if your search module only contains variables, for example CPLEX_LIBRARIES

    you can use specifiers debug

    and optimized

    :

    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.

+3


source







All Articles