2

I'm having a bigger CMake project with a lot of subprojects. Almost all subprojects are written in C++, so it is no problem to integrate them simply via add_subdirectory. There however are some parts of the project which are written in C# and Python. Both of them currently use Visual Studio Solutions to build them.

Currently we're building the CMake-stuff at first, then the solutions afterwards. We then copy the created binaries into their respective directories in the CMake install directory. It would be a lot more practical if we could just build everything with CMake.

MyProject
|
|--> CMakeLists.txt (includes all subprojects)
|
|--> SubA (C++)
|-----> CMakeLists.txt
|
|--> SubB (C++)
|-----> CMakeLists.txt
|
|--> SubC (C#)
|-----> SubC.sln
|
|--> SubD (Python)
|-----> SubD.sln

I would like to integrate them directly into the CMake environment but cannot find what the best way to do that.

Is there a way to integrate non-C++ subprojects into a CMake project? Are there any best practices for this case?

NOTE: The Python solution just calls some script-commands to convert it into an executable. No need to use the solution directly in here, this could also be done via a call to an external batch script or something like that.

MOnsDaR
  • 8,401
  • 8
  • 49
  • 70

2 Answers2

3

I did the same in one of my project. I have a big solution with many C++ projects and two C# projects.

I used include_external_msproject.

In MyProj/CMakeLists.txt:

cmake_minimum_required (VERSION 2.6)

project (MyProj)

include_external_msproject( my_proj path_to_myproj/myproj.csproj
TYPE FAE04EC0-301F-11D3-BF4B-00C04F79EFBC )

And in my main /CMakeLists.txt:

ADD_SUBDIRECTORY( "MyProj/" )

I don't know if you can use the same for a python project...

Pierre Fourgeaud
  • 14,290
  • 1
  • 38
  • 62
  • Thanks a lot! I also found this question: http://stackoverflow.com/questions/2074144/generate-c-sharp-project-using-cmake which helped me building the C# projects – MOnsDaR Mar 20 '14 at 10:29
  • You're linking to an old documentation of `include_external_msproject`, the version you're using is here: http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command%3ainclude_external_msproject – MOnsDaR Mar 20 '14 at 10:30
  • @MOnsDaR Yes sorry I modified the link, Thanks. In my `CMakeLists.txt` there is more than just thoses lines :) I modify also the `.csproj` a bit to match my requirements. If you need more, just tell me ;) – Pierre Fourgeaud Mar 20 '14 at 10:35
  • I think I got the pointers I needed. I'm just waiting for some information about the Python part before accepting an answer. – MOnsDaR Mar 20 '14 at 11:58
0

In addition to the answer from Pierre which covers the C# side:

I'm now building the Python components via execute_process. I created a batch-file which executes the needed steps. For more customization I could use configure_file and put some CMake magic into the script.

On Linux I'll simply use a shell script.

MOnsDaR
  • 8,401
  • 8
  • 49
  • 70