Skip to content

Commit 10e2fd4

Browse files
authored
Merge pull request commonmark#295 from nwellnhof/link-exe-with-lib
Link executable with static or shared library
2 parents 8daa6b1 + 75fab76 commit 10e2fd4

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)