重新扫描CMake并传递参数

时间:2016-12-01 09:09:18

标签: cmake dependency-management

我正在使用外部项目制作CMAKE文件。我跟随这里的例子: CMake ExternalProject_Add() and FindPackage()

但是,我有一个问题。当我拨打cmake时,我使用cmake -G "MinGW Makefiles" ..。不幸的是,-G参数似乎没有传递到重新扫描目标。如何将适用的Cmake命令中继到任何重新扫描?

我认为这是我需要改变的路线

 add_custom_target(Rescan ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS Eigen3)

这是CMakeLists.txt:

find_package( Dep1 )

include (ExternalProject)
ExternalProject_Add (
                   Dep1
                   SVN_REPOSITORY https://svn.company.nl/svn/Dep1-trunk
                   SVN_REVISION -rHEAD
                   TIMEOUT 10
)

if (NOT Dep1_FOUND )
  add_custom_target(Rescan ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS Dep1)
else (NOT Dep1_FOUND)
  add_custom_target(Rescan)
endif (NOT Dep1_FOUND)

#build app
add_executable( Testapp main.cpp )
add_dependencies( Testapp Rescan )

if (${Dep1_FOUND})
  target_include_directories( Testapp PUBLIC ${Dep1_INCLUDE_DIR} )
  target_link_libraries( Testapp ${Dep1_LIBRARY} )
endif (${Dep1_FOUND})

#Install package
install(TARGETS Testapp EXPORT ${PROJECT_NAME}Targets
  RUNTIME DESTINATION bin
)

1 个答案:

答案 0 :(得分:1)

当然,请致电

add_custom_target(Rescan ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} ${CMAKE_SOURCE_DIR} DEPENDS Eigen3)

请参阅CMAKE_GENERATOR变量的文档。