Mohsin Kazmi | 2419508 | 2018-09-13 09:59:50 +0200 | [diff] [blame] | 1 | # 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 | |
| 14 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) |
| 15 | |
| 16 | project(japi) |
| 17 | |
| 18 | include(CheckCCompilerFlag) |
| 19 | |
| 20 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") |
| 21 | set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}") |
| 22 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
| 23 | set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}") |
| 24 | endif() |
| 25 | |
| 26 | check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member) |
| 27 | if (compiler_flag_no_address_of_packed_member) |
| 28 | add_definitions(-Wno-address-of-packed-member) |
| 29 | endif() |
| 30 | |
| 31 | execute_process( |
| 32 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../src |
| 33 | COMMAND scripts/version |
| 34 | OUTPUT_VARIABLE JAPI_VERSION |
| 35 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 36 | ) |
| 37 | string(REPLACE "-" ";" JAPI_LIB_VERSION ${JAPI_VERSION}) |
| 38 | list(GET JAPI_LIB_VERSION 0 JAPI_LIB_VERSION) |
| 39 | |
| 40 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 41 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) |
| 42 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 43 | |
| 44 | find_package(Threads REQUIRED) |
| 45 | |
| 46 | unset(dirlist) |
| 47 | |
| 48 | macro(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() |
| 55 | endmacro() |
| 56 | |
| 57 | list(APPEND dirlist $ENV{JAVA_HOME}) |
| 58 | subdirlist(dirlist /usr/lib/jvm) |
| 59 | subdirlist(dirlist /usr/lib64/jvm) |
| 60 | |
| 61 | unset(JAVA_HOME_SET) |
| 62 | find_path(JAVA_HOME_SET NAMES include/jni.h PATHS ${dirlist}) |
| 63 | if (NOT JAVA_HOME_SET) |
| 64 | message("JAVA_HOME is not found") |
| 65 | else() |
| 66 | set(ENV{JAVA_HOME} "${JAVA_HOME_SET}") |
| 67 | endif() |
| 68 | |
| 69 | message("JAVA_HOME: $ENV{JAVA_HOME}") |
| 70 | |
| 71 | find_package(Java 1.8 REQUIRED COMPONENTS Development) |
| 72 | get_filename_component(jvm_path ${Java_JAVAC_EXECUTABLE} DIRECTORY) |
| 73 | set (Java_INCLUDE_DIRS ${jvm_path}/../include ${jvm_path}/../include/linux) |
| 74 | |
| 75 | message("Found java headers ${Java_INCLUDE_DIRS}") |
| 76 | message("Found javac at: " ${Java_JAVAC_EXECUTABLE}) |
| 77 | add_subdirectory(java) |