Skip to content

Commit 75fab76

Browse files
committed
Link executable with static or shared library
If CMARK_STATIC is on (default), link the executable with the static library. This produces exactly the same result as compiling the library sources again and linking with the object files. If CMARK_STATIC is off, link the executable with the shared library. This wasn't supported before and should be the preferred way to package cmark on Linux distros. Building only a shared library and a statically linked executable isn't supported anymore but this doesn't seem useful.
1 parent 8daa6b1 commit 75fab76

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ set(LIBRARY_SOURCES
4646
)
4747

4848
set(PROGRAM "cmark")
49-
set(PROGRAM_SOURCES
50-
${LIBRARY_SOURCES}
51-
main.c
52-
)
49+
set(PROGRAM_SOURCES main.c)
5350

5451
include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
5552

@@ -60,9 +57,14 @@ include (GenerateExportHeader)
6057

6158
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
6259

63-
# Disable the PUBLIC declarations when compiling the executable:
64-
set_target_properties(${PROGRAM} PROPERTIES
65-
COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
60+
if (CMARK_STATIC)
61+
target_link_libraries(${PROGRAM} ${STATICLIBRARY})
62+
# Disable the PUBLIC declarations when compiling the executable:
63+
set_target_properties(${PROGRAM} PROPERTIES
64+
COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
65+
elseif (CMARK_SHARED)
66+
target_link_libraries(${PROGRAM} ${LIBRARY})
67+
endif()
6668

6769
# Check integrity of node structure when compiled as debug:
6870
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCMARK_DEBUG_NODES")

0 commit comments

Comments
 (0)