Search code examples
javacmake64-bit32-bit

How to make CMake's FindJava get 64 bit Java with a 32 bit Visual Studio generator


I apply CMake to generate a Visual Studio 2017 solution to build a 32-bit application on and for Windows 10. To create the build system I let CMake call some Java tools to generate some of the code to compile (applying Eclipse Modeling Framework). To find Java itself I apply the CMake finder module FindJava in a find_package(Java) call.

I've observed that FindJava automatically selects the 32-bit version of Java in this case although a 64-bit Java is also available. Note, when I call CMake to generate for Visual Studio 2017 x64, FindJava returns with 64-bit Java. So, the Java version seems to depend on the bitness of the generator in use.

My problem is, that the 32-bit Java sometimes cannot allocate enough heap memory to execute the code generation tools.

To avoid that, I would like to have FindJava always find the 64-bit Java independent of the Visual Studio generator bitness.

How can I achieve that?

I currently use CMake 3.14 but could update if it helps.

Edit

I forgot to mention that I implement the CMake build system to be used by many developers on their machines. So I'd prefer to not assume a fixed path to the 32-bit and 64-bit Java installations on the build machines.


Solution

  • Analysing the code of FindJava.cmake showed that it is currently not possible to select the Java bitness manually as requested.

    I've filed a change request for that: https://gitlab.kitware.com/cmake/cmake/issues/20306