Skip to content

Commit

Permalink
Full build and testing directly from CMake
Browse files Browse the repository at this point in the history
Add a direct mode for CMake builds. Add a CMake variable to distinguish
between `build.sh` and direct command line use -- in direct mode the
build would try to pick up reasonable system defaults. Set that variable
to OFF by default and to ON in `build.sh`.

Add explicit option for Intl support for direct CMake use and set its
default to `ON`. Add another explicit option for ICU include path
(default to empty), also only under direct CMake. Make sure Intl setting
does not get overridden.

Expose some ICU build options - embedding (default to OFF), Intl
(default to ON), and ICU include path (default to empty).

Move DbgController.js.h generation to CMake, make that step conditional
on whether dependencies have changed.

Add testing under control of CMake. Invoking `check` target should
run entire test suite, producing log file in the build directory.

Make some CMake error messages slightly more informative.

Nit: build.sh - "makefiles" is inaccurate, as it supports Ninja as well.

Closes chakra-core#6417
  • Loading branch information
ppenzin committed May 8, 2020
1 parent c72b4b7 commit 2b29b55
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ tags
*.dylib
Makefile
pal/src/config.h
DbgController.js.h
lib/wabt/built/config.h

# Generated by other tools
Expand Down
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ project (CHAKRACORE)

set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")

# Disable exepected CMake workflow
option(CHAKRACORE_BUILD_SH "Use build.sh")

if(NOT CHAKRACORE_BUILD_SH)
option(INTL_ICU "Enable Intl" ON)
option(EMBED_ICU "Build ICU within ChakraCore build" OFF)
set(ICU_INCLUDE_PATH "" CACHE STRING "libicu iclude path")
endif(NOT CHAKRACORE_BUILD_SH)

# Keep CMake from caching static/shared library
# option. Otherwise, CMake fails to update cached
# references
Expand All @@ -27,7 +36,7 @@ if(LIBS_ONLY_BUILD_SH)
set(CC_LIBS_ONLY_BUILD 1)
endif()

if(CC_USES_SYSTEM_ARCH_SH)
if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CC_TARGETS_AMD64_SH 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
Expand All @@ -46,7 +55,7 @@ elseif(CC_TARGETS_X86_SH)
set(CC_TARGETS_X86 1)
set(CMAKE_SYSTEM_PROCESSOR "i386")
else()
message(FATAL_ERROR "Couldn't detect target processor, try `--arch` argument with build.sh")
message(FATAL_ERROR "Unsupported target processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()

unset(CC_TARGETS_ARM_SH CACHE)
Expand Down Expand Up @@ -128,13 +137,15 @@ if(SYSTEM_ICU_SH)
unset(SYSTEM_ICU_SH CACHE)
endif()

if(INTL_ICU_SH)
unset(INTL_ICU_SH CACHE)
set(INTL_ICU 1)
else()
unset(INTL_ICU_SH CACHE)
set(INTL_ICU 0)
endif()
if(CHAKRACORE_BUILD_SH)
if(INTL_ICU_SH)
unset(INTL_ICU_SH CACHE)
set(INTL_ICU 1)
else()
unset(INTL_ICU_SH CACHE)
set(INTL_ICU 0)
endif()
endif(CHAKRACORE_BUILD_SH)

if(EMBED_ICU_SH)
set(EMBED_ICU 1)
Expand Down Expand Up @@ -296,7 +307,7 @@ elseif(CC_TARGET_OS_OSX)
endif()
endif()
else()
message(FATAL_ERROR "This OS is not supported")
message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
Expand Down Expand Up @@ -562,3 +573,5 @@ endif()
add_subdirectory (lib)

add_subdirectory (bin)

add_subdirectory(test)
9 changes: 9 additions & 0 deletions bin/ch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
add_custom_target(dbg_controller_h
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js controllerScript
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js
)

set(ch_source_files
ch.cpp
ChakraRtInterface.cpp
Expand All @@ -17,6 +23,8 @@ endif()

add_executable (ch ${ch_source_files})

add_dependencies(ch dbg_controller_h)

set_target_properties(ch
PROPERTIES
POSITION_INDEPENDENT_CODE True
Expand All @@ -30,6 +38,7 @@ endif()

target_include_directories (ch
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
../ChakraCore
../../lib/Common
../../lib/Jsrt
Expand Down
2 changes: 1 addition & 1 deletion bin/ch/jstoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def convert():
if os.path.isfile(js_file_name) == False:
print_usage()

h_file_name = js_file_name + '.h'
h_file_name = os.path.basename(js_file_name) + '.h'

js_file_time = os.path.getmtime(js_file_name)
h_file_time = 0
Expand Down
18 changes: 6 additions & 12 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,6 @@ if [[ $WB_CHECK || $WB_ANALYZE ]]; then
fi
fi

# prepare DbgController.js.h
CH_DIR="${CHAKRACORE_DIR}/bin/ch"
"${CH_DIR}/jstoc.py" "${CH_DIR}/DbgController.js" controllerScript
if [[ $? != 0 ]]; then
exit 1
fi

if [ ! -d "$BUILD_DIRECTORY" ]; then
SAFE_RUN `mkdir -p $BUILD_DIRECTORY`
fi
Expand All @@ -634,12 +627,13 @@ else
echo "Compile Target : System Default"
fi

echo Generating $BUILD_TYPE makefiles
echo Generating $BUILD_TYPE build
echo $EXTRA_DEFINES
cmake $CMAKE_GEN $CC_PREFIX $CMAKE_ICU $LTO $LTTNG $STATIC_LIBRARY $ARCH $TARGET_OS \
$ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\
$VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
cmake $CMAKE_GEN -DCHAKRACORE_BUILD_SH=ON $CC_PREFIX $CMAKE_ICU $LTO $LTTNG \
$STATIC_LIBRARY $ARCH $TARGET_OS \ $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS \
$LIBS_ONLY_BUILD $VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME

_RET=$?
if [[ $? == 0 ]]; then
Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
set(TEST_BUILD_TYPE --test)
elseif (CMAKE_BUILD_TYPE STREQUAL Debug)
set(TEST_BUILD_TYPE --debug)
endif ()

add_custom_target(check
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtests.py ${TEST_BUILD_TYPE} --binary ${CMAKE_BINARY_DIR}/ch --logfile ${CMAKE_BINARY_DIR}/check.log
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
DEPENDS ch
)

0 comments on commit 2b29b55

Please sign in to comment.