Skip to content

Commit

Permalink
Add shared library target to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 14, 2023
1 parent 9749a90 commit d4d08fa
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
if: ${{ matrix.buildType == 'Release' }}
run: |
time ./build/run-test262 -m -c test262.conf -a
linux-shared:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build
run: |
mkdir build
cd build
cmake -DBUILD_SHARED=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
ldd build/qjs-shared
- name: stats
run: |
./build/qjs-shared -qd
linux-asan:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -160,6 +175,21 @@ jobs:
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
./build/qjs tests/test_worker.js
macos-shared:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: build
run: |
mkdir build
cd build
cmake -DBUILD_SHARED=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
otool -L build/qjs-shared
- name: stats
run: |
./build/qjs-shared -qd
macos-asan:
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -248,3 +278,31 @@ jobs:
./build/qjs tests/test_builtin.js
./build/qjs tests/test_loop.js
./build/qjs tests/test_std.js
windows-mingw-shared:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v3
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
install: >-
git
make
pacboy: >-
cmake:p
ninja:p
toolchain:p
- name: build
run: |
mkdir build
cd build
cmake -DBUILD_SHARED=ON ..
cd ..
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
ldd build/qjs-shared
- name: stats
run: |
./build/qjs-shared -qd
31 changes: 30 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ project(quickjs LANGUAGES C)
# - LTO
# - Support cross-compilation
# - Install targets
# - Shared library target

set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
Expand Down Expand Up @@ -52,6 +51,11 @@ else()
add_compile_options(-g)
endif()

option(BUILD_SHARED "Build a shared library and CLI too" OFF)
if(BUILD_SHARED)
message(STATUS "Building shared library targets")
endif()

option(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF)
option(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF)
option(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
Expand Down Expand Up @@ -122,6 +126,16 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
endif()
target_include_directories(qjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

if(BUILD_SHARED)
add_library(qjs_shared SHARED ${qjs_sources})
target_compile_definitions(qjs_shared PRIVATE ${qjs_defines})
if (CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(qjs_shared PRIVATE
DUMP_LEAKS
)
endif()
target_include_directories(qjs_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
endif()

# QuickJS bytecode compiler
#
Expand Down Expand Up @@ -163,6 +177,21 @@ if(NOT MINGW)
target_link_libraries(qjs_exe dl)
endif()

if(BUILD_SHARED)
add_executable(qjs_shared_exe
qjs.c
quickjs-libc.c
${CMAKE_CURRENT_BINARY_DIR}/repl.c
)
set_target_properties(qjs_shared_exe PROPERTIES
OUTPUT_NAME "qjs-shared"
)
target_compile_definitions(qjs_shared_exe PRIVATE ${qjs_defines})
target_link_libraries(qjs_shared_exe qjs_shared m pthread)
if(NOT MINGW)
target_link_libraries(qjs_shared_exe dl)
endif()
endif()

# Test262 runner
#
Expand Down

0 comments on commit d4d08fa

Please sign in to comment.