javamacoscmakejava-native-interfacesumo

Unable to CMAKE on Mac M2 - JNI was not found


I am trying to build SUMO on MAC M2, I am following the instructions from this source.

When I initiate cmake -B build, I get the following error:

-- CMAKE_BINARY_DIR: /Users/daspr/sumo/build
-- CMAKE_SOURCE_DIR: /Users/daspr/sumo
--
-- Platform:
--     Host: Darwin-23.4.0 arm64
--     Target: Darwin-23.4.0 arm64
--     CMake: 3.30.2
--     CMake generator: Unix Makefiles
--     CMake build tool: /usr/bin/make
--     Compiler: AppleClang 14.0.3.14030022
--
-- Found Python: /Users/daspr/opt/anaconda3/bin/python3.9
-- Brew detected: /opt/homebrew
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
-- Found Proj: /opt/homebrew/lib/libproj.dylib
-- Found Fox: -I/opt/homebrew/Cellar/fox/1.6.58/include/fox-1.6 -L/opt/homebrew/Cellar/fox/1.6.58/lib -lFOX-1.6 -lX11 -lXext -lfreetype -lfontconfig -lXft -lXcursor -lXrender -lXrandr -lXfixes -lXi -ldl -lpthread -ljpeg -lpng -ltiff -lz -lbz2 -lGLU -lGL
-- Could NOT find suitable FFmpeg.
-- Could NOT find JuPedSim! Skipping JuPedSim integration.
-- Found Java: /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home/bin/java (found version "20.0.0") found components: Development
-- Found Java: /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home/bin/java (found version "20.0.0")
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
CMake Warning at src/libsumo/CMakeLists.txt:151 (message):
  ENABLE_JAVA_BINDINGS is set but Java or JNI was not found.


xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
CMake Warning at src/libtraci/CMakeLists.txt:110 (message):
  ENABLE_JAVA_BINDINGS is set but Java or JNI was not found.


-- Enabled features: Darwin-23.4.0 arm64 AppleClang 14.0.3.14030022 Release FMI Proj GUI FMT Intl SWIG Eigen GDAL OSG GL2PS
-- Configuring done (2.4s)
-- Generating done (0.9s)
-- Build files have been written to: /Users/daspr/sumo/build

I already have Java installed and echo $JAVA_HOME returns /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home.

Error faced:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
    CMake Warning at src/libsumo/CMakeLists.txt:151 (message):
      ENABLE_JAVA_BINDINGS is set but Java or JNI was not found.

Please help.


Solution

  • The xcode-select error is pretty pertinent to your situation but in a very roundabout way: CMake runs xcodebuild --version to see if Xcode is 12.1 or newer. Depending on the answer it switches the internal CMAKE_FIND_FRAMEWORK to ONLY or NEVER. If the check fails (because xcodebuild -version does not return anything), it is set to the "ONLY" mode in which it will fail to find any files.

    Add the following somewhere globally, before you call find_package for either Java or JNI to bypass the Xcode check:

    set(XCODE_VERSION "15.0")
    

    You will need to remove your build directory to get rid of any cached variables too.

    EDIT: I reported this upstream.