CMake:如何在父级构建之前让子目录安装

时间:2018-07-30 01:08:20

标签: cmake

Top项目A具有两个add_subdirectory(B),add_subdirectory(C)。 并且A将包含B生成的头文件,因此在B中,INSTALL会将文件复制到dist。 问题是:
    总是在构建A时,仅在B,C,A构建完成后才执行B和C的安装,因此第一次A的构建总是失败,因为头文件不存在。

子目录:eventloop

project(eventloop)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}  src_list)
message("event ${CMAKE_CURRENT_SOURCE_DIR} ")
add_library(eventloop ${src_list})

set_target_properties(eventloop PROPERTIES PUBLIC_HEADER 
"IDeferredMethodRunner.hpp;IFdEventHandler.hpp;IEventLoop.hpp;ITimerEventHandler.hpp;TEventLoop.hpp;TEventPump.hpp;TEventItem.hpp;TEventFd.hpp")
INSTALL(TARGETS eventloop 
        ARCHIVE DESTINATION $ENV{ECARX_PROJECT_ROOT_PATH}/dist/lib
        LIBRARY DESTINATION $ENV{ECARX_PROJECT_ROOT_PATH}/dist/lib
        PUBLIC_HEADER DESTINATION  $ENV{ECARX_PROJECT_ROOT_PATH}/dist/include/eventloop
        )

add_custom_command(
    TARGET eventloop
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install
    )

主要目录:车辆

cmake_minimum_required(VERSION 3.11.3)
project(vehicleman)



add_subdirectory(../../common/cpp/eventloop   event)
add_subdirectory(../../common/cpp/socket   socket)


aux_source_directory(. src_list)
add_executable(vehicleman ${src_list} )
target_include_directories(vehicleman PUBLIC $ENV{ECARX_PROJECT_INCLUDE_DIR})
target_link_libraries(vehicleman pthread eventloop socket)
##add_dependencies(vehicleman $ENV{ECARX_PROJECT_INCLUDE_DIR})
#[[find_package(GTest REQUIRED)

include(GoogleTest)

set(unittest_srcs unittests/main.cpp TProcess.cpp)

add_executable(tests ${unittest_srcs})

add_executable(dumy_bin unittests/dumy_bin.cpp)


target_include_directories(tests PUBLIC ./)
target_link_libraries(tests gtest gtest_main pthread eventloop)
enable_testing()
##gtest_add_tests(TARGET tests TEST_PREFIX old:)
##gtest_discover_tests(tests TEST_PREFIX new:)
add_test(NAME test COMMAND tests)
]]

总的来说,当建造车手时,我要做cmake

  1. 构建事件循环
  2. 安装eventloop
  3. 造车工

0 个答案:

没有答案