Sunday, 15 April 2012

cmake - CMakeLists configuration to link two C++ projects -


I have the following condition: Project A relies on Project B, but both are built at the same time. To include Project A, which includes Project B and its libraries are also required. Now I have tried this like:

  ADD_SUBDIRECTORY ($ {CMAKE_SOURCE_DIR} / other_project other_project)  

and then:

  INCLUDE_DIRECTORIES (includes $ {CMAKE_SOURCE_DIR} / other_project /}} list (attached LINK_LIBS other_project)  

in Project A's CMakeLists.txt, but it does work It does not seem that the compiler gives me an error while adding Project B's headers, even if they do not exist.

What is the correct way to add dependency to A? How should CMakeLists.txt look like?

Edit:

As suggested in the comments, this question was resolved, although I want to see an example of how to use it, a CMakeList In the txt file The following is a simple example which creates zlib and then creates libxml2 which we rely on the construction zlib

One thing is worth mentioning, I pulled this example quickly from what I have already done. The Libxml2 example uses the make, so it will actually build on a system, in which it is, e.g. Linux, Mac ...

The proposed directory structure for this example is ...

  • src /
    - CMakeLists.txt
      < / Li> --------- External_ZLib.cmake

      External_libxml2.cmake
    • Davoud / (There is no need to create this directory, CMK will do it for you )
    • # Any version that supports ExternalProject, setting cmake_minimum_required (VERSION 3.1) project (test_ext_proj) Set Ahia (test_ext_proj_CMAKE_DIR "$ {CMAKE_CURRENT_SOURCE_DIR} / CMake") or (downloaded CMAKE_MODULE_PATH $ {test_ext_proj_CMAKE_DIR} $ {CMAKE_MODULE_PATH}) Set Test_ext_proj_BUILD_INSTALL_PREFIX $ {CMAKE_CURRENT_BINARY_DIR} / install) Set (test_ext_proj_DOWNLOAD_DIR $ {CMAKE_CURRENT_SOURCE_DIR} / download cache path " (External_jilib) included (external_libxcil2)

      External_ZLib.cm take shots:

      Set Set (ZLib_version 1.2.8) Set (ZLib_url "http://zlib.net/zlib-${ZLib_version}.tar.gz") Set (ZLib_md5 "44d667c142d7cda120332623eab69f40") Exter nalProject_Add (zlib URL $ {ZLib_url} URL_MD5 $ {ZLib_md5} PREFIX $ {vision tpl_BUILD_PREFIX} DOWNLOAD_DIR $ {test_ext_proj_DOWNLOAD_DIR} INSTALL_DIR $ {test_ext_proj_BUILD_INSTALL_PREFIX} CMAKE_GENERATOR $ {General} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX: PATH = $ {test_ext_proj_BUILD_INSTALL_PREFIX} -DCMAKE_BUILD_TYPE = $ { CMAKE_BUILD_TYPE} -DCMAKE_C_FLAGS = $ {CMAKE_C_FLAGS}) # This variable is required, so other packages can find it. Set (libxml2_release "2.9") set (ZLB_ROOT $ {test_ext_proj_BUILD_INSTALL_PREFIX} cache path "")

      External_libxml2.cmake:

        set (libxml2_patch_version 0) Set (libxml2_url "ftp://xmlsoft.org/libxml2/libxml2-sources-${libxml2_release}.${libxml2_patch_version}.tar.gz") Set (libxml2_md5 "7da7af8f62e111497d5a2b61d01bd811") # We need to tell that we depend The build order is set correctly on ZLib (_XML2_DEPENDS ZLib) # This build is required to build, make sure we have it, or error out. If (CMAKE_GENERATOR Matches ". * Makefiles") (MAKE_EXECUTABLE "$ (create)") and () find_program (MAKE_EXECUTABLE make) if (not MAKE_EXECUTABLE) message (FATAL_ERROR "did not get ', to create libxml2 need. ") endif () endif () ExternalProject_Add (libxml2 up $ {_ XML2_DEPENDS} URL $ {libxml2_url} URL_MD5 $ {libxml2_md5} pREFIX $ {test_ext_proj_BUILD_PREFIX} DOWNLOAD_DIR $ {test_ext_proj_DOWNLOAD_DIR} INSTALL_DIR $ {test_ext_proj_BUILD_INSTALL_PREFIX} BUILD_IN_SOURCE 1 CONFIGURE_COMMAND configured prefix = $ {Test_ext_proj_BUILD_INSTALL_PREFIX} - with -zlib = $ {ZLIB_ROOT} BUILD_COMMAND $ {MAKE_EXECUTABLE} INSTALL_COMMAND $ {MAKE_EXECUTABLE} Install)  

No comments:

Post a Comment