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) 16project (jerry-main C) 17 18# Optional build settings 19set(ENABLE_LINK_MAP OFF CACHE BOOL "Enable generating a link map file?") 20 21# Status messages 22message(STATUS "ENABLE_LINK_MAP " ${ENABLE_LINK_MAP}) 23 24# Generate map file 25if(ENABLE_LINK_MAP) 26 if("${PLATFORM}" STREQUAL "DARWIN") 27 set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} -Xlinker -map -Xlinker jerry.map") 28 else() 29 set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} -Xlinker -Map -Xlinker jerry.map") 30 endif() 31endif() 32 33# Get version information from git 34if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git") 35 execute_process(COMMAND git rev-parse --short HEAD 36 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 37 OUTPUT_VARIABLE JERRY_COMMIT_HASH 38 OUTPUT_STRIP_TRAILING_WHITESPACE) 39 set(JERRY_COMMIT_HASH " (${JERRY_COMMIT_HASH})") 40else() 41 set(JERRY_COMMIT_HASH "") 42endif() 43 44set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_COMMIT_HASH="${JERRY_COMMIT_HASH}") 45 46macro(jerry_create_executable JERRY_NAME) 47 add_executable(${JERRY_NAME} ${ARGN}) 48 set_property(TARGET ${JERRY_NAME} 49 PROPERTY LINK_FLAGS "${LINKER_FLAGS_COMMON}") 50 target_compile_definitions(${JERRY_NAME} PRIVATE ${DEFINES_JERRY}) 51 52 target_link_libraries(${JERRY_NAME} jerry-core) 53 54 install(TARGETS ${JERRY_NAME} DESTINATION bin) 55endmacro() 56 57# Jerry with libfuzzer support 58if(JERRY_LIBFUZZER) 59 jerry_create_executable("jerry-libfuzzer" "libfuzzer.c") 60 target_link_libraries("jerry-libfuzzer" jerry-port-default -fsanitize=fuzzer) 61endif() 62 63# Jerry standalones 64if(JERRY_CMDLINE) 65 jerry_create_executable("jerry" "main-unix.c" "cli.c") 66 target_link_libraries("jerry" jerry-ext jerry-port-default) 67endif() 68 69if(JERRY_CMDLINE_TEST) 70 jerry_create_executable("jerry-test" "main-unix-test.c" "benchmarking.c") 71 target_link_libraries("jerry-test" jerry-port-default-minimal) 72endif() 73 74if(JERRY_CMDLINE_SNAPSHOT) 75 jerry_create_executable("jerry-snapshot" "main-unix-snapshot.c" "cli.c") 76 target_link_libraries("jerry-snapshot" jerry-port-default) 77endif() 78