1 # https://cmake.org/cmake/help/latest/module/UseJava.html
4 set(CMAKE_JNI_TARGET TRUE)
5 file(GLOB_RECURSE SOURCES src/*.java)
6 add_jar(ajar GENERATE_NATIVE_HEADERS ajar_native
7 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include
8 SOURCES ${SOURCES} OUTPUT_NAME liba
10 install_jar(ajar ${CMAKE_INSTALL_DATADIR}/java)
12 if(CMAKE_VERSION VERSION_LESS 3.11)
19 add_custom_command(TARGET ajar POST_BUILD
20 COMMAND ${Java_JAVAC_EXECUTABLE} -classpath ${sep}${CMAKE_CURRENT_SOURCE_DIR}${sep}${CMAKE_CURRENT_BINARY_DIR}
21 -d ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ajar.dir -h ${CMAKE_CURRENT_BINARY_DIR}/include
22 @${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ajar.dir/java_sources
23 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
28 option(LIBA_JAVADOC "Enable/Disable ffi javadoc" 0)
31 create_javadoc(${PROJECT_NAME} FILES ${SOURCES}
32 INSTALLPATH ${CMAKE_INSTALL_DATADIR}/javadoc
34 add_dependencies(adoc ${PROJECT_NAME}_javadoc)
38 set(CMAKE_SHARED_LIBRARY_PREFIX "")
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 SHARED ${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)