cmake-basis / BASIS

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!
https://cmake-basis.github.io
Other
48 stars 10 forks source link

Unable to call Subproject from toplevel project #628

Open srini2174 opened 5 years ago

srini2174 commented 5 years ago

I am trying to create a project following the structure shown below

MyWorkspace
____ MyFramework1
___Module1
___Module2
____ MyFramework2
___Module1
___Module2

I have created the following equivalent BasisProject structure

TopLevelProject
____ Subproject1
___Module1
_ BasisProject.cmake
___Module2
_ BasisProject.cmake
____ Subproject2
___Module1
_ BasisProject.cmake
___Module2
_ BasisProject.cmake
___BasisProject.cmake
___CMakeLists.txt

But there is no way the subproject is called from the toplevel project.

I tried adding basis_add_subdirectory(Subproject1) in the CMakeLists.txt of the toplevelproject. I get the error " Module Subproject1 specified DEFAULT_MODULES, but a module cannot have itself modules."

I tried adding add_subdirectory(Subproject1) in the CMakeLists.txt of the toplevelproject. I get the error

"CMake Error at config/basis-modules/InstallationTools.cmake:456 (add_custom_target): add_custom_target cannot create target "uninstall" because another target with the same name already exists. The existing target is a custom target"

What is the right way to call the subproject from the toplevel project?

schuhschuh commented 4 years ago

I apologize for the very very late response! Though I assume this answer may be too late, here some information as future reference for others. I suggest a look at my other project called MIRTK that uses BASIS with submodules.

You could add Subproject1/Module1, Subproject1/Module2,... to the MODULE_DIRS defined by the top-level project BasisProject.cmake file as done for MIRTK here.

srini2174 commented 4 years ago

I had followed exactly the way it is done in MIRTK, but I still get the error

CMake Error at CMake/Basis/ProjectTools.cmake:358 (message): [cmake] Module PluginItf specified DEFAULT_MODULES, but a module cannot have itself [cmake] modules.

The subprojects are only treated as modules of the top level project and they are not treated as a subproject.

schuhschuh commented 4 years ago

Thanks for following up. In that case, I would say the error message is probably quite specific and may not actually be relating to the fact that your top-level project has modules. Rather, do you have an entry DEFAULT_MODULES in your SubprojectX/ModuleY/BasisProject.cmake files? If so, please remove. Only the TopLevelProject/BasisProject.cmake file should contain a DEFAULT_MODULES option as part of the basis_project command.

Otherwise, please post the content of the top-level BasisProject.cmake file and the PluginItf/BasisProject.cmake, for example.

srini2174 commented 4 years ago

I have removed the DEFAULT_MODULES option in the BasisProject.cmake file. Now the configuration is done. When I build it Ninja gives the message "No work to do".

As I understand SUBPROJECTS can have modules under them. I have all the sources as a module of the subproject. Since I have removed the DEFAULT_MODULES option no module under the subproject is included/built.

schuhschuh commented 4 years ago

Can you list the default subproject modules with DEFAULT_MODULES in the TopLevelProject/BasisProject.cmake file (but not SubprojectX/ModuleY/BasisProject.cmake)? That's how it is also done in MIRTK if you want to have another look to double check.

srini2174 commented 4 years ago

Thanks. I was able to get the configuration done, but I felt that it is counter intuitive. One of my team member works on the sub-project with all the modules. So by default all the modules are on. Finally during the integration I will have to remove all the DEFAULT_MODULES option from all the sub-project and also add the sub-project and all the modules under the sub-project in the toplevel project once again. If I have many modules and many sub-projects this becomes very difficult.

Further I am also having some issues in getting the dependency between sub-projects.