c++ - Cmake multi-library scenario -


we organize c++ project this:

project/     lib1/       (first library)         cmakelist.txt         src/             lib1.c             foo1.h         build/         test/       (tests)             cmakelist.txt             test1.c             test2.c     lib2/       (second library)         cmakelist.txt         src/             cmakelist.txt             os/              (os dependent code)                 cmakelist.txt                 win32/                     xxx.c    (win32 implementation)                 linux/                     xxx.c    (linux implementation)             lib2.c             foo2.h         build/     include/    (shared/public headers)         lib1/             lib.h    (shared library header included apps)         lib2/             lib.h    (shared library header -"-) 

please, how write cmakelists.txt when lib2 should use link1 , when e.g. lib2 should portable (at least win32, linux...)?

correction: if cmakelist.txt files not on places, please assume so. forgot.

the whole philosophy start central cmakelists.txt whole project. @ level targets (libs, executables) gonna aggregated there no problem linking lib1 lib2 example. if lib2 gonna linking lib1, lib1 needs built first.

platform specific source files should set conditionally variable. (if need set variable in subdirectory , use in directory above, have set cache, using cache force etc. - see manual set)

this how proper out of source build - cmake intends:

cd project-build cmake ../project 

having separate build directories per library not cmake'ish (if may so) , require hacks.

project-build/ project/     cmakelists.txt (whole project cmakelists.txt)     [         project(myawesomeproject)          include_directories(include) # allow lib1 , lib2 include lib1/lib.h , lib2/lib.h         add_subdirectory(lib1) # adds target lib1         add_subdirectory(lib2) # adds target lib2      ]      lib1/       (first library)         cmakelist.txt         [             add_library(lib1...)             add_subdirectory(test)         ]         src/             lib1.c             foo1.h         test/       (tests)             cmakelist.txt             test1.c             test2.c     lib2/       (second library)         cmakelist.txt         [             add_subdirectory(src)         ]         src/             cmakelist.txt             [                 if(win32)                     set(lib2_os_sources os/win32/xxx.c)                 elsif(linux)                     set(lib2_os_sources os/linux/xxx.c)                 else()                     message(fatal_error "unsupported os")                 endif()                 add_library(lib2 shared lib2.c ${lib2_os_sources})             ]             os/              (os dependent code)                 win32/                     xxx.c    (win32 implementation)                 linux/                     xxx.c    (linux implementation)             lib2.c             foo2.h     include/    (shared/public headers)         lib1/             lib.h    (shared library header included apps)         lib2/             lib.h    (shared library header -"-) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -