javac++cmakeswig

cmake + useSWIG + Java: missing Java package name


I am trying to SWIG a simple C++ module, specifying as a target the Java language. Everything goes fine except that the output Java sources don't have the package name at the beginning of the file.


swig_add_library(myLIbrary
    TYPE SHARED
    LANGUAGE java
    OUTPUT_DIR ./generated
    OUTFILE_DIR ./generated/Wrapper

    SOURCES ./mainswig.i ${SRC}
)

I know that this is possible because I was able to do so with SWIG in the command line by passing -package com.myfoo.bar.baz.

But I can't find the proper option to pass to SWIG through CMake. (I'm using Cmake 3.16 and SWIG 4)

Has anyone had the same issue?


Solution

  • I have found a solution. Just add the following after the swig_add_library:

    
    set_property(TARGET myLibrary PROPERTY SWIG_COMPILE_OPTIONS -package com.foo.bar.baz)