Skip to content

Commit 0b09109

Browse files
authored
Add shared library target to CMake (#60)
1 parent cc3e062 commit 0b09109

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

.github/workflows/ci.yml

+58
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ jobs:
4848
if: ${{ matrix.buildType == 'Release' }}
4949
run: |
5050
time ./build/run-test262 -m -c test262.conf -a
51+
linux-shared:
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v3
55+
- name: build
56+
run: |
57+
mkdir build
58+
cd build
59+
cmake -DBUILD_SHARED_LIBS=ON ..
60+
cd ..
61+
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
62+
ldd build/qjs
63+
- name: stats
64+
run: |
65+
./build/qjs -qd
5166
linux-asan:
5267
runs-on: ubuntu-latest
5368
steps:
@@ -160,6 +175,21 @@ jobs:
160175
./build/qjs tests/test_loop.js
161176
./build/qjs tests/test_std.js
162177
./build/qjs tests/test_worker.js
178+
macos-shared:
179+
runs-on: macos-latest
180+
steps:
181+
- uses: actions/checkout@v3
182+
- name: build
183+
run: |
184+
mkdir build
185+
cd build
186+
cmake -DBUILD_SHARED_LIBS=ON ..
187+
cd ..
188+
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
189+
otool -L build/qjs
190+
- name: stats
191+
run: |
192+
./build/qjs -qd
163193
macos-asan:
164194
runs-on: macos-latest
165195
steps:
@@ -248,3 +278,31 @@ jobs:
248278
./build/qjs tests/test_builtin.js
249279
./build/qjs tests/test_loop.js
250280
./build/qjs tests/test_std.js
281+
windows-mingw-shared:
282+
runs-on: windows-latest
283+
defaults:
284+
run:
285+
shell: msys2 {0}
286+
steps:
287+
- uses: actions/checkout@v3
288+
- name: Setup MSYS2
289+
uses: msys2/setup-msys2@v2
290+
with:
291+
install: >-
292+
git
293+
make
294+
pacboy: >-
295+
cmake:p
296+
ninja:p
297+
toolchain:p
298+
- name: build
299+
run: |
300+
mkdir build
301+
cd build
302+
cmake -DBUILD_SHARED_LIBS=ON ..
303+
cd ..
304+
cmake --build build -j$(getconf _NPROCESSORS_ONLN)
305+
ldd build/qjs
306+
- name: stats
307+
run: |
308+
./build/qjs -qd

CMakeLists.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ cmake_minimum_required(VERSION 3.9)
33
project(quickjs LANGUAGES C)
44

55
# TODO:
6-
# - LTO
76
# - Support cross-compilation
87
# - Install targets
9-
# - Shared library target
108

119
set(CMAKE_C_STANDARD_REQUIRED ON)
1210
set(CMAKE_C_EXTENSIONS ON)
@@ -52,6 +50,11 @@ else()
5250
add_compile_options(-g)
5351
endif()
5452

53+
option(BUILD_SHARED_LIBS "Build a shared library" OFF)
54+
if(BUILD_SHARED_LIBS)
55+
message(STATUS "Building a shared library")
56+
endif()
57+
5558
option(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF)
5659
option(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF)
5760
option(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
@@ -97,8 +100,6 @@ add_link_options(
97100
)
98101
endif()
99102

100-
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")
101-
102103

103104
# QuickJS library
104105
#
@@ -113,7 +114,7 @@ set(qjs_sources
113114

114115
list(APPEND qjs_defines _GNU_SOURCE)
115116

116-
add_library(qjs STATIC ${qjs_sources})
117+
add_library(qjs ${qjs_sources})
117118
target_compile_definitions(qjs PRIVATE ${qjs_defines})
118119
if (CMAKE_BUILD_TYPE MATCHES Debug)
119120
target_compile_definitions(qjs PRIVATE

0 commit comments

Comments
 (0)