Skip to content

Commit

Permalink
[TIMOB-24283] Add Windows support (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and infosia committed Feb 3, 2017
1 parent 7bc8baa commit b19b25f
Show file tree
Hide file tree
Showing 19 changed files with 1,092 additions and 0 deletions.
119 changes: 119 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Titanium Windows Native Module - ti.paint
#
# Copyright (c) 2017 Axway All Rights Reserved.
# Licensed under the terms of the Apache Public License.
# Please see the LICENSE included with this distribution for details.

cmake_minimum_required(VERSION 3.0.0)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows10")
set(PLATFORM win10)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsPhone")
set(PLATFORM phone)
add_definitions("-DPHONE")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM store)
else()
message(FATAL_ERROR "This app supports Store / Phone only.")
endif()

project(TiPaint)

set(TiPaint_VERSION 0.1.0)

set(WINDOWS_SOURCE_DIR "C:/ProgramData/Titanium/mobilesdk/win32/6.1.0.v20170123100346/windows")

SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)

option(TiPaint_DISABLE_TESTS "Disable compiling the tests" OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

get_filename_component(APPCELERATOR_CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ABSOLUTE)
list(INSERT CMAKE_MODULE_PATH 0 ${APPCELERATOR_CMAKE_MODULE_PATH})

find_package(HAL REQUIRED)
find_package(TitaniumKit REQUIRED)
find_package(LayoutEngine REQUIRED)
find_package(TitaniumWindows_UI REQUIRED)

enable_testing()

set(SOURCE_TiPaint
include/TiPaint.hpp
src/TiPaint.cpp
include/TiPaintView.hpp
src/TiPaintView.cpp
)

source_group(TiPaint FILES ${SOURCE_TiPaint})

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

add_library(TiPaint SHARED
${SOURCE_TiPaint}
)

include(GenerateExportHeader)
generate_export_header(TiPaint)
target_compile_definitions(TiPaint PRIVATE TiPaint_EXPORTS)

target_include_directories(TiPaint PUBLIC
${PROJECT_SOURCE_DIR}/include
$<TARGET_PROPERTY:HAL,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:TitaniumKit,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:LayoutEngine,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:TitaniumWindows_UI,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(TiPaint
HAL
TitaniumKit
LayoutEngine
TitaniumWindows_UI
)

set_target_properties(TiPaint PROPERTIES VS_WINRT_COMPONENT TRUE)

set_property(TARGET TiPaint APPEND_STRING PROPERTY LINK_FLAGS_DEBUG "/OPT:NOREF /OPT:NOICF")

if (NOT TiPaint_DISABLE_TESTS)
add_subdirectory(test)
endif()

set_property(TARGET TiPaint PROPERTY VERSION ${TiPaint_VERSION})
set_property(TARGET TiPaint PROPERTY SOVERSION 0)
set_property(TARGET TiPaint PROPERTY INTERFACE_TiPaint_MAJOR_VERSION 0)
set_property(TARGET TiPaint APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING TiPaint_MAJOR_VERSION
)

install(TARGETS TiPaint EXPORT TiPaint_Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

export(EXPORT TiPaint_Targets
FILE "${CMAKE_BINARY_DIR}/TiPaint_Targets.cmake"
)

configure_file(cmake/TiPaint_Config.cmake
"${CMAKE_BINARY_DIR}/TiPaint_Config.cmake"
COPYONLY
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/TiPaint_ConfigVersion.cmake"
VERSION ${TiPaint_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(PACKAGE TiPaint)
88 changes: 88 additions & 0 deletions windows/cmake/FindHAL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# FindHAL
# Author: Chris Williams
#
# Copyright (c) 2017 Axway All Rights Reserved.
# Licensed under the terms of the Apache Public License.
# Please see the LICENSE included with this distribution for details.

# Author: Chris Williams
# Created: 2014.12.02


# Generated by CMake 3.1.3

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget HAL)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)

if (${CMAKE_SYSTEM_VERSION} MATCHES "^10.0")
set(PLATFORM win10)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsPhone")
set(PLATFORM phone)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM store)
else()
message(FATAL_ERROR "This app supports Store / Phone only.")
endif()

set(HAL_ARCH "x86")
if(CMAKE_GENERATOR MATCHES "^Visual Studio .+ ARM$")
set(HAL_ARCH "arm")
endif()

# Taken and slightly modified from build's HAL_Targets.cmake file
# INTERFACE_INCLUDE_DIRECTORIES is modified to point to our pre-packaged include dir for module

# Create imported target HAL
add_library(HAL SHARED IMPORTED)

set_target_properties(HAL PROPERTIES
COMPATIBLE_INTERFACE_STRING "HAL_MAJOR_VERSION"
INTERFACE_INCLUDE_DIRECTORIES "${WINDOWS_SOURCE_DIR}/lib/HAL/include"
INTERFACE_HAL_MAJOR_VERSION "0"
)

set_target_properties(HAL PROPERTIES
IMPORTED_IMPLIB "${WINDOWS_SOURCE_DIR}/lib/HAL/${PLATFORM}/${HAL_ARCH}/HAL.lib"
IMPORTED_LOCATION "${WINDOWS_SOURCE_DIR}/lib/HAL/${PLATFORM}/${HAL_ARCH}/HAL.dll"
)

# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
61 changes: 61 additions & 0 deletions windows/cmake/FindJavascriptCore.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# HAL
#
# Copyright (c) 2017 Axway All Rights Reserved.
# Licensed under the terms of the Apache Public License.
# Please see the LICENSE included with this distribution for details.

# Author: Matt Langston
# Created: 2014.09.03
#
# Try to find JavaScriptCore. Once done this will define:
#
# JavaScriptCore_FOUND - system has JavaScriptCore
# JavaScriptCore_INCLUDE_DIRS - the include directory
# JavaScriptCore_LIBRARY_DIR - the directory containing the library
# JavaScriptCore_LIBRARIES - link these to use JavaScriptCore

find_package(PkgConfig)

pkg_check_modules(PC_JavaScriptCore QUIET JavaScriptCore)

find_path(JavaScriptCore_INCLUDE_DIRS
NAMES JavaScriptCore/JavaScript.h
HINTS ${PC_JavaScriptCore_INCLUDE_DIRS} ${PC_JavaScriptCore_INCLUDEDIR}
PATHS ENV JavaScriptCore_HOME
PATH_SUFFIXES includes
)

set(JavaScriptCore_ARCH "x86")
if(CMAKE_GENERATOR MATCHES "^Visual Studio .+ ARM$")
set(JavaScriptCore_ARCH "arm")
endif()

find_library(JavaScriptCore_LIBRARIES
NAMES JavaScriptCore JavaScriptCore-Debug JavaScriptCore-Release
HINTS ${PC_JavaScriptCore_LIBRARY_DIRS} ${PC_JavaScriptCore_LIBDIR}
PATHS ENV JavaScriptCore_HOME
PATH_SUFFIXES ${JavaScriptCore_ARCH}
)

if(NOT JavaScriptCore_LIBRARIES MATCHES ".+-NOTFOUND")
get_filename_component(JavaScriptCore_LIBRARY_DIR ${JavaScriptCore_LIBRARIES} DIRECTORY)

# If we found the JavaScriptCore library and we're using a Visual
# Studio generator and we're targeting either WindowsStore or
# WindowsPhone, then allow Visual Studio to use both the
# JavaScriptCore-Debug.lib and JavaScriptCore-Release.lib if they
# exist.
if(CMAKE_GENERATOR MATCHES "^Visual Studio .+" AND CMAKE_SYSTEM_NAME MATCHES "^Windows(Store|Phone)")
string(REGEX REPLACE "-(Debug|Release)" "-$(Configuration)" JavaScriptCore_LIBRARIES ${JavaScriptCore_LIBRARIES})
endif()

endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(JavaScriptCore DEFAULT_MSG JavaScriptCore_INCLUDE_DIRS JavaScriptCore_LIBRARIES)

# message(STATUS "MDL: CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}")
# message(STATUS "MDL: JAVASCRIPTCORE_FOUND = ${JAVASCRIPTCORE_FOUND}")
# message(STATUS "MDL: JavaScriptCore_INCLUDE_DIRS = ${JavaScriptCore_INCLUDE_DIRS}")
# message(STATUS "MDL: JavaScriptCore_LIBRARY_DIR = ${JavaScriptCore_LIBRARY_DIR}")
# message(STATUS "MDL: JavaScriptCore_LIBRARIES = ${JavaScriptCore_LIBRARIES}")
85 changes: 85 additions & 0 deletions windows/cmake/FindLayoutEngine.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# FindLayoutEngine
# Author: Chris Williams
#
# Copyright (c) 2017 Axway All Rights Reserved.
# Licensed under the terms of the Apache Public License.
# Please see the LICENSE included with this distribution for details.

# Author: Chris Williams
# Created: 2014.12.02

# Generated by CMake 3.1.3

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget LayoutEngine)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)


if (${CMAKE_SYSTEM_VERSION} MATCHES "^10.0")
set(PLATFORM win10)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsPhone")
set(PLATFORM phone)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM store)
else()
message(FATAL_ERROR "This app supports Store / Phone only.")
endif()

set(LayoutEngine_ARCH "x86")
if(CMAKE_GENERATOR MATCHES "^Visual Studio .+ ARM$")
set(LayoutEngine_ARCH "arm")
endif()

# Taken and slightly modified from build's LayoutEngine_Targets.cmake file
# INTERFACE_INCLUDE_DIRECTORIES is modified to point to our pre-packaged include dir for module

# Create imported target LayoutEngine
add_library(LayoutEngine SHARED IMPORTED)

set_target_properties(LayoutEngine PROPERTIES
COMPATIBLE_INTERFACE_STRING "LayoutEngine_MAJOR_VERSION"
INTERFACE_INCLUDE_DIRECTORIES "${WINDOWS_SOURCE_DIR}/lib/LayoutEngine/include;$<TARGET_PROPERTY:HAL,INTERFACE_INCLUDE_DIRECTORIES>"
INTERFACE_LINK_LIBRARIES "HAL"
INTERFACE_LayoutEngine_MAJOR_VERSION "0"
)
set_target_properties(LayoutEngine PROPERTIES
IMPORTED_IMPLIB "${WINDOWS_SOURCE_DIR}/lib/LayoutEngine/${PLATFORM}/${LayoutEngine_ARCH}/LayoutEngine.lib"
IMPORTED_LOCATION "${WINDOWS_SOURCE_DIR}/lib/LayoutEngine/${PLATFORM}/${LayoutEngine_ARCH}/LayoutEngine.dll"
)

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
Loading

0 comments on commit b19b25f

Please sign in to comment.