Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Open
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore ChakraCore subfolder Should it exist.
ChakraCore
ChakraCore/


# Ignore build directories.
BuildLinux/
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.2)

project(ChakraCoreSamples)

find_package(PkgConfig)

pkg_check_modules(PC_ICU_UC icu-uc)
pkg_check_modules(PC_ICU_I18N icu-i18n)

# Find Deps for OpenGL Example.
find_package(OpenGL)
pkg_check_modules(PC_GLFW glfw3)
pkg_check_modules(PC_GLEW glew)
#TODO: embed glew and glfw.

if(EXISTS "${CMAKE_SOURCE_DIR}/ChakraCore/CMakeLists.txt")
SET(CC_AUTODETECT_CPU ON CACHE BOOL "" FORCE)
SET(CC_AUTODETECT_ICU ON CACHE BOOL "" FORCE)
add_subdirectory(ChakraCore)
else()
# TODO: Detect ChakraCore when installed as a System Package.
message(FATAL_ERROR "ChakraCore not found")
endif()

if(NOT TARGET Chakra.Pal OR
NOT TARGET Chakra.Common.Core OR
NOT TARGET Chakra.Jsrt )
message(FATAL_ERROR "ChakraCore not found")
endif()


add_custom_target(CopyChakraHeaders ALL
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/ChakraCore/lib/Jsrt/ChakraCore.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/ChakraCore/lib/Jsrt/ChakraCommon.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/ChakraCore/lib/Jsrt/ChakraCommonWindows.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/ChakraCore/lib/Jsrt/ChakraDebug.h"
"${CMAKE_BINARY_DIR}/include"
)

add_subdirectory("ChakraCore Samples/Hello World/Linux_OSX")


if(PC_GLFW_FOUND AND PC_GLEW_FOUND AND OpenGL_FOUND)
message(STATUS "Building OpenGL Example.")
add_subdirectory("ChakraCore Samples/OpenGL Engine/")
endif()
67 changes: 67 additions & 0 deletions ChakraCore Samples/Hello World/Linux_OSX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

add_executable (ChakraHelloWorld sample.cpp)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LINKER_START_GROUP -Wl,--start-group)
set(LINKER_END_GROUP -Wl,--end-group)
endif()

if(CC_TARGETS_X86)
set(lib_target "-m32")
endif()

if(TARGET ChakraCore)
# common link deps
set(lib_target "${lib_target}"
-Wl,-undefined,error
${LINKER_START_GROUP}
ChakraCore
${LINKER_END_GROUP}
)
else()
#TODO: Fix Static Compile.
set(lib_target "${lib_target}"
-Wl,-undefined,error
${LINKER_START_GROUP}
Chakra.Common.Core
Chakra.Jsrt
Chakra.Pal
${LINKER_END_GROUP}
)
endif()

SET_TARGET_PROPERTIES(ChakraHelloWorld
PROPERTIES COMPILE_FLAGS "-std=c++11")

target_link_libraries (ChakraHelloWorld ${lib_target})

if(NOT CC_XCODE_PROJECT)
set(CC_LIB_EXT "so")
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_LIB_EXT "dylib")
endif()
if(TARGET ChakraCore)
add_custom_command(TARGET ChakraHelloWorld POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/ChakraCore/libChakraCore.${CC_LIB_EXT}"
"${CMAKE_BINARY_DIR}/"
)
endif()
add_custom_command(TARGET ChakraHelloWorld POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/ChakraCore Samples/Hello World/Linux_OSX/ChakraHelloWorld"
${CMAKE_BINARY_DIR}/
)
endif()

add_dependencies(ChakraHelloWorld CopyChakraHeaders)


if(PC_ICU_UC_FOUND AND PC_ICU_I18N_FOUND)
target_link_libraries(ChakraHelloWorld ${PC_ICU_UC_LIBRARIES} ${PC_ICU_I18N_LIBRARIES})
endif()

target_include_directories (ChakraHelloWorld
PUBLIC "${CMAKE_BINARY_DIR}/include")
3 changes: 3 additions & 0 deletions ChakraCore Samples/Hello World/Linux_OSX/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ int main()
// Your script; try replace hello-world with something else
const char* script = "(()=>{return \'Hello World!\';})()";

FAIL_CHECK(JsInitializeRuntime(0, nullptr));

// Create a runtime.
FAIL_CHECK(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime));

Expand Down Expand Up @@ -69,6 +71,7 @@ int main()
// Dispose runtime
FAIL_CHECK(JsSetCurrentContext(JS_INVALID_REFERENCE));
FAIL_CHECK(JsDisposeRuntime(runtime));
FAIL_CHECK(JsFinalizeRuntime());

return 0;
}
107 changes: 107 additions & 0 deletions ChakraCore Samples/OpenGL Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

add_executable (ChakraOpenGLEngine
OpenGLEngine/Canvas.cpp
OpenGLEngine/Task.cpp
OpenGLEngine/main.cpp
OpenGLEngine/ChakraCoreHost.cpp
OpenGLEngine/Shape.cpp
)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LINKER_START_GROUP -Wl,--start-group)
set(LINKER_END_GROUP -Wl,--end-group)
endif()

if(CC_TARGETS_X86)
set(lib_target "-m32")
endif()


# Link against OpenGL
target_include_directories (ChakraOpenGLEngine PUBLIC "${OPENGL_INCLUDE_DIR}")

# Link against GLEW
if(PC_GLEW_FOUND)
# This should include internationalization.
target_include_directories (ChakraOpenGLEngine PUBLIC "${PC_GLEW_INCLUDE_DIRS}" )
endif()

# Link against GLFW.
if(PC_GLFW_FOUND)
# This should include internationalization.
target_include_directories (ChakraOpenGLEngine PUBLIC "${PC_GLFW_INCLUDE_DIRS}")
endif()

# common link deps
if(TARGET ChakraCore)
#Use ChakraCore shared Library.
set(lib_target "${lib_target}"
-Wl,-undefined,error
${LINKER_START_GROUP}
ChakraCore
${LINKER_END_GROUP}
${PC_GLEW_LDFLAGS}
${PC_GLFW_LDFLAGS}
${OPENGL_gl_LIBRARY}
${PC_ICU_UC_LIBRARIES}
${PC_ICU_I18N_LIBRARIES}
)
else()
#Use ChakraCore Static Library.
set(lib_target "${lib_target}"
-Wl,-undefined,error
${LINKER_START_GROUP}
Chakra.Common.Core
Chakra.Jsrt
Chakra.Pal
${LINKER_END_GROUP}
${PC_GLEW_LDFLAGS}
${PC_GLFW_LDFLAGS}
${OPENGL_gl_LIBRARY}
${LINKER_END_GROUP}
)
endif()



target_link_libraries(ChakraOpenGLEngine ${lib_target} )

#use C++11
SET_TARGET_PROPERTIES(ChakraOpenGLEngine PROPERTIES COMPILE_FLAGS
"-std=c++11 -Wno-pragma-once-outside-header"
)

add_dependencies(ChakraOpenGLEngine CopyChakraHeaders)
target_include_directories (ChakraOpenGLEngine PUBLIC "${CMAKE_BINARY_DIR}/include")



if(NOT CC_XCODE_PROJECT)
set(CC_LIB_EXT "so")
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_LIB_EXT "dylib")
endif()
if(TARGET ChakraCore)
add_custom_command(TARGET ChakraOpenGLEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/ChakraCore/libChakraCore.${CC_LIB_EXT}"
"${CMAKE_BINARY_DIR}/"
)
endif()
# Copy ChakraOpenGLEngine to Binary Directory.
add_custom_command(TARGET ChakraOpenGLEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/ChakraCore Samples/OpenGL Engine/ChakraOpenGLEngine"
"${CMAKE_BINARY_DIR}/"
)
# Copy the Example Javascript file.
add_custom_command(TARGET ChakraOpenGLEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/OpenGLEngine/app.js"
"${CMAKE_BINARY_DIR}/"
)

endif()

4 changes: 3 additions & 1 deletion ChakraCore Samples/OpenGL Engine/OpenGLEngine/Canvas.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "Canvas.h"

Canvas::Canvas()
Expand Down Expand Up @@ -75,4 +77,4 @@ void Canvas::render()
Canvas::~Canvas()
{
glfwTerminate();
}
}
Loading