From efb8e37664250cf91780efe1764ddb0c161ae9f2 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 24 May 2015 15:10:31 +0200 Subject: [PATCH] Build both static and shared libraries. First many other projects do this, and it seems a good choice. Due mainly to windows where the static and shared libraries have the same name, appended an 's' to the static library. The tidy console app will use the static library, since to build the man page tidy may need to be run before the shared libraries are installed. And this makes the windows tidy exe a stand-alone app. No DLL install issue. This addresses issue #194, and possibly #190 --- CMakeLists.txt | 56 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 166d47a..30bdcc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ list(GET VERSION_LIST 2 TIDY_POINT_VERSION) # Allow developer to select is Dynamic or static library built set( LIB_TYPE STATIC ) # set default static -option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library" OFF ) +option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library" ON ) option( BUILD_TAB2SPACE "Set ON to build utility app, tab2space" OFF ) option( BUILD_SAMPLE_CODE "Set ON to build the sample code" OFF ) if (NOT MAN_INSTALL_DIR) @@ -117,32 +117,43 @@ if (MSVC) list(APPEND CFILES ${SRCDIR}/sprtf.c) list(APPEND LIBHFILES ${SRCDIR}/sprtf.h) endif () -set(name lib-tidy) -add_library ( ${name} ${LIB_TYPE} ${CFILES} ${HFILES} ${LIBHFILES} ) +####################################### +# Always build the STATIC library +set(name tidy-static) +add_library ( ${name} STATIC ${CFILES} ${HFILES} ${LIBHFILES} ) set_target_properties( ${name} PROPERTIES - OUTPUT_NAME ${LIB_NAME} + OUTPUT_NAME ${LIB_NAME}s ) -set_target_properties( ${name} PROPERTIES - VERSION ${LIBTIDY_VERSION} - SOVERSION ${TIDY_MAJOR_VERSION} ) -if (BUILD_SHARED_LIB) -set_target_properties( ${name} PROPERTIES - COMPILE_FLAGS "-DBUILD_SHARED_LIB" - ) -set_target_properties( ${name} PROPERTIES - COMPILE_FLAGS "-DBUILDING_SHARED_LIB" - ) -endif () list ( APPEND add_LIBS ${name} ) install(TARGETS ${name} - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - ) + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) install( FILES ${HFILES} DESTINATION include ) +######################################## +# if user option still on +if (BUILD_SHARED_LIB) + set(name tidy-share) + add_library ( ${name} SHARED ${CFILES} ${HFILES} ${LIBHFILES} ) + set_target_properties( ${name} PROPERTIES + OUTPUT_NAME ${LIB_NAME} ) + set_target_properties( ${name} PROPERTIES + VERSION ${LIBTIDY_VERSION} + SOVERSION ${TIDY_MAJOR_VERSION} ) + set_target_properties( ${name} PROPERTIES + COMPILE_FLAGS "-DBUILD_SHARED_LIB" ) + set_target_properties( ${name} PROPERTIES + COMPILE_FLAGS "-DBUILDING_SHARED_LIB" ) + install(TARGETS ${name} + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) +endif () ########################################################## -### main executable +### main executable - linked with STATIC library set(name ${LIB_NAME}) set ( BINDIR console ) add_executable( ${name} ${BINDIR}/tidy.c ) @@ -150,11 +161,6 @@ target_link_libraries( ${name} ${add_LIBS} ) if (MSVC) set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d ) endif () -if (BUILD_SHARED_LIB) -set_target_properties( ${name} PROPERTIES - COMPILE_FLAGS "-DBUILD_SHARED_LIB" - ) -endif () install (TARGETS ${name} DESTINATION bin) if (BUILD_TAB2SPACE)