1# Copyright (c) Facebook, Inc. and its affiliates. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15cmake_minimum_required(VERSION 3.6.0) 16project(fbjni CXX) 17 18include(GNUInstallDirs) 19 20set(FBJNI_COMPILE_OPTIONS 21 -Wall 22 -std=c++14 23 -pthread 24 -fno-omit-frame-pointer 25 -fexceptions 26 -frtti 27 -ffunction-sections 28 -O3 29 -DNDEBUG 30) 31 32file(GLOB fbjni_SOURCES 33 cxx/fbjni/*.cpp 34 cxx/fbjni/detail/*.cpp 35 cxx/lyra/*.cpp 36) 37 38add_library(fbjni SHARED ${fbjni_SOURCES}) 39set_target_properties(fbjni PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) 40 41target_compile_options(fbjni PRIVATE ${FBJNI_COMPILE_OPTIONS}) 42target_compile_options(fbjni PRIVATE -DBUILDING_FBJNI) 43 44target_include_directories(fbjni BEFORE 45 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cxx> 46) 47 48if (NOT ANDROID_ABI) 49 if (NOT JAVA_HOME) 50 message(FATAL_ERROR 51 "fbjni requires JAVA_HOME to be defined for non-Android builds.") 52 endif() 53 target_include_directories(fbjni PUBLIC ${JAVA_HOME}/include) 54 if (CMAKE_SYSTEM_NAME STREQUAL Linux) 55 target_include_directories(fbjni PUBLIC ${JAVA_HOME}/include/linux) 56 endif() 57 if (CMAKE_SYSTEM_NAME STREQUAL Darwin) 58 target_include_directories(fbjni PUBLIC ${JAVA_HOME}/include/darwin) 59 endif() 60 # win32/jni_md.h typedefs jint as long, because apparently 61 # long is 32 bits on Windows. This breaks a lot of stuff. 62 # It could probably be fixed, but for now just require 63 # building with Android's jni.h on Windows, which doesn't do this. 64 # if (CMAKE_SYSTEM_NAME STREQUAL Windows) 65 # target_include_directories(fbjni PUBLIC ${JAVA_HOME}/include/win32) 66 # endif() 67 68 if(NOT FBJNI_SKIP_TESTS) 69 enable_testing() 70 add_subdirectory(test/jni) 71 72 find_library(GTEST_LIB gtest) 73 if(NOT GTEST_LIB) 74 # Download and unpack googletest at configure time 75 configure_file(googletest-CMakeLists.txt.in googletest-download/CMakeLists.txt) 76 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 77 RESULT_VARIABLE result 78 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) 79 if(result) 80 message(FATAL_ERROR "CMake step for googletest failed: ${result}") 81 endif() 82 execute_process(COMMAND ${CMAKE_COMMAND} --build . 83 RESULT_VARIABLE result 84 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) 85 if(result) 86 message(FATAL_ERROR "Build step for googletest failed: ${result}") 87 endif() 88 89 # Add googletest directly to our build. This defines 90 # the gtest and gtest_main targets. 91 add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src 92 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build 93 EXCLUDE_FROM_ALL) 94 endif() 95 endif() 96endif() 97 98if (ANDROID_ABI) 99 target_link_libraries(fbjni 100 android 101 log 102 ) 103endif() 104 105install(TARGETS fbjni EXPORT fbjniLibraryConfig 106 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 107 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 108 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) #For windows 109 110install(EXPORT fbjniLibraryConfig DESTINATION share/cmake/fbjni 111 FILE fbjniLibraryConfig.cmake) 112 113if(MSVC) 114 install(FILES $<TARGET_PDB_FILE:fbjni> DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) 115 install(TARGETS fbjni DESTINATION ${CMAKE_INSTALL_LIBDIR}) 116endif() 117