Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake Fixes #2084

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07b4982
CMake: Add prefix CC_BUILD_ to SHARED_LIBRARY and STATIC_LIBRARY vari…
kphillisjr Nov 10, 2016
ae80791
Linux: Add Script to generate Eclips Projects
kphillisjr Nov 11, 2016
330f4b0
CMake: properly use options for static library and shared library.
kphillisjr Nov 15, 2016
01f649d
cmake: Use options to handle Link Time Optimization.
kphillisjr Nov 15, 2016
9565ff6
cmake: Use CC_ENABLE_JIT to toggle the JIT support
kphillisjr Nov 15, 2016
78795f4
cmake: Copy ChakraCore headers to binary build path.
kphillisjr Nov 15, 2016
4f1d1b4
cmake: Add CC_AUTODETECT_CPU option.
kphillisjr Nov 15, 2016
017ac72
cmake: add CC_AUTODETECT_ICU option.
kphillisjr Nov 17, 2016
ebe108d
cmake: Fix copy of headers after embedding cmake.
kphillisjr Nov 17, 2016
ed116dd
cmake: Hide linker dependencies of ChakraCore
kphillisjr Nov 17, 2016
ade0a91
Merge remote-tracking branch 'upstream/master' into cmake_embed_v1
kphillisjr Nov 17, 2016
147c317
Jsrt: Move static library functious out of JsrtHelper.cpp.
kphillisjr Nov 23, 2016
42fba83
Jsrt: Fix shared library support for XPLAT.
kphillisjr Nov 23, 2016
5c4713f
Merge remote-tracking branch 'upstream/master' into cmake_embed_v3
kphillisjr Nov 23, 2016
06d6d31
Jsrt: Add new API calls.
kphillisjr Nov 23, 2016
8f6084e
jsrt: Fix windows compile.
kphillisjr Nov 23, 2016
e114760
cmake: fix formatting errors.
kphillisjr Nov 23, 2016
0e5f133
jsrt: Fix whitespace in JsrtInitialize.cpp
kphillisjr Nov 23, 2016
5ab34b4
jsrt: fix static build errors.
kphillisjr Nov 23, 2016
ca480b6
xplat: fix whitespace errors.
kphillisjr Nov 23, 2016
e1dd3ef
tests: fix detection of static builds.
kphillisjr Nov 23, 2016
b44f5e6
Merge branch 'master' into cmake_embed_v3
kphillisjr Nov 26, 2016
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ install_manifest.txt
# VS Code
.vscode/

# Eclipse
.metadata/
RemoteSystemsTempFiles/

# additional *nix generated files
*.a
*.gch
Expand All @@ -92,3 +96,4 @@ pal/src/config.h
deps/

.DS_Store

72 changes: 48 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
cmake_minimum_required(VERSION 3.2)
project (CHAKRACORE)

# Keep CMake from caching static/shared library
# option. Otherwise, CMake fails to update cached
# references
if(SHARED_LIBRARY_SH)
unset(SHARED_LIBRARY_SH CACHE)
unset(STATIC_LIBRARY_SH CACHE)
unset(STATIC_LIBRARY CACHE)
set(SHARED_LIBRARY 1)
endif()

if(STATIC_LIBRARY_SH)
unset(SHARED_LIBRARY_SH CACHE)
unset(STATIC_LIBRARY_SH CACHE)
unset(SHARED_LIBRARY CACHE)
set(STATIC_LIBRARY 1)
option(CC_BUILD_STATIC_LIBRARY "Enable Building ChakraCore as a Static Library")
option(CC_BUILD_SHARED_LIBRARY "Enable Building ChakraCore as a Shared Library" ON)
option(CC_ENABLE_FULL_LTO "Enable Full Link Time Optimization (CLANG 3.9+)")
option(CC_ENABLE_THIN_LTO "Enable Thin Link Time Optimization (CLANG 3.9+)")
option(CC_ENABLE_JIT "Enable JIT support" ON)
option(CC_AUTODETECT_CPU "Autodetect Target CPU")
option(CC_AUTODETECT_ICU "Autodetect ICU (International Components for Unicode) library")

if(CC_AUTODETECT_CPU)
if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64|amd64|AMD64")
set(CC_TARGETS_AMD64 1)
message(STATUS "ChakraCore: Building 64-bit x86 code (AMD64)")
elseif( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i[3-6]86.*|x86.*")
set(CC_TARGETS_X86 1)
set(CMAKE_SYSTEM_PROCESSOR "i386")
message(STATUS "ChakraCore: Building 32-bit x86 code.")
else()
message(FATAL_ERROR "ChakraCore: Autodetection for ${CMAKE_SYSTEM_PROCESSOR} not supported.")
endif()
endif()

if(CC_TARGETS_AMD64_SH)
Expand Down Expand Up @@ -71,7 +75,18 @@ function(clr_unknown_arch)
endif()
endfunction()

if(ICU_INCLUDE_PATH)
if(CC_AUTODETECT_ICU)
find_package(PkgConfig)
# Find ICU Common and Data files
pkg_check_modules(PKGCFG_ICU_UC icu-uc)
# Find ICU Internationalization Library.
pkg_check_modules(PKGCFG_ICU_I18N icu-i18n)
if(PKGCFG_ICU_UC_FOUND AND PKGCFG_ICU_I18N_FOUND)
# This should include internationalization.
set(ICU_CC_PATH "${PKGCFG_ICU_UC_INCLUDE_DIRS}")
set(ICULIB "${PKGCFG_ICU_UC_LDFLAGS}")
endif()
elseif(ICU_INCLUDE_PATH)
add_definitions(-DHAS_REAL_ICU=1)
set(ICU_CC_PATH "${ICU_INCLUDE_PATH}/../lib/")
find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
Expand Down Expand Up @@ -167,7 +182,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
add_definitions("-fdiagnostics-color=always")
endif()

if(STATIC_LIBRARY)
if(CC_BUILD_STATIC_LIBRARY)
add_definitions(-DCHAKRA_STATIC_LIBRARY=1)
endif()

Expand Down Expand Up @@ -262,12 +277,18 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
endif()
endif(CLR_CMAKE_PLATFORM_XPLAT)

if(ENABLE_FULL_LTO_SH)
unset(DENABLE_FULL_LTO_SH CACHE)
if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
OR CMAKE_CXX_COMPILER_ID STREQUAL Clang
OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
if(CC_ENABLE_FULL_LTO)
add_compile_options(-flto)
elseif(ENABLE_THIN_LTO_SH)
unset(ENABLE_THIN_LTO_SH CACHE)
elseif(CC_ENABLE_THIN_LTO)
add_compile_options(-flto=thin)
endif()
else()
if(CC_ENABLE_THIN_LTO OR CC_ENABLE_FULL_LTO)
message(WARNING "Link Time Optimization currently only supports CLANG and GCC")
endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
Expand All @@ -294,12 +315,15 @@ if(IS_64BIT_BUILD)
)
endif(IS_64BIT_BUILD)

if(NO_JIT_SH)
if(CLR_CMAKE_PLATFORM_XPLAT)
add_definitions(-DFEATURE_PAL)
endif(CLR_CMAKE_PLATFORM_XPLAT)


if(NOT CC_ENABLE_JIT)
unset(NO_JIT_SH CACHE) # don't cache
unset(BuildJIT CACHE) # also clear it just in case
add_definitions(-DDISABLE_JIT=1)
else()
set(BuildJIT 1)
endif()

if(WITHOUT_FEATURES_SH)
Expand Down
2 changes: 1 addition & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_subdirectory (GCStress)
add_subdirectory (ch)
if(NOT STATIC_LIBRARY)
if(NOT CC_BUILD_STATIC_LIBRARY)
add_subdirectory (ChakraCore)
endif()
18 changes: 17 additions & 1 deletion bin/ChakraCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if(CC_TARGETS_X86)
set(lib_target "${lib_target} -m32")
endif()

target_link_libraries (ChakraCore ${lib_target})
target_link_libraries (ChakraCore PRIVATE ${lib_target})

if(NOT CC_XCODE_PROJECT)
set(CC_LIB_EXT "so")
Expand All @@ -74,4 +74,20 @@ if(NOT CC_XCODE_PROJECT)
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.${CC_LIB_EXT}"
${CHAKRACORE_BINARY_DIR}/
)
add_custom_command(TARGET ChakraCore POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CHAKRACORE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../../lib/Jsrt/ChakraCore.h"
"${CHAKRACORE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../../lib/Jsrt/ChakraCommon.h"
"${CHAKRACORE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../../lib/Jsrt/ChakraCommonWindows.h"
"${CHAKRACORE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../../lib/Jsrt/ChakraDebug.h"
"${CHAKRACORE_BINARY_DIR}/include"
)

endif()
4 changes: 2 additions & 2 deletions bin/ch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(ch_source_files
WScriptJsrt.cpp
)

if (STATIC_LIBRARY)
if (CC_BUILD_STATIC_LIBRARY)
set(ch_source_files "${ch_source_files}"
../ChakraCore/TestHooks.cpp
)
Expand Down Expand Up @@ -38,7 +38,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") # osx clang sets this by default
endif()

if(STATIC_LIBRARY)
if(CC_BUILD_STATIC_LIBRARY)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(LINKER_START_GROUP -Wl,--start-group)
set(LINKER_END_GROUP -Wl,--end-group)
Expand Down
20 changes: 13 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MAKE=make
MULTICORE_BUILD=""
NO_JIT=
ICU_PATH="-DICU_SETTINGS_RESET=1"
STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
STATIC_LIBRARY="-DCC_BUILD_SHARED_LIBRARY=1"
SANITIZE=
WITHOUT_FEATURES=""
CREATE_DEB=0
Expand Down Expand Up @@ -191,11 +191,11 @@ while [[ $# -gt 0 ]]; do
;;

--lto)
LTO="-DENABLE_FULL_LTO_SH=1"
LTO="-DCC_ENABLE_FULL_LTO=1"
;;

--lto-thin)
LTO="-DENABLE_THIN_LTO_SH=1"
LTO="-DCC_ENABLE_THIN_LTO=1"
;;

-n | --ninja)
Expand All @@ -208,7 +208,7 @@ while [[ $# -gt 0 ]]; do
;;

--no-jit)
NO_JIT="-DNO_JIT_SH=1"
NO_JIT="-DCC_ENABLE_JIT=0"
;;

--xcode)
Expand All @@ -222,7 +222,7 @@ while [[ $# -gt 0 ]]; do
;;

--static)
STATIC_LIBRARY="-DSTATIC_LIBRARY_SH=1"
STATIC_LIBRARY="-DCC_BUILD_STATIC_LIBRARY=1"
;;

--sanitize=*)
Expand Down Expand Up @@ -317,7 +317,13 @@ if [[ ${#_CXX} > 0 ]]; then
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
fi

build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
if [[ $STATIC_LIBRARY == "-DCC_BUILD_SHARED_LIBRARY=1" ]]; then
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
else
build_directory="$CHAKRACORE_DIR/BuildLinux/Static${BUILD_TYPE:0}"
fi


if [ ! -d "$build_directory" ]; then
SAFE_RUN `mkdir -p $build_directory`
fi
Expand Down Expand Up @@ -355,7 +361,7 @@ else
mkdir -p $DEB_FOLDER/usr/local/bin
mkdir -p $DEB_FOLDER/DEBIAN
cp $DEB_FOLDER/../ch $DEB_FOLDER/usr/local/bin/
if [[ $STATIC_LIBRARY == "-DSHARED_LIBRARY_SH=1" ]]; then
if [[ $STATIC_LIBRARY == "-DCC_BUILD_SHARED_LIBRARY=1" ]]; then
cp $DEB_FOLDER/../*.so $DEB_FOLDER/usr/local/bin/
fi
echo -e "Package: ChakraCore"\
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_compile_options(-fPIC)

if(BuildJIT)
if(CC_ENABLE_JIT)
add_subdirectory (Backend)
endif()

Expand Down
2 changes: 1 addition & 1 deletion lib/Common/Codex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(NOT STATIC_LIBRARY)
if(NOT CC_BUILD_STATIC_LIBRARY)
# CH has a direct dependency to this project
add_library (Chakra.Common.Codex.Singular STATIC
Utf8Codex.cpp)
Expand Down
3 changes: 2 additions & 1 deletion lib/Jsrt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(BuildJIT)
if(CC_ENABLE_JIT)
set(chakra_backend_objects $<TARGET_OBJECTS:Chakra.Backend>)
endif()

Expand All @@ -17,6 +17,7 @@ add_library (Chakra.Jsrt STATIC
JsrtRuntime.cpp
JsrtSourceHolder.cpp
JsrtThreadService.cpp
JsrtInitialize.cpp
$<TARGET_OBJECTS:Chakra.Jsrt.Core>
${chakra_backend_objects}
# Do not take this in. We need to control the
Expand Down
3 changes: 2 additions & 1 deletion lib/Jsrt/Chakra.Jsrt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtDiag.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtExternalArrayBuffer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtExternalObject.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtInitialize.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtRuntime.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtThreadService.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JsrtPch.cpp">
Expand Down Expand Up @@ -88,4 +89,4 @@
</ItemGroup>
<Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>
23 changes: 23 additions & 0 deletions lib/Jsrt/ChakraCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,29 @@ typedef UINT32 DWORD;
_In_opt_ void *callbackState,
_In_ JsObjectBeforeCollectCallback objectBeforeCollectCallback);

/// <summary>
/// Initializes the ChakraCore Library Runtime.
/// </summary>
/// <remarks>
/// This does not create a contexts.
/// </remarks>
/// <param name="argc">Argument Count.</param>
/// <param name="argv">Argument Strings.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API JsInitializeRuntime(
_In_ int argc,
_In_ char** argv);

/// <summary>
/// Finalizes the ChakraCore Library Runtime, and performs last minute cleanups.
/// </summary>
/// <remarks>
/// This function will destroy any contexts that are currently in session.
/// </remarks>
CHAKRA_API JsFinalizeRuntime();

/// <summary>
/// Creates a script context for running scripts.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ JsErrorCode CreateRuntimeCore(_In_ JsRuntimeAttributes attributes,
_In_opt_ JsTTDWriteBytesToStreamCallback writeBytesToStream, _In_opt_ JsTTDFlushAndCloseStreamCallback flushAndCloseStream,
_In_opt_ JsThreadServiceCallback threadService, _Out_ JsRuntimeHandle *runtimeHandle)
{
VALIDATE_ENTER_CURRENT_THREAD();
/* Ensure that the Runtime is Initialized */
JsInitializeRuntime(0, NULL);

PARAM_NOT_NULL(runtimeHandle);
*runtimeHandle = nullptr;
Expand Down Expand Up @@ -734,7 +735,8 @@ CHAKRA_API JsGetCurrentContext(_Out_ JsContextRef *currentContext)

CHAKRA_API JsSetCurrentContext(_In_ JsContextRef newContext)
{
VALIDATE_ENTER_CURRENT_THREAD();
/* Ensure that the Runtime is Initialized */
JsInitializeRuntime(0, NULL);

return GlobalAPIWrapper([&] (TTDRecorder& _actionEntryPopper) -> JsErrorCode {
JsrtContext *currentContext = JsrtContext::GetCurrent();
Expand Down
2 changes: 2 additions & 0 deletions lib/Jsrt/JsrtCommonExports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@
JsCreatePropertyIdUtf8
JsCopyPropertyIdUtf8
JsDiagEvaluateUtf8
JsInitializeRuntime
JsFinalizeRuntime
#endif
Loading