CMake : multiple subprojects using the same static library

前端 未结 2 1577
遥遥无期
遥遥无期 2021-02-01 03:50

I\'m using cmake to compile one of my work projets, here is the deal

-
  client/
    CMakeLists.txt
  server/
    CMakeLists.txt
  libs/
    libstuff/
      CMak         


        
2条回答
  •  执笔经年
    2021-02-01 04:15

    A simple solution is to guard the add_subdirectory calls in both the client and the server CMake list file with an if using a TARGET conditional, i.e.:

    if (NOT TARGET plugin)
        add_subdirectory("${CMAKE_SOURCE_DIR}/common/libplugin")
    endif() 
    

    This prevents the libplugin sub-directory from being added more than once.

提交回复
热议问题