improve a_version_parse and implement a_version_tostr
[liba.git] / java / CMakeLists.txt
blobb35b4737af88838ff9f5e70b6fe87fe928fa595e
1 # https://cmake.org/cmake/help/latest/module/UseJava.html
2 include(UseJava)
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)
13   if(WIN32)
14     set(sep ";")
15   else()
16     set(sep ":")
17   endif()
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}
24   )
25   set(sep)
26 endif()
28 option(LIBA_JAVADOC "Enable/Disable ffi javadoc" 0)
30 if(LIBA_JAVADOC)
31   create_javadoc(${PROJECT_NAME} FILES ${SOURCES}
32     INSTALLPATH ${CMAKE_INSTALL_DATADIR}/javadoc
33   )
34   add_dependencies(adoc ${PROJECT_NAME}_javadoc)
35 endif()
37 if(WIN32)
38   set(CMAKE_SHARED_LIBRARY_PREFIX "")
39 endif()
41 if(LIBA_FLOAT EQUAL 8)
42   set(OBJECTS $<TARGET_OBJECTS:a>)
43 else()
44   get_property(OBJECTS TARGET a PROPERTY SOURCES)
45 endif()
47 if(LIBA_CXX)
48   file_scaner(SOURCES RECURSE src EXT c h cc hh cpp hpp)
49 else()
50   file_scaner(SOURCES RECURSE src EXT c h)
51 endif()
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}
61   )
62 else()
63   target_link_libraries(ajni PRIVATE ajar_native)
64 endif()
66 if(NOT LIBA_FLOAT EQUAL 8)
67   target_compile_definitions(ajni PRIVATE A_SIZE_FLOAT=8)
68 endif()
70 install(TARGETS ajni
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
83 else()
84   set(JAVA_SIZEOF_VOID_P 4) # 32
85 endif()
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>)
95   else()
96     set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
97   endif()
99   file(GLOB_RECURSE SOURCES src/*.java)
100   add_subdirectory(test)
101 endif()