Add a "single" source/header file generation and build mode (#2790)

Introduce a new way of building: before any file is compiled
all source files are combined into a single C file and all
header files into a single H file (per subdir).

This new approach makes it possible to quickly integrate JerryScript
into other projects:

```
$ gcc -o demo demo.c jerryscript.c jerryscript-port-default.c -lm
```

To use the source generator run:
```
$ cmake -Bbuild_dir -H. -DENABLE_ALL_IN_ONE_SOURCE=ON
$ make -C build_dir generate-single-source
```

This will create the following files in the `build_dir`:
* jerryscript.c
* jerryscript.h
* jerryscript-config.h
* jerryscript-port-default.c
* jerryscript-port-default.h

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
Péter Gál
2019-04-01 11:06:13 +02:00
committed by Robert Fancsik
parent e063b8af80
commit 3f6599c358
4 changed files with 330 additions and 0 deletions
+50
View File
@@ -150,6 +150,56 @@ if(ENABLE_ALL_IN_ONE)
set(SOURCE_CORE_FILES ${ALL_IN_FILE})
endif()
# "Single" JerryScript source/header build.
# The process will create the following files:
# * jerryscript.c
# * jerryscript.h
# * jerryscript-config.h
if(ENABLE_ALL_IN_ONE_SOURCE)
# Create a default configuration
set(JERRYSCRIPT_CONFIG_H "${CMAKE_BINARY_DIR}/jerryscript-config.h")
set(JERRYSCRIPT_SOURCE_CONFIG_H "${CMAKE_CURRENT_SOURCE_DIR}/config.h")
add_custom_command(OUTPUT ${JERRYSCRIPT_CONFIG_H}
COMMAND ${CMAKE_COMMAND} -E copy ${JERRYSCRIPT_SOURCE_CONFIG_H} ${JERRYSCRIPT_CONFIG_H}
DEPENDS ${JERRYSCRIPT_SOURCE_CONFIG_H})
# Create single C file
file(GLOB HEADER_CORE_FILES *.h)
set(ALL_IN_FILE "${CMAKE_BINARY_DIR}/jerryscript.c")
set(ALL_IN_FILE_H "${CMAKE_BINARY_DIR}/jerryscript.h")
add_custom_command(OUTPUT ${ALL_IN_FILE}
COMMAND python ${CMAKE_SOURCE_DIR}/tools/srcmerger.py
--base-dir ${CMAKE_CURRENT_SOURCE_DIR}
--input ${CMAKE_CURRENT_SOURCE_DIR}/api/jerry.c
--output ${ALL_IN_FILE}
--append-c-files
--remove-include jerryscript.h
--remove-include jerryscript-port.h
--remove-include jerryscript-compiler.h
--remove-include jerryscript-core.h
--remove-include jerryscript-debugger.h
--remove-include jerryscript-debugger-transport.h
--remove-include jerryscript-port.h
--remove-include jerryscript-snapshot.h
--remove-include config.h
--push-include jerryscript.h
DEPENDS ${SOURCE_CORE_FILES} ${ALL_IN_FILE_H} ${JERRYSCRIPT_CONFIG_H}
)
add_custom_command(OUTPUT ${ALL_IN_FILE_H}
COMMAND python ${CMAKE_SOURCE_DIR}/tools/srcmerger.py
--base-dir ${CMAKE_CURRENT_SOURCE_DIR}
--input ${CMAKE_CURRENT_SOURCE_DIR}/include/jerryscript.h
--output ${ALL_IN_FILE_H}
--remove-include config.h
--push-include jerryscript-config.h
DEPENDS ${HEADER_CORE_FILES} ${JERRYSCRIPT_CONFIG_H}
)
add_custom_target(generate-single-source-jerry DEPENDS ${ALL_IN_FILE} ${ALL_IN_FILE_H})
add_custom_target(generate-single-source DEPENDS generate-single-source-jerry)
set(SOURCE_CORE_FILES ${ALL_IN_FILE} ${ALL_IN_FILE_H})
endif()
# Third-party
# Valgrind
set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind")