[CMake] REGEX REPLACE help

Andreas Schneider asn at cryptomilk.org
Mon Mar 18 13:57:28 EDT 2013


Hi,

I'm trying to improve the FindJNI.cmake module. However I'm totally 
incompatible with regex. I think my brain is simply not made for it.

I'm trying to get the correct path from java itself so find the header and 
library files. However this code will simply not work at all. I'm trying since 
hours...

# openjdk
find_program(JAVA_EXE java)
if (JAVA_EXE)
    execute_process(
        COMMAND ${JAVA_EXE} -XshowSettings:properties
        OUTPUT_QUIET
        ERROR_VARIABLE __JAVA_SETTINGS
        ERROR_STRIP_TRAILING_WHITESPACE
    )

    string(REGEX REPLACE "^ *java.home = (.+)/jre$" "\\1" _JAVA_LIBRARY_PATH 
"${__JAVA_SETTINGS}")
    message(STATUS "_JAVA_LIBRARY_PATH=${_JAVA_LIBRARY_PATH}")
endif()

This is the output of ${JAVA_EXE} -XshowSettings:properties:

Property settings:
    awt.toolkit = sun.awt.X11.XToolkit
    file.encoding = UTF-8
    file.encoding.pkg = sun.io
    file.separator = /
    java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
    java.awt.printerjob = sun.print.PSPrinterJob
    java.class.path = .
    java.class.version = 51.0
    java.endorsed.dirs = /usr/lib64/jvm/java-1.7.0-
openjdk-1.7.0/jre/lib/endorsed
    java.ext.dirs = /usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/jre/lib/ext
        /usr/java/packages/lib/ext
    java.home = /usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/jre
    java.io.tmpdir = /tmp
    java.library.path = /usr/java/packages/lib/amd64
        /usr/lib64
        /lib64
        /lib
        /usr/lib
    java.runtime.name = OpenJDK Runtime Environment



Thanks for the help.


	-- andreas


-- 
Andreas Schneider                   GPG-ID: F33E3FC6
www.cryptomilk.org                asn at cryptomilk.org



More information about the CMake mailing list