summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt18
1 files changed, 12 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9923f1..1f626d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,14 +45,19 @@ IF(JSONC_FOUND)
INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
ENDIF()
-SET(UCODE_SOURCES main.c lexer.c lib.c vm.c chunk.c value.c compiler.c source.c types.c)
-ADD_EXECUTABLE(ucode ${UCODE_SOURCES})
-SET_PROPERTY(TARGET ucode PROPERTY ENABLE_EXPORTS 1)
-TARGET_LINK_LIBRARIES(ucode ${json})
+SET(UCODE_SOURCES lexer.c lib.c vm.c chunk.c value.c compiler.c source.c types.c)
+ADD_LIBRARY(libucode SHARED ${UCODE_SOURCES})
+SET(SOVERSION 0 CACHE STRING "Override ucode library version")
+SET_TARGET_PROPERTIES(libucode PROPERTIES OUTPUT_NAME ucode SOVERSION ${SOVERSION})
+TARGET_LINK_LIBRARIES(libucode ${json})
+
+SET(CLI_SOURCES main.c)
+ADD_EXECUTABLE(ucode ${CLI_SOURCES})
+TARGET_LINK_LIBRARIES(ucode libucode ${json})
CHECK_FUNCTION_EXISTS(dlopen DLOPEN_FUNCTION_EXISTS)
IF (NOT DLOPEN_FUNCTION_EXISTS)
- TARGET_LINK_LIBRARIES(ucode dl)
+ TARGET_LINK_LIBRARIES(libucode dl)
ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES json-c)
@@ -114,7 +119,7 @@ IF(UNIT_TESTING)
LIST(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
- ADD_EXECUTABLE(ucode-san ${UCODE_SOURCES})
+ ADD_EXECUTABLE(ucode-san ${CLI_SOURCES} ${UCODE_SOURCES})
SET_PROPERTY(TARGET ucode-san PROPERTY ENABLE_EXPORTS 1)
TARGET_LINK_LIBRARIES(ucode-san ${json})
TARGET_COMPILE_OPTIONS(ucode-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
@@ -123,4 +128,5 @@ IF(UNIT_TESTING)
ENDIF()
INSTALL(TARGETS ucode RUNTIME DESTINATION bin)
+INSTALL(TARGETS libucode LIBRARY DESTINATION lib)
INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode)