Skip to content

Commit b3fc9a7

Browse files
authored
Allow Rust to build core as a static lib (#3283)
1 parent 18245ef commit b3fc9a7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1601,3 +1601,5 @@ endif()
16011601
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
16021602
add_subdirectory(${PROJECT_SOURCE_DIR}/benchmark)
16031603
add_subdirectory(${PROJECT_SOURCE_DIR}/render-test)
1604+
1605+
include(cmake/mbgl-core-deps.cmake)

cmake/mbgl-core-deps.cmake

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# this file defines a target that will generate a mbgl-core-deps.txt which includes the linker
2+
# flags that would need to be passed to an executable or library that links with
3+
# the static mbgl-core library
4+
5+
set(DUMMY_FILE "${CMAKE_BINARY_DIR}/dummy.cpp")
6+
add_custom_command(
7+
OUTPUT ${DUMMY_FILE}
8+
COMMAND ${CMAKE_COMMAND} -E echo "int main() {}" > ${DUMMY_FILE}
9+
COMMENT "Generating dummy.cpp"
10+
VERBATIM
11+
)
12+
13+
# https://stackoverflow.com/questions/34165365/retrieve-all-link-flags-in-cmake
14+
set(CMAKE_ECHO_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES})
15+
set(CMAKE_ECHO_FLAGS ${CMAKE_CXX_FLAGS})
16+
set(CMAKE_ECHO_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS})
17+
set(CMAKE_ECHO_IMPLICIT_LINK_DIRECTORIES ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
18+
set(
19+
CMAKE_ECHO_LINK_EXECUTABLE
20+
"<CMAKE_COMMAND> -E echo \"<FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>\" > <TARGET>"
21+
)
22+
23+
add_executable(mbgl-core-deps EXCLUDE_FROM_ALL "${DUMMY_FILE}")
24+
target_link_libraries(mbgl-core-deps mbgl-core)
25+
add_custom_target(generate_dummy DEPENDS ${DUMMY_FILE})
26+
add_dependencies(mbgl-core-deps generate_dummy)
27+
28+
set_target_properties(
29+
mbgl-core-deps
30+
PROPERTIES
31+
LINKER_LANGUAGE ECHO
32+
SUFFIX ".txt"
33+
)

0 commit comments

Comments
 (0)