In my CMake script I'm adding a custom configuration type like suggested in the CMake FAQ:
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Debug Release MyRelease)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE)
endif()
I would like to have a MyRelease configuration in my generated Visual Studio 2015 project that behaves like Release but with an additional post-build step. The problem is, that it appears to use the Debug configuration as the basis by default. This, in turn, becomes a problem when using imported targets that don't explicitly specify the library location for my own configuration type. For example, when using the imported target opencv_core it will try to link against the opencv_core2413d.lib which is defined specifically for Debug configuration.
Is there a way to let custom configuration types inherit from the Release configuration type?
Note: I'm using CMake version 3.12.
Related
In CMake, is it possible to make target dependencies specific to a particular configuration?
My structure is an executable, which can be built with different backend renderers, one OpenGL and the other D3D. The backend renderers have their own (static) libraries, and only one library should be linked in, based on the configuration (eg. GL_Debug, D3D_Debug, etc). However, it doesn't seem as though the add_dependency command has any options for per-configuration settings.
My current solution is to use generation configurations (Debug, Release, etc), and an option to select the renderer type, and regenerate the solution if I'd like to switch. However, this is clunky if I want to switch between the two frequently. Ideally, I would have a solution with all the renderer configurations, and could just switch between them in Visual Studio.
target_link_libraries command may link in configuration-dependent way. Alternatively, generator-expressions can be used for LINK_LIBRARIES property for executable/library.
Lets say I have a solution S1 with two projects pdep and pmaster, respectively creating a static and dynamic library. I have the configurations:
release win32 : produces pdep.lib
debug win32 : produces pdepd.lib
release x64 : produces pdepx64.lib
debug x64 : produces pdepx64d.lib
pmaster link configuration is done by Configuration Properties -> Linker -> Input -> Additional Dependencies
No #pragma comment(lib ) in the code. No common properties references.
What I observe :
In s1 with both pdep and pmaster the command line for the linker is fine. ie /LIBPATH:"c:\pdep\lib\x64\Release" "pdepx64.lib"
In a solution S2 freshly created by clicking on the project pmaster, I always have an additional line with an absolute path to a specific version of pdep, regardless of the configuration. ie /LIBPATH:"c:\pdep\lib\x64\Release" "pdepx64.lib" "c:\pdep\lib\pdepd.lib"
How does the linker in S2 derives the additional option "c:\pdep\lib\pdepd.lib"? How do I get rid of it?
Multiple possibilities:
Common Properties -> References
Link Library Dependencies in Linker or Librarian section. This assumes that Project Dependencies have been setup.
#pragma comment(lib...) is playing some role
You can flatten the project file using msbuild with a preprocess flag. Then load that into a plain text or xml editor. Look at the linker command and see what $(properties) hold the options, and then look at where that is being set.
With msbuild you can also use more verbose logging and it will report which conditions are evaluated and such.
I'm coming up against a problem in the creation of an Xcode compiler plugin that appears to be the result of a problem in the way compile lines are generated by Xcode and how some of these options are overridden by the platform SDK.
Upon creating a custom compiler plugin that functions perfectly when building applications for MacOSX. I noticed a problem when building applications for iPhoneOS. The SDK continually complains about an invalid value in the min-iphoneos-version variable, the reason being that this isn't set on the compile command-line. Looking at the iPhoneOS platform SDK for Xcode5 you notice that the setting is defined in the 'Native Build System.xcspec' file (Applications/Xcode.app/Contents/Developer/Platforms/iPhone*.platform/Developer/Library/Xcode/Specifications/). Essentially, from what I can gather, this file is consulted and the -mmin-macosx-version flag is overwritten with this command-line option which results in a valid build for Apple compilers. However, create your own compiler plugin and problem ensue since your new compiler will not be matched by any of the 'Compiler' definitions in the 'Native Build System.xcspec' file.
I can only think of a couple of solutions to this,
rewrite/patch the 'Native Build System.xcspec' file upon installation, resulting in an horrendous solution requiring making unsupportable patches to Apple's build system.
another technique that allows a custom compiler plugin to define options specific for a platform SDK via some matching technique,
if a new .xcspec file is added to a Plugin in the PrivatePlugIns directory as a Resource, do all of these files get parsed upon build-time? if so then it may be possible to add these settings to a file such as,
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneSimulator Build System Support.xcplugin/Contents/Resources/MyPlugin.xcspec
Has anyone else come up against this 'road-block' (ahem, design problem)?
I'm trying to use differents configurations for multi-library use.
I explain : i have to use many library for one solution, but i need to change the configuration for each library target, for a debug use of my solution some library will be in 'debug' mode but some other needs a 'Render' configuration. (It's 3rdParty project i can't edit them)
I want to know if its possible.
Thanks !
Here an example the result i wanted to have :
http://i48.tinypic.com/mtugqf.png
You can almost do this. CMake allows for extra configurations by setting CMAKE_CONFIGURATION_TYPES, so in your case this would be
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};Render" CACHE STRING "" FORCE)
This needs to be after the project command.
However, this adds a new configuration type to all targets. I don't think CMake has the ability to mix different configurations for individual targets. You'd still have to manually modify the specific libraries' configs via the Configuration Manager once CMake had created the .sln.
I am using VS2010 Express and just installed Boost v1_47. I have added the 'include' folder to 'additional include folders' option, and also the 'lib' folder to the 'additional libraries' option in VS.
Then, I included boost/regex.hpp in one of my files, but actually wrote no code using boost yet. However, when building the solution I get lots of error messages, coming in two flavours:
Redefiniton errors, such as:
1>D:\boost\boost_1_47\boost/detail/interlocked.hpp(83): error C2373: '_InterlockedCompareExchangePointer' : redefinition; different type modifiers
1> C:\Program Files\Microsoft SDKs\Windows\v7.1\include\winnt.h(2597) : see declaration of '_InterlockedCompareExchangePointer'
Invalid calling convention errors (lots of these), such as:
D:\boost\boost_1_47\boost/regex/v4/regex_traits_defaults.hpp(271): error C3641: 'boost::re_detail::global_lower' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe
Note: I haven't explicitly included winnt.h in any of my source/header files, and have tried de-activating pre-compiled headers and removing the stdafx.h includes, but it didn't solve the problem.
What's going on?
Thanks in advance
You have to make sure that you compile your program with the same settings as boost.
It seems like you used the wrong project template (CLR something) to create your application project.
You could try to modify the properties of your existing project to make it compatible with boost, but the CLR ... projects have lots of incompatible property values set by default, so i think the easiest way would be to create a new project from scratch (and import your existing code).
You should use the "Empty Project" template and create a new project, and then add your existing source and header files to it, and add the boost include path again, and add any required boost .lib files to Project Properties > Linker > Input > Additional Dependencies (Most boost libraries work out of the box without adding anything to linker inputs because they are header only, so you might not need to add any .libs).
Boost is a C++ required, designed to be consumed by C++ code, not C++/CLI code, thus it can only be used with native C++ classes, and most boost headers will produce headers when included in a source file which contains C++/CLI code.