GlobJniFiles.cmake

# GLOB_RECURSE all the generated .cpp and .java files, and write a file which sets variables 
# named jniCppFiles and jniJavaFiles
#     ${CPP_PATH}   :  path to the folder containing the generated .cpp files
#     ${JAVA_PATH}  :  path to the folder containing the generated .java files
#     ${OUPUT_PATH} :  path to file to create which sets the jniCppFiles and jniJavaFiles variables

set(tempPath ${CMAKE_CURRENT_BINARY_DIR}/jniFiles.cmake)
file(WRITE ${tempPath} "")

file(GLOB_RECURSE cppSourceFiles RELATIVE ${CPP_PATH} ${CPP_PATH}/*.cpp)
file(APPEND ${tempPath} "set(jniCppFiles\n")
foreach(f ${cppSourceFiles})
    file(APPEND ${tempPath} "    ${f}\n")
endforeach()
file(APPEND ${tempPath} ")\n")

file(GLOB_RECURSE javaSourceFiles RELATIVE ${JAVA_PATH} ${JAVA_PATH}/*.java)
file(APPEND ${tempPath} "set(jniJavaFiles\n")
foreach(f ${javaSourceFiles})
    file(APPEND ${tempPath} "    ${f}\n")
endforeach()
file(APPEND ${tempPath} ")\n")

execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tempPath} ${OUPUT_PATH})