使用CMake查找scala-library.jar

时间:2017-02-02 15:59:56

标签: scala cmake

我想使用CMake为我的项目找到scala-library.jar的位置。这可以通过在CMake中使用 execute_process 函数来执行scala代码并获取位置来以某种方式完成吗?

1 个答案:

答案 0 :(得分:2)

是的,您可以使用execute_process()来呼叫shell以查找scala-library.jar。您也可以使用CMake的FindJava.cmakeUseJava.cmake模块。

裸骨CMakeLists.txt看起来像是:

cmake_minimum_required(VERSION 3.0)

find_package(Java COMPONENTS Runtime)
if(JAVA_FOUND)
    include(UseJava)
else()
    message(WARNING "Couldn't find Java")
endif()

find_jar(SCALA_JAR "scala-library")
message("scala-library.jar is at ${SCALA_JAR}")

事实上,在我的debian系统上(完成apt-get install default-jre scala之后),我得到了:

$ cmake .
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found Java: /usr/bin/java (found version "1.7.0.111") 
scala-library.jar is at /usr/share/java/scala-library.jar
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nega/foo
$

阅读UseJava上的文档,了解如何使用find_jar()进行更具体的搜索。