Skip to content

Introduce 'USE_COMPILER_DEFAULT_LIBC' cmake option for switching from jerry-libc to a libc, provided by compiler #331

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

Merged
merged 1 commit into from
Jul 8, 2015
Merged
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
34 changes: 21 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ project (Jerry CXX C ASM)
set(MCU_SCRIPT_GENERATED_HEADER ${CMAKE_BINARY_DIR}/generated.h)

# Should we use external libc?
if(NOT DEFINED EXTERNAL_LIBC_INTERFACE OR EXTERNAL_LIBC_INTERFACE STREQUAL "UNDEFINED")
if(DEFINED USE_COMPILER_DEFAULT_LIBC AND USE_COMPILER_DEFAULT_LIBC STREQUAL "YES")
if(NOT EXTERNAL_LIBC_INTERFACE STREQUAL "" AND NOT EXTERNAL_LIBC_INTERFACE STREQUAL "UNDEFINED")
message(FATAL_ERROR "EXTERNAL_LIBC_INTERFACE='${EXTERNAL_LIBC_INTERFACE}' should not be set in case compiler's default libc is used (USE_COMPILER_DEFAULT_LIBC=YES)")
endif()

set(USE_JERRY_LIBC FALSE)
elseif(NOT DEFINED EXTERNAL_LIBC_INTERFACE OR EXTERNAL_LIBC_INTERFACE STREQUAL "UNDEFINED")
set(USE_JERRY_LIBC TRUE)
else()
set(USE_JERRY_LIBC FALSE)
Expand Down Expand Up @@ -180,6 +186,11 @@ project (Jerry CXX C ASM)
set(COMPILE_FLAGS_JERRY "-fno-builtin")
set(LINKER_FLAGS_COMMON "-Wl,-z,noexecstack")

# Turn off linking to compiler's default libc, in case jerry-libc is used
if(${USE_JERRY_LIBC})
set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} -nostdlib")
endif()

# LTO
if("${ENABLE_LTO}" STREQUAL "ON")
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -flto -fno-fat-lto-objects")
Expand Down Expand Up @@ -219,13 +230,13 @@ project (Jerry CXX C ASM)
set(LINKER_FLAGS_COMMON_MCU_STM32F4 "-T${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/FLASH_Program/TrueSTUDIO/FLASH_Program/stm32_flash.ld")

# Debug
set(FLAGS_COMMON_DEBUG "-nostdlib")
set(FLAGS_COMMON_DEBUG "")

# Release
set(FLAGS_COMMON_RELEASE "-Os -nostdlib")
set(FLAGS_COMMON_RELEASE "-Os")

# Unit tests
set(FLAGS_COMMON_UNITTESTS "-O3 -nostdlib")
set(FLAGS_COMMON_UNITTESTS "-O3")

# Include directories
# Core interface
Expand All @@ -249,13 +260,6 @@ project (Jerry CXX C ASM)
file(GLOB SOURCE_UNIT_TEST_MAIN_MODULES tests/unit/*.cpp)

# Imported libraries
# libc
add_library(${PREFIX_IMPORTED_LIB}libc SHARED IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=libc.so
OUTPUT_VARIABLE IMPORTED_LIBC_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set_property(TARGET ${PREFIX_IMPORTED_LIB}libc
PROPERTY IMPORTED_LOCATION ${IMPORTED_LIBC_LOCATION})
# libgcc
add_library(${PREFIX_IMPORTED_LIB}libgcc STATIC IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=libgcc.a
Expand Down Expand Up @@ -299,7 +303,9 @@ project (Jerry CXX C ASM)

function(declare_targets_for_build_mode BUILD_MODE)
set(TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.${PLATFORM_L})
set(LIBC_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.jerry-libc.${PLATFORM_L}.lib)
if (${USE_JERRY_LIBC})
set(LIBC_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.jerry-libc.${PLATFORM_L}.lib)
endif()

function(declare_target_with_modifiers ) # modifiers are passed in ARGN implicit argument
set(CORE_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}})
Expand Down Expand Up @@ -408,7 +414,9 @@ project (Jerry CXX C ASM)
set(TARGET_NAME unit-${TARGET_NAME})

set(CORE_TARGET_NAME unittests.jerry-core)
set(LIBC_TARGET_NAME unittests.jerry-libc.${PLATFORM_L}.lib)
if (${USE_JERRY_LIBC})
set(LIBC_TARGET_NAME unittests.jerry-libc.${PLATFORM_L}.lib)
endif ()
set(FDLIBM_TARGET_NAME unittests.jerry-fdlibm${SUFFIX_THIRD_PARTY_LIB})

add_executable(${TARGET_NAME} ${SOURCE_UNIT_TEST_MAIN})
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@
endif

# External build configuration
# Flag, indicating whether to use compiler's default libc (YES / NO)
USE_COMPILER_DEFAULT_LIBC ?= NO
# List of include paths for external libraries (semicolon-separated)
EXTERNAL_LIBS_INTERFACE ?=
# External libc interface
ifeq ($(USE_COMPILER_DEFAULT_LIBC),YES)
ifneq ($(EXTERNAL_LIBC_INTERFACE),)
$(error EXTERNAL_LIBC_INTERFACE should not be specified in case compiler's default libc is used)
endif
endif
# Compiler to use for external build
EXTERNAL_C_COMPILER ?= arm-none-eabi-gcc
EXTERNAL_CXX_COMPILER ?= arm-none-eabi-g++
Expand Down