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
+37
View File
@@ -22,6 +22,43 @@ set(INCLUDE_PORT_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/include")
# Source directories
file(GLOB SOURCE_PORT_DEFAULT *.c)
# "Single" JerryScript source/header build.
# The process will create the following files:
# * jerryscript-port-default.c
# * jerryscript-port-default.h
if(ENABLE_ALL_IN_ONE_SOURCE)
file(GLOB HEADER_PORT_DEFAULT *.h)
set(ALL_IN_FILE "${CMAKE_BINARY_DIR}/jerryscript-port-default.c")
set(ALL_IN_FILE_H "${CMAKE_BINARY_DIR}/jerryscript-port-default.h")
add_custom_command(OUTPUT ${ALL_IN_FILE}
COMMAND python ${CMAKE_SOURCE_DIR}/tools/srcmerger.py
--base-dir ${CMAKE_CURRENT_SOURCE_DIR}
--output ${ALL_IN_FILE}
--append-c-files
--remove-include jerryscript-port.h
--remove-include jerryscript-port-default.h
--remove-include jerryscript-debugger.h
--push-include jerryscript.h
--push-include jerryscript-port-default.h
DEPENDS ${SOURCE_PORT_DEFAULT} ${ALL_IN_FILE_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-port-default.h
--output ${ALL_IN_FILE_H}
--remove-include jerryscript-port.h
--remove-include jerryscript.h
--push-include jerryscript.h
DEPENDS ${HEADER_PORT_DEFAULT}
)
add_custom_target(generate-single-source-port DEPENDS ${ALL_IN_FILE} ${ALL_IN_FILE_H})
add_dependencies(generate-single-source generate-single-source-port)
set(SOURCE_PORT_DEFAULT ${ALL_IN_FILE} ${ALL_IN_FILE_H})
endif()
# Define _BSD_SOURCE and _DEFAULT_SOURCE
# (should only be necessary if we used compiler default libc but not checking that)
set(DEFINES_PORT_DEFAULT _BSD_SOURCE _DEFAULT_SOURCE)