blob: 274dd0798da0a3a95e6325fe4135a9f13f35e2b0 [file] [log] [blame]
Mohsin Kazmi24195082018-09-13 09:59:50 +02001# Copyright (c) 2018 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
15
16project(japi)
17
18include(CheckCCompilerFlag)
19
20if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
21 set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
22elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
23 set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
24endif()
25
26check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member)
27if (compiler_flag_no_address_of_packed_member)
28 add_definitions(-Wno-address-of-packed-member)
29endif()
30
31execute_process(
32 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../src
33 COMMAND scripts/version
34 OUTPUT_VARIABLE JAPI_VERSION
35 OUTPUT_STRIP_TRAILING_WHITESPACE
36)
37string(REPLACE "-" ";" JAPI_LIB_VERSION ${JAPI_VERSION})
38list(GET JAPI_LIB_VERSION 0 JAPI_LIB_VERSION)
39
40set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
41set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
42set(CMAKE_INSTALL_MESSAGE NEVER)
43
44find_package(Threads REQUIRED)
45
46unset(dirlist)
47
48macro(subdirlist dirlist dirpath)
49 file(GLOB dirs RELATIVE ${dirpath} ${dirpath}/*)
50 foreach(dir ${dirs})
51 if(IS_DIRECTORY ${dirpath}/${dir})
52 list(APPEND dirlist ${dirpath}/${dir})
53 endif()
54 endforeach()
55endmacro()
56
57list(APPEND dirlist $ENV{JAVA_HOME})
58subdirlist(dirlist /usr/lib/jvm)
59subdirlist(dirlist /usr/lib64/jvm)
60
61unset(JAVA_HOME_SET)
62find_path(JAVA_HOME_SET NAMES include/jni.h PATHS ${dirlist})
63if (NOT JAVA_HOME_SET)
64 message("JAVA_HOME is not found")
65else()
66 set(ENV{JAVA_HOME} "${JAVA_HOME_SET}")
67endif()
68
69message("JAVA_HOME: $ENV{JAVA_HOME}")
70
71find_package(Java 1.8 REQUIRED COMPONENTS Development)
72get_filename_component(jvm_path ${Java_JAVAC_EXECUTABLE} DIRECTORY)
73set (Java_INCLUDE_DIRS ${jvm_path}/../include ${jvm_path}/../include/linux)
74
75message("Found java headers ${Java_INCLUDE_DIRS}")
76message("Found javac at: " ${Java_JAVAC_EXECUTABLE})
77add_subdirectory(java)