1# Copyright JS Foundation and other contributors, http://js.foundation 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15cmake_minimum_required (VERSION 2.8.12) 16set(JERRY_PORT_DEFAULT_NAME jerry-port-default) 17project (${JERRY_PORT_DEFAULT_NAME} C) 18 19# Include directories 20set(INCLUDE_PORT_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/include") 21 22# Source directories 23file(GLOB SOURCE_PORT_DEFAULT *.c) 24 25# "Single" JerryScript source/header build. 26# The process will create the following files: 27# * jerryscript-port-default.c 28# * jerryscript-port-default.h 29if(ENABLE_ALL_IN_ONE_SOURCE) 30 file(GLOB HEADER_PORT_DEFAULT *.h) 31 set(ALL_IN_FILE "${CMAKE_BINARY_DIR}/src/jerryscript-port-default.c") 32 set(ALL_IN_FILE_H "${CMAKE_BINARY_DIR}/src/jerryscript-port-default.h") 33 34 add_custom_command(OUTPUT ${ALL_IN_FILE} ${ALL_IN_FILE_H} ${JERRYSCRIPT_CONFIG_H} 35 COMMAND python ${CMAKE_SOURCE_DIR}/tools/srcgenerator.py 36 --jerry-port-default 37 --output-dir ${CMAKE_BINARY_DIR}/src 38 DEPENDS ${SOURCE_PORT_DEFAULT} 39 ${HEADER_PORT_DEFAULT} 40 ${CMAKE_SOURCE_DIR}/tools/srcgenerator.py 41 ${CMAKE_SOURCE_DIR}/tools/srcmerger.py 42 ) 43 add_custom_target(generate-single-source-port DEPENDS ${ALL_IN_FILE} ${ALL_IN_FILE_H}) 44 add_dependencies(generate-single-source generate-single-source-port) 45 46 set(SOURCE_PORT_DEFAULT ${ALL_IN_FILE} ${ALL_IN_FILE_H}) 47endif() 48 49# Define _BSD_SOURCE and _DEFAULT_SOURCE 50# (should only be necessary if we used compiler default libc but not checking that) 51set(DEFINES_PORT_DEFAULT _BSD_SOURCE _DEFAULT_SOURCE) 52 53INCLUDE (CheckStructHasMember) 54# CHECK_STRUCT_HAS_MEMBER works by trying to compile some C code that accesses the 55# given field of the given struct. However, our default compiler options break this 56# C code, so turn a couple of them off for this. 57set(CMAKE_REQUIRED_FLAGS "-Wno-error=strict-prototypes -Wno-error=old-style-definition") 58# tm.tm_gmtoff is non-standard, so glibc doesn't expose it in c99 mode 59# (our default). Define some macros to expose it anyway. 60set(CMAKE_REQUIRED_DEFINITIONS "-D_BSD_SOURCE -D_DEFAULT_SOURCE") 61CHECK_STRUCT_HAS_MEMBER ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) 62if(HAVE_TM_GMTOFF) 63 set(DEFINES_PORT_DEFAULT ${DEFINES_PORT_DEFAULT} HAVE_TM_GMTOFF) 64endif() 65 66# Sleep function availability check 67INCLUDE (CheckIncludeFiles) 68CHECK_INCLUDE_FILES (time.h HAVE_TIME_H) 69CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) 70if(HAVE_TIME_H) 71 set(DEFINES_PORT_DEFAULT ${DEFINES_PORT_DEFAULT} HAVE_TIME_H) 72elseif(HAVE_UNISTD_H) 73 set(DEFINES_PORT_DEFAULT ${DEFINES_PORT_DEFAULT} HAVE_UNISTD_H) 74endif() 75 76# Default Jerry port implementation library variants: 77# - default 78# - default-minimal (no extra termination and log APIs) 79foreach(JERRY_PORT_LIBRARY_NAME ${JERRY_PORT_DEFAULT_NAME} ${JERRY_PORT_DEFAULT_NAME}-minimal) 80 add_library(${JERRY_PORT_LIBRARY_NAME} ${SOURCE_PORT_DEFAULT}) 81 target_include_directories(${JERRY_PORT_LIBRARY_NAME} PUBLIC ${INCLUDE_PORT_DEFAULT}) 82 target_include_directories(${JERRY_PORT_LIBRARY_NAME} PRIVATE ${INCLUDE_CORE_PUBLIC}) 83 target_include_directories(${JERRY_PORT_LIBRARY_NAME} PRIVATE ${INCLUDE_EXT_PUBLIC}) 84 target_compile_definitions(${JERRY_PORT_LIBRARY_NAME} PRIVATE ${DEFINES_PORT_DEFAULT}) 85 target_link_libraries(${JERRY_PORT_LIBRARY_NAME} jerry-core) # FIXME: remove this dependency as soon as possible 86endforeach() 87 88target_compile_definitions(${JERRY_PORT_DEFAULT_NAME}-minimal PRIVATE DISABLE_EXTRA_API) 89 90# Installation 91configure_file(libjerry-port-default.pc.in libjerry-port-default.pc @ONLY) 92configure_file(libjerry-port-default-minimal.pc.in libjerry-port-default-minimal.pc @ONLY) 93 94install(TARGETS ${JERRY_PORT_DEFAULT_NAME} ${JERRY_PORT_DEFAULT_NAME}-minimal DESTINATION lib) 95install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libjerry-port-default.pc ${CMAKE_CURRENT_BINARY_DIR}/libjerry-port-default-minimal.pc DESTINATION lib/pkgconfig) 96install(DIRECTORY ${INCLUDE_PORT_DEFAULT}/ DESTINATION include) 97