Skip to content

Commit

Permalink
Add CMARK_PROGRAM flag to avoid compiling the cmark executable
Browse files Browse the repository at this point in the history
Useful to build only the library (e.g. if we are cross-compiling to
other platform where the program cannot be executed anyway).
  • Loading branch information
dacap committed Jun 17, 2021
1 parent ae7ead2 commit 728c684
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
endif()

option(CMARK_PROGRAM "Build cmark executable" ON)
option(CMARK_TESTS "Build cmark tests and enable testing" ON)
option(CMARK_STATIC "Build static libcmark library" ON)
option(CMARK_SHARED "Build shared libcmark library" ON)
Expand Down
40 changes: 22 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,35 @@ set(LIBRARY_SOURCES
${HEADERS}
)

set(PROGRAM "cmark_exe")
set(PROGRAM_SOURCES main.c)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in
${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h)

include(GNUInstallDirs)
include (GenerateExportHeader)

add_executable(${PROGRAM} ${PROGRAM_SOURCES})
set_target_properties(${PROGRAM} PROPERTIES
OUTPUT_NAME "cmark")
if(CMARK_PROGRAM)
set(PROGRAM "cmark_exe")
set(PROGRAM_SOURCES main.c)

if (CMARK_STATIC)
target_link_libraries(${PROGRAM} ${STATICLIBRARY})
# Disable the PUBLIC declarations when compiling the executable:
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
set_target_properties(${PROGRAM} PROPERTIES
COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
elseif (CMARK_SHARED)
target_link_libraries(${PROGRAM} ${LIBRARY})
OUTPUT_NAME "cmark")

if (CMARK_STATIC)
target_link_libraries(${PROGRAM} ${STATICLIBRARY})
# Disable the PUBLIC declarations when compiling the executable:
set_target_properties(${PROGRAM} PROPERTIES
COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
elseif (CMARK_SHARED)
target_link_libraries(${PROGRAM} ${LIBRARY})
endif()

if(MSVC)
set_property(TARGET ${PROGRAM}
APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
endif(MSVC)

list(APPEND CMARK_INSTALL ${PROGRAM})
endif()

# -fvisibility=hidden
Expand Down Expand Up @@ -112,17 +121,12 @@ if (CMARK_STATIC)
list(APPEND CMARK_INSTALL ${STATICLIBRARY})
endif()

if (MSVC)
set_property(TARGET ${PROGRAM}
APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
endif(MSVC)

if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
include(InstallRequiredSystemLibraries)
endif()

install(TARGETS ${PROGRAM} ${CMARK_INSTALL}
install(TARGETS ${CMARK_INSTALL}
EXPORT cmark-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down

0 comments on commit 728c684

Please sign in to comment.