Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

CMake for building the support library #248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
cmake_minimum_required(VERSION 3.6.0)

project(Djinni)

include(GNUInstallDirs)

set(SRC_SHARED
"support-lib/include/djinni/djinni_common.hpp"
"support-lib/include/djinni/proxy_cache_interface.hpp"
"support-lib/src/proxy_cache_impl.hpp"
)
set(SRC_JNI
"support-lib/include/djinni/jni/djinni_support.hpp"
"support-lib/include/djinni/jni/Marshal.hpp"
"support-lib/src/jni/djinni_support.cpp"
)
set(SRC_OBJC
"support-lib/include/djinni/objc/DJICppWrapperCache+Private.h"
"support-lib/include/djinni/objc/DJIError.h"
"support-lib/include/djinni/objc/DJIMarshal+Private.h"
"support-lib/include/djinni/objc/DJIObjcWrapperCache+Private.h"
"support-lib/src/objc/DJIError.mm"
"support-lib/src/objc/DJIProxyCaches.mm"
)

option(DJINNI_STATIC_LIB "Build Djinni as a static library instead of dynamic (the default)." off)
if(DJINNI_STATIC_LIB)
add_library(djinni STATIC ${SRC_SHARED})
else()
add_library(djinni SHARED ${SRC_SHARED})
endif()
source_group("" FILES ${SRC_SHARED})

target_include_directories(djinni PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/support-lib/include>")
set_target_properties(djinni PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED true
CXX_EXTENSIONS false
)

# Objective-C support
option(DJINNI_WITH_OBJC "Include the Objective-C support code in Djinni." off)
if(DJINNI_WITH_OBJC)
target_sources(djinni PRIVATE ${SRC_OBJC})
source_group("objc" FILES ${SRC_OBJC})
target_compile_options(djinni PUBLIC "-fobjc-arc")
endif()

# JNI support
option(DJINNI_WITH_JNI "Include the JNI support code in Djinni." off)
if(DJINNI_WITH_JNI)
if(NOT DJINNI_STATIC_LIB)
list(APPEND SRC_JNI "support-lib/src/jni/djinni_main.cpp")
endif()
target_sources(djinni PRIVATE ${SRC_JNI})
source_group("jni" FILES ${SRC_JNI})
# Do not use the host's jni.h on Android as it is provided automatically by the NDK
if(NOT ANDROID)
find_package(JNI REQUIRED QUIET)
target_include_directories(djinni
PUBLIC
"${JNI_INCLUDE_DIRS}"
)
endif()
# Exceptions and RTTI are disabled in the NDK by default
if(ANDROID)
target_compile_options(djinni PRIVATE "-fexceptions" "-frtti")
endif()
endif()

if(NOT (DJINNI_WITH_OBJC OR DJINNI_WITH_JNI))
message(FATAL_ERROR "At least one of DJINNI_WITH_OBJC or DJINNI_WITH_JNI must be enabled.")
endif()

# Apple framework
option(DJINNI_FRAMEWORK "If enabled the Objective-C binary of Djinni is built as djinni.framework otherwise as djinni.dylib on Apple systems." off)
if(APPLE AND DJINNI_FRAMEWORK)
set_target_properties(djinni PROPERTIES
FRAMEWORK true
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.dropbox.djinni"
)
endif()

# Installation
install(TARGETS djinni
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

if(APPLE AND DJINNI_FRAMEWORK)
install(DIRECTORY "support-lib/include/djinni/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/djinni.framework/Header"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp")
else()
target_include_directories(djinni PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
install(DIRECTORY "support-lib/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp")
endif()

# Store path to the "run" executable so it can be passed as argument to add_custom_command() scripts
set(DJINNI_RUN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/run" CACHE FILEPATH "Path to the Djinni generator executable.")
2 changes: 1 addition & 1 deletion example/generated-src/jni/NativeItemList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file generated by Djinni from example.djinni

#include "NativeItemList.hpp" // my header
#include "Marshal.hpp"
#include "djinni/jni/Marshal.hpp"

namespace djinni_generated {

Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/jni/NativeItemList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"
#include "item_list.hpp"

namespace djinni_generated {
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/jni/NativeSortItems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"
#include "sort_items.hpp"

namespace djinni_generated {
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/jni/NativeSortOrder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"
#include "sort_order.hpp"

namespace djinni_generated {
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/jni/NativeTextboxListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"
#include "textbox_listener.hpp"

namespace djinni_generated {
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/objc/TXSItemList+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file generated by Djinni from example.djinni

#import "TXSItemList+Private.h"
#import "DJIMarshal+Private.h"
#import "djinni/objc/DJIMarshal+Private.h"
#include <cassert>

namespace djinni_generated {
Expand Down
4 changes: 2 additions & 2 deletions example/generated-src/objc/TXSSortItems+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#import "TXSSortItems+Private.h"
#import "TXSSortItems.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#import "TXSItemList+Private.h"
#import "TXSSortOrder+Private.h"
#import "TXSTextboxListener+Private.h"
#import "djinni/objc/DJICppWrapperCache+Private.h"
#import "djinni/objc/DJIError.h"
#include <exception>
#include <stdexcept>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/objc/TXSSortOrder+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// This file generated by Djinni from example.djinni

#include "sort_order.hpp"
#import "DJIMarshal+Private.h"
#import "djinni/objc/DJIMarshal+Private.h"

2 changes: 1 addition & 1 deletion example/generated-src/objc/TXSTextboxListener+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#import "TXSTextboxListener+Private.h"
#import "TXSTextboxListener.h"
#import "DJIObjcWrapperCache+Private.h"
#import "TXSItemList+Private.h"
#import "djinni/objc/DJIObjcWrapperCache+Private.h"
#include <stdexcept>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
Expand Down
2 changes: 1 addition & 1 deletion example/libtextsort.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"ldflags": [ "-llog", "-Wl,--build-id,--gc-sections,--exclude-libs,ALL" ],
"sources": [
"../support-lib/jni/djinni_main.cpp",
"../support-lib/src/jni/djinni_main.cpp",
"<!@(python glob.py generated-src/jni '*.cpp' '*.hpp')",
"<!@(python glob.py generated-src/cpp '*.cpp' '*.hpp')",
"<!@(python glob.py handwritten-src/cpp '*.cpp' '*.hpp')",
Expand Down
4 changes: 2 additions & 2 deletions example/objc/TextSort.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../support-lib/objc $(SRCROOT)/../generated-src/objc";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../support-lib/include/ $(SRCROOT)/../generated-src/objc";
};
name = Debug;
};
Expand Down Expand Up @@ -287,7 +287,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../support-lib/objc $(SRCROOT)/../generated-src/objc";
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../support-lib/include/ $(SRCROOT)/../generated-src/objc";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Main {
var jniIncludeCppPrefix: String = ""
var jniFileIdentStyleOptional: Option[IdentConverter] = None
var jniBaseLibClassIdentStyleOptional: Option[IdentConverter] = None
var jniBaseLibIncludePrefix: String = ""
var jniBaseLibIncludePrefix: String = "djinni/jni/"
var cppHeaderOutFolderOptional: Option[File] = None
var cppExt: String = "cpp"
var cppHeaderExt: String = "hpp"
Expand All @@ -72,7 +72,7 @@ object Main {
var objcppIncludeObjcPrefixOptional: Option[String] = None
var objcFileIdentStyleOptional: Option[IdentConverter] = None
var objcppNamespace: String = "djinni_generated"
var objcBaseLibIncludePrefix: String = ""
var objcBaseLibIncludePrefix: String = "djinni/objc/"
var inFileListPath: Option[File] = None
var outFileListPath: Option[File] = None
var skipGeneration: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"
#include <cassert>
#include <chrono>
#include <cstdint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <string>
#include <unordered_map>

#include "../proxy_cache_interface.hpp"
#include "../djinni_common.hpp"
#include "djinni/proxy_cache_interface.hpp"
#include "djinni/djinni_common.hpp"
#include <jni.h>

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import <Foundation/Foundation.h>
#include <memory>

#include "../proxy_cache_interface.hpp"
#include "djinni/proxy_cache_interface.hpp"

namespace djinni {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import <Foundation/Foundation.h>
#include <memory>

#include "../proxy_cache_interface.hpp"
#include "djinni/proxy_cache_interface.hpp"

namespace djinni {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// This provides a minimal JNI_OnLoad and JNI_OnUnload implementation - include it if your
// app doesn't use JNI except through Djinni.

#include "djinni_support.hpp"
#include "djinni/jni/djinni_support.hpp"

// Called when library is loaded by the first class which uses it.
CJNIEXPORT jint JNICALL JNI_OnLoad(JavaVM * jvm, void * /*reserved*/) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//

#include "../djinni_common.hpp"
#include "djinni_support.hpp"
#include "djinni/djinni_common.hpp"
#include "djinni/jni/djinni_support.hpp"
#include "../proxy_cache_impl.hpp"
#include <cassert>
#include <cstdlib>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

#include <Foundation/Foundation.h>
#include "DJIError.h"
#include "djinni/objc/DJIError.h"
#include <exception>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

#include "../proxy_cache_impl.hpp"
#include "DJIObjcWrapperCache+Private.h"
#include "DJICppWrapperCache+Private.h"
#include "djinni/objc/DJIObjcWrapperCache+Private.h"
#include "djinni/objc/DJICppWrapperCache+Private.h"

namespace djinni {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include "proxy_cache_interface.hpp"
#include "djinni/proxy_cache_interface.hpp"
#include <functional>
#include <mutex>
#include <unordered_map>
Expand Down
36 changes: 20 additions & 16 deletions support-lib/support_lib.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
"target_name": "djinni_jni",
"type": "static_library",
"sources": [
"djinni_common.hpp",
"jni/djinni_support.cpp",
"jni/djinni_support.hpp",
"jni/Marshal.hpp",
"include/djinni/djinni_common.hpp",
"include/djinni/jni/djinni_support.hpp",
"include/djinni/jni/Marshal.hpp",
"src/jni/djinni_support.cpp",
],
"include_dirs": [
"jni",
"include",
"src",
],
"direct_dependent_settings": {
"include_dirs": [
"jni",
"include",
"src",
],
},
},
Expand All @@ -25,21 +27,23 @@
"CLANG_ENABLE_OBJC_ARC": "YES",
},
"sources": [
"objc/DJICppWrapperCache+Private.h",
"objc/DJIError.h",
"objc/DJIError.mm",
"objc/DJIMarshal+Private.h",
"objc/DJIObjcWrapperCache+Private.h",
"objc/DJIProxyCaches.mm",
"proxy_cache_impl.hpp",
"proxy_cache_interface.hpp",
"include/djinni/objc/DJICppWrapperCache+Private.h",
"include/djinni/objc/DJIError.h",
"include/djinni/objc/DJIMarshal+Private.h",
"include/djinni/objc/DJIObjcWrapperCache+Private.h",
"include/djinni/proxy_cache_interface.hpp",
"src/objc/DJIProxyCaches.mm",
"src/objc/DJIError.mm",
"src/proxy_cache_impl.hpp",
],
"include_dirs": [
"objc",
"include",
"src",
],
"direct_dependent_settings": {
"include_dirs": [
"objc",
"include",
"src",
],
},
},
Expand Down
Loading