1 include(UseJava) # https://cmake.org/cmake/help/latest/module/UseJava.html
2 set(CMAKE_SHARED_MODULE_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
5 set(CMAKE_SHARED_MODULE_PREFIX "")
8 set(CMAKE_JNI_TARGET TRUE)
9 file(GLOB_RECURSE SOURCES src/*.java)
10 add_jar(ajar GENERATE_NATIVE_HEADERS ajar_native
11 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include
12 SOURCES ${SOURCES} OUTPUT_NAME liba
14 install_jar(ajar ${CMAKE_INSTALL_DATADIR}/java)
16 if(CMAKE_VERSION VERSION_LESS 3.11)
23 add_custom_command(TARGET ajar POST_BUILD
24 COMMAND ${Java_JAVAC_EXECUTABLE} -classpath ${sep}${CMAKE_CURRENT_SOURCE_DIR}${sep}${CMAKE_CURRENT_BINARY_DIR}
25 -d ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ajar.dir -h ${CMAKE_CURRENT_BINARY_DIR}/include
26 @${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ajar.dir/java_sources
27 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
32 option(LIBA_JAVADOC "Enable/Disable ffi javadoc" 0)
35 create_javadoc(${PROJECT_NAME} FILES ${SOURCES}
36 INSTALLPATH ${CMAKE_INSTALL_DATADIR}/javadoc
38 add_dependencies(adoc ${PROJECT_NAME}_javadoc)
41 if(LIBA_FLOAT EQUAL 8)
42 set(OBJECTS $<TARGET_OBJECTS:a>)
44 get_property(OBJECTS TARGET a PROPERTY SOURCES)
48 file_scaner(SOURCES RECURSE src EXT c h cc hh cpp hpp)
50 file_scaner(SOURCES RECURSE src EXT c h)
53 add_library(ajni MODULE ${OBJECTS} ${SOURCES})
54 set_target_properties(ajni PROPERTIES DEFINE_SYMBOL A_EXPORTS OUTPUT_NAME a)
55 add_library_properties(ajni PRIVATE alib)
56 set_library_options(ajni)
58 if(CMAKE_VERSION VERSION_LESS 3.11)
59 target_include_directories(ajni PRIVATE
60 ${CMAKE_CURRENT_BINARY_DIR}/include ${JNI_INCLUDE_DIRS}
63 target_link_libraries(ajni PRIVATE ajar_native)
66 if(NOT LIBA_FLOAT EQUAL 8)
67 target_compile_definitions(ajni PRIVATE A_SIZE_FLOAT=8)
71 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/jni
72 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/jni
73 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
76 execute_process(COMMAND ${Java_JAVA_EXECUTABLE} -version
77 OUTPUT_VARIABLE version ERROR_VARIABLE version
79 string(FIND "${version}" "64-Bit" index)
81 if(${index} GREATER -1)
82 set(JAVA_SIZEOF_VOID_P 8) # 64
84 set(JAVA_SIZEOF_VOID_P 4) # 32
87 if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/test/CMakeLists.txt AND
88 CMAKE_SIZEOF_VOID_P EQUAL JAVA_SIZEOF_VOID_P AND BUILD_TESTING)
89 get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
91 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
92 set(WORKING_DIRECTORY $<TARGET_FILE_DIR:ajni>)
93 elseif(IS_MULTI_CONFIG)
94 set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
96 set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
99 file(GLOB_RECURSE SOURCES src/*.java)
100 add_subdirectory(test)