fix version matching in FindPackage.cmake
[liba.git] / java / CMakeLists.txt
blob213761a9b0958f63ce8532038203c75a373f094f
1 include(UseJava) # https://cmake.org/cmake/help/latest/module/UseJava.html
2 set(CMAKE_SHARED_MODULE_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
4 if(WIN32)
5   set(CMAKE_SHARED_MODULE_PREFIX "")
6 endif()
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)
17   if(WIN32)
18     set(sep ";")
19   else()
20     set(sep ":")
21   endif()
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}
28   )
29   set(sep)
30 endif()
32 option(LIBA_JAVADOC "Enable/Disable ffi javadoc" 0)
34 if(LIBA_JAVADOC)
35   create_javadoc(${PROJECT_NAME} FILES ${SOURCES}
36     INSTALLPATH ${CMAKE_INSTALL_DATADIR}/javadoc
37   )
38   add_dependencies(adoc ${PROJECT_NAME}_javadoc)
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 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}
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()