c++ - Isolating gitsubmodule projects in CMake -


i'm trying manage c++ project dependencies using cmake , gitsubmodules. i'm following layout described here: http://foonathan.net/blog/2016/07/07/cmake-dependency-handling.html , it's worked me on smaller projects. i've started use on larger projects , i'm hitting issue cmake.

my current setup

all external build dependencies in contrib/ subfolder inside main project. each submodule , has own separate directory. /contrib - /eigen - /curl - /leapserial - /zlib - /opencv etc.

the contrib/cmakelistst.txt initializes submodule , adds subdirectory each external dependency

# eigen execute_process(command git submodule update --recursive --init -- eigen  working_directory ${cmake_current_source_dir}) # options.. add_subdirectory(eigen exclude_from_all)  # curl execute_process(command git submodule update --recursive --init -- curl  working_directory ${cmake_current_source_dir}) # initialize cache cmake build options.. add_subdirectory(curl exclude_from_all)  # leap serial execute_process(command git submodule update --recursive --init -- leapserial  working_directory ${cmake_current_source_dir}) # initialize cache cmake build options.. add_subdirectory(leapserial exclude_from_all)  # zlib execute_process(command git submodule update --recursive --init -- zlib  working_directory ${cmake_current_source_dir}) # initialize cache cmake build options.. add_subdirectory(zlib exclude_from_all)  # opencv execute_process(command git submodule update --recursive --init -- opencv   working_directory ${cmake_current_source_dir}) # initialize cache cmake build options.. add_subdirectory(opencv exclude_from_all) 

this setup has worked fantastically me:

  1. it's system/packagemanager independent. don't need install libraries started developing
  2. i can maintain exact versions of dependencies setting submodule particular commit. there no surprises external library breaking build
  3. adding libraries build in root cmakelistst.txt trivial. since have target available have add_executable(someprojectimworkingon ${cmake_current_source_dir}/src/main.cpp ) target_link_libraries(someprojectimworkingon opencv_world eigen zlib etc.)
  4. when hook existing library target own target executable/library cmake automatically (through target interface) add include directories target , add other necessary options library target requires used
  5. i can pick toolchain/compiler-option/build-type in root cmakelists.txt , it'll propogate subprojects (i need build multiple systems. big big deal)
  6. since it's in 1 "mega-project" makes easy hook rtags/kdevelop/clion navigate not on own code, library code

some issues can't resolved:

1

subdirectories define targets same name. in example gave, both eigen opencv library define 'uninstall' target

i tried update the

add_subdirectory(blah) 

to

add_subdirectory(blah exclude_from_all) 

but doesn't fix issue reason

enabling variable allow_duplicate_custom_targets kinda works.. hack, work make files, , libraries still "mixing" it's still issue

2

the second issue came in leapserial illustrates bigger issue. project no longer knows it's own name. leapserial tried determine version of leapserial, when asks project version it's getting root project version. ie. when cmake code in subproject asks "what project in" it's getting root project, , not immediate project it's in.

so again, parent "namespace"s leaking everywhere. bound create more , more issues down line. need submodules self-contained

is there cleaner solution?

externalprojectadd might solve of these problems, has lot more issues of own. it's real non-starter b/c doesn't of i've listed. central issue doesn't expose sub-project's targets - , vomits variables have juggle


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -