Skip to content

Commit

Permalink
Fix BUILD_SHARED_LIBS issue (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 authored Jan 27, 2025
1 parent 294db69 commit c720204
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)

#BEGIN internal
option(BUILD_SHARED_LIBS "Use \"ON\" to build shared libraries instead of static where it's not specified (not recommended)" OFF)
option(USE_EMSCRIPTEN "Use \"ON\" for config building wasm." OFF)
option(TON_ONLY_TONLIB "Use \"ON\" to build only tonlib." OFF)
if (USE_EMSCRIPTEN)
Expand Down
16 changes: 6 additions & 10 deletions emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

option(BUILD_SHARED_LIBS "Use \"OFF\" for a static build." ON)

if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)
endif()
Expand All @@ -11,11 +9,6 @@ set(EMULATOR_STATIC_SOURCE
tvm-emulator.hpp
)

set(EMULATOR_HEADERS
transaction-emulator.h
emulator-extern.h
)

set(EMULATOR_SOURCE
emulator-extern.cpp
)
Expand All @@ -29,10 +22,10 @@ include(GenerateExportHeader)
add_library(emulator_static STATIC ${EMULATOR_STATIC_SOURCE})
target_link_libraries(emulator_static PUBLIC ton_crypto smc-envelope)

if (NOT USE_EMSCRIPTEN AND BUILD_SHARED_LIBS)
add_library(emulator SHARED ${EMULATOR_SOURCE} ${EMULATOR_HEADERS})
if (USE_EMSCRIPTEN)
add_library(emulator STATIC ${EMULATOR_SOURCE})
else()
add_library(emulator STATIC ${EMULATOR_SOURCE} ${EMULATOR_HEADERS})
add_library(emulator SHARED ${EMULATOR_SOURCE})
endif()

if (PORTABLE AND NOT APPLE)
Expand All @@ -42,6 +35,9 @@ else()
endif()

generate_export_header(emulator EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/emulator_export.h)
if (USE_EMSCRIPTEN)
target_compile_definitions(emulator PUBLIC EMULATOR_STATIC_DEFINE)
endif()
target_include_directories(emulator PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
Expand Down
12 changes: 5 additions & 7 deletions tonlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

option(BUILD_SHARED_LIBS "Use \"OFF\" for a static build." ON)

if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)
endif()
Expand Down Expand Up @@ -92,10 +90,10 @@ set(TONLIB_JSON_HEADERS tonlib/tonlib_client_json.h)
set(TONLIB_JSON_SOURCE tonlib/tonlib_client_json.cpp)

include(GenerateExportHeader)
if (NOT USE_EMSCRIPTEN AND BUILD_SHARED_LIBS)
add_library(tonlibjson SHARED ${TONLIB_JSON_SOURCE} ${TONLIB_JSON_HEADERS})
if (USE_EMSCRIPTEN)
add_library(tonlibjson STATIC ${TONLIB_JSON_SOURCE})
else()
add_library(tonlibjson STATIC ${TONLIB_JSON_SOURCE} ${TONLIB_JSON_HEADERS})
add_library(tonlibjson SHARED ${TONLIB_JSON_SOURCE})
endif()

if (PORTABLE AND NOT APPLE)
Expand All @@ -105,7 +103,7 @@ else()
endif()

generate_export_header(tonlibjson EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/tonlib/tonlibjson_export.h)
if (!BUILD_SHARED_LIBS)
if (USE_EMSCRIPTEN)
target_compile_definitions(tonlibjson PUBLIC TONLIBJSON_STATIC_DEFINE)
endif()
target_include_directories(tonlibjson PUBLIC
Expand Down Expand Up @@ -159,7 +157,7 @@ endif()

install(FILES ${TONLIB_JSON_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/tonlib/tonlibjson_export.h DESTINATION include/tonlib/)

if (NOT USE_EMSCRIPTEN AND BUILD_SHARED_LIBS)
if (NOT USE_EMSCRIPTEN)
install(EXPORT Tonlib
FILE TonlibTargets.cmake
NAMESPACE Tonlib::
Expand Down

0 comments on commit c720204

Please sign in to comment.