我有一个CMake文件,其中包含依赖于软件包的目标(即Java)以及不需要Java的目标。 我希望能够构建不要求Java且不需要Java的目标。
add_executable(nojava_targ "")
add_executable(java_targ "")
问题在于,一旦CMake在没有Java的机器上看到要求Java的项目,则CMake出现错误,并拒绝构建Makefile。即使不需要Java,这也可以防止构建不需要Java的目标。
find_package(JNI COMPONENTS Development)
target_include_directories( java_targ PRIVATE
${JTARG_INCLUDES}
${JNI_INCLUDE_DIRS})
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/mnt/src/prjx/JAVA_INCLUDE_PATH
used as include directory in directory /mnt/src/prjx/
是否可以通过某种方式向CMake发出此程序包的信号,但仅某些目标机发出信号?
答案 0 :(得分:0)
find_package将找到包将JNI_FOUND设置为true,因此添加任何Java目标 仅当JNI_Found为true时才使用命令。像这样:
find_package(JNI COMPONENTS Development)
if(JNI_FOUND)
add_executable(java_targ java_targ.cpp)
target_include_directories(java_targ PRIVATE
${JTARG_INCLUDES}
${JNI_INCLUDE_DIRS})
endif()