0

I have composite project which contains: C++ library for Linux/Windows, C++/CLI library based on C++ library sources for Windows, C# projects based on C++/CLI library for Windows, C++ projects based on C++ library for Linux/Windows. How to build this kind of projects? What build system I need choose?

Now I use CMake which generate makefile in Linux and MSVS solution in Windows, but it's so difficult to write CMakeLists.txt for build C# projects.

Before I had two MSVS solutions: for managed (which configurated by cmake) and for native (which generated by cmake) code projects. Managed projects were writen in MSVS. Native projects were writen in CMakeLists.txt. CMake were configurating managed projects used Windows enviroment variables which were keeping paths to external libraries, output directories, etc. Surely it's bad decision.

dizel3d
  • 3,619
  • 1
  • 22
  • 35
  • You should have all of it in VS. Is there something more than just "VS" that you were looking for? – N_A Apr 09 '12 at 18:11
  • Do you mean I should have original MSVS project for building in Windows and CMakeLists for building in Linux? But in this case if I want to add source file to native library I need change MSVS project and CMakeLists. – dizel3d Apr 09 '12 at 18:29

2 Answers2

0

MSBuild is a decent build script tool that integrates well with Visual Studio project files (which are essentially MSBuild scripts themselves). There will probably be some learning curve if you've never used it before, but beyond that it's pretty simple to use it to build a .NET project.

Example of building Visual Studio projects using an MSBuild script:

<!-- Compile a C# project and output to a staging directory -->
<MSBuild Projects="MyCsProject\MyCsProject.csproj" Properties="outDir=Staging\bin\MyCsProject" />

<!-- Compile a C++/CLI project and output to a staging directory, then re-sign it -->
<MSBuild Projects="MyCppProject\MyCppProject.vcxproj" Properties="outDir=Staging\bin\MyCppProject" />
<Exec Command="&quot;$(WindowsSDKDirectory)\Bin\sn.exe&quot; -Rc Staging\bin\MyCppProject\MyCppProject.dll $(StrongNameKeyContainer)" />

If you're using Visual Studio Professional or higher, then your can have a solution file that contains both your C# projects and your C++/CLI projects, so it's fairly easy to build everything from within Visual Studio.

However, if you're using the Express editions of Visual Studio, then you will probably want to use MSBuild (or another build script tool), since you can't have a C++/CLI project in the same solution as a C# project using the Express editions, therefore you will want to have an MSBuild script that can compile all of your various projects in one step.

One gotcha that I've run into with C++/CLI projects is with signing. If you need to sign your C++/CLI assembly, then you'll need to add a step to your MSBuild script to use the "sn" tool (should be part of the Windows SDK) to re-sign your C++/CLI assembly after it has been compiled. If you're using a .snk.pfx file, then you will need to use the "sn" tool to first add that key to a key container (with the -i switch), and then you will need to use that key container when you re-sign the assembly (with the -Rc switch).

Dr. Wily's Apprentice
  • 10,212
  • 1
  • 25
  • 27
  • MSBuild is not working under Linux, but I need that native C++ library should be built in Linux and Windows. – dizel3d Apr 09 '12 at 18:39
0

I'm currently working in a project that has C++, CLI and C# and the C++ is also used in an iOS application. The way we have it setup on windows is we have each language in its own project and then all the projects in one solution, that way we can compile everything in one step through the IDE. All the dependencies and such are managed by VS. I think the simplicity of having VS setup all the dependencies and such far outweighs the extra work of making a project for the C++ files. For iOS I have a separate Xcode project that builds all the C++ stuff for iOS, likewise you would have a CMake project for windows.

N_A
  • 19,799
  • 4
  • 52
  • 98
  • How you configure Vusial Studio projects? I mean how you set paths to external libraries, output dir? – dizel3d Apr 09 '12 at 18:59
  • For C++? In the C++ project property pages under VC++ Directories you can set the Library Directories. – N_A Apr 09 '12 at 19:09
  • You only need to set the library directories for applications outside of your solution. The ones inside will put their compiled libraries in a location that is part of the default paths. For C# references to your CLI projects you simply add the desired project to its references. – N_A Apr 09 '12 at 19:28
  • Should I need set Library Directories for every project in soulution? For example in CMake I need set 2 varibales: CRYPTO++_ROOT and BOOST_ROOT. And all projects will be known where to find headers, where to find release libraries, where to find debug libraries. But I seems that set all this paths for every project in Visual Studio is not easy. – dizel3d Apr 09 '12 at 19:32
  • See http://stackoverflow.com/questions/111631/visual-studio-solutions-multiple-project-how-to-effectively-propagate-projec – N_A Apr 09 '12 at 19:38
  • And what about external library name? For example, boost system library name may be boost_system_1_49_0.dll, boost_system_1_50_0.dll depending on boost the version. In CMake I set BOOST_ROOT (boost root path) only. But in MSVS I need set particular library. – dizel3d Apr 09 '12 at 19:41
  • See the link, it explains how to create a property sheet which is inherited by all the property sheets in your project. You would only have to set the boost version in the inherited property sheet, so only one place. – N_A Apr 09 '12 at 19:44