diff options
author | Azamat H. Hackimov <azamat.hackimov@gmail.com> | 2017-01-05 01:12:16 +0500 |
---|---|---|
committer | Azamat H. Hackimov <azamat.hackimov@gmail.com> | 2017-01-06 17:17:10 +0500 |
commit | c9c18fff2fd8b3d0bef0120fe3db3b6ab0beeb9b (patch) | |
tree | bc2450b78f0afeb62feb64d5457f85d9536b5013 | |
parent | 7031efcb5fc577dc70f3188ce1c46bf894b1e48a (diff) |
Make shared and static libraries optional
Now you can enable/disable compilation and installation targets for
shared and static libraries via -DCMARK_SHARED=ON/OFF and
-DCMARK_STATIC=ON/OFF
-rwxr-xr-x | CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/CMakeLists.txt | 84 | ||||
-rwxr-xr-x | test/CMakeLists.txt | 49 |
3 files changed, 78 insertions, 59 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 328f74c..4e60fd5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,9 +22,11 @@ set(PROJECT_VERSION_PATCH 1) set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} ) 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) add_subdirectory(src) -if(CMARK_TESTS) +if(CMARK_TESTS AND CMARK_SHARED) add_subdirectory(api_test) endif() add_subdirectory(man) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a4dc9f..f52ded6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,11 +54,6 @@ include_directories(. ${CMAKE_CURRENT_BINARY_DIR}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc - DESTINATION lib${LIB_SUFFIX}/pkgconfig) - include (GenerateExportHeader) add_executable(${PROGRAM} ${PROGRAM_SOURCES}) @@ -82,58 +77,75 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") endif () -add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES}) -add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES}) -# Include minor version and patch level in soname for now. -set_target_properties(${LIBRARY} PROPERTIES - OUTPUT_NAME "cmark" - SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} - VERSION ${PROJECT_VERSION}) -set_target_properties(${STATICLIBRARY} PROPERTIES - COMPILE_FLAGS -DCMARK_STATIC_DEFINE - POSITION_INDEPENDENT_CODE ON) - -if (MSVC) - set_target_properties(${STATICLIBRARY} PROPERTIES - OUTPUT_NAME "cmark_static" - VERSION ${PROJECT_VERSION}) -else() - set_target_properties(${STATICLIBRARY} PROPERTIES +if (CMARK_SHARED) + add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES}) + # Include minor version and patch level in soname for now. + set_target_properties(${LIBRARY} PROPERTIES OUTPUT_NAME "cmark" + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} VERSION ${PROJECT_VERSION}) -endif(MSVC) -set_property(TARGET ${LIBRARY} - APPEND PROPERTY MACOSX_RPATH true) + set_property(TARGET ${LIBRARY} + APPEND PROPERTY MACOSX_RPATH true) -# Avoid name clash between PROGRAM and LIBRARY pdb files. -set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark_dll) + # Avoid name clash between PROGRAM and LIBRARY pdb files. + set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark_dll) -generate_export_header(${LIBRARY} + generate_export_header(${LIBRARY} BASE_NAME ${PROJECT_NAME}) + list(APPEND CMARK_INSTALL ${LIBRARY}) +endif() + +if (CMARK_STATIC) + add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES}) + set_target_properties(${STATICLIBRARY} PROPERTIES + COMPILE_FLAGS -DCMARK_STATIC_DEFINE + POSITION_INDEPENDENT_CODE ON) + + if (MSVC) + set_target_properties(${STATICLIBRARY} PROPERTIES + OUTPUT_NAME "cmark_static" + VERSION ${PROJECT_VERSION}) + else() + set_target_properties(${STATICLIBRARY} PROPERTIES + OUTPUT_NAME "cmark" + VERSION ${PROJECT_VERSION}) + endif(MSVC) + + list(APPEND CMARK_INSTALL ${STATICLIBRARY}) +endif() + if (MSVC) set_property(TARGET ${PROGRAM} APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO) endif(MSVC) set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) + include (InstallRequiredSystemLibraries) -install(TARGETS ${PROGRAM} ${LIBRARY} ${STATICLIBRARY} +install(TARGETS ${PROGRAM} ${CMARK_INSTALL} EXPORT cmark RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX} ) -install(FILES - cmark.h - ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h - ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h - DESTINATION include - ) +if(CMARK_SHARED OR CMARK_STATIC) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc + DESTINATION lib${LIB_SUFFIX}/pkgconfig) -install(EXPORT cmark DESTINATION lib${LIB_SUFFIX}/cmake) + install(FILES + cmark.h + ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h + ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h + DESTINATION include + ) + + install(EXPORT cmark DESTINATION lib${LIB_SUFFIX}/cmake) +endif() # Feature tests include(CheckIncludeFile) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2a597ab..6da3a6b 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,9 @@ else(SPEC_TESTS) find_package(PythonInterp 3) endif(SPEC_TESTS) -add_test(NAME api_test COMMAND api_test) +if (CMARK_SHARED) + add_test(NAME api_test COMMAND api_test) +endif() if (WIN32) file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR) @@ -28,15 +30,30 @@ IF (PYTHONINTERP_FOUND) "${CMAKE_CURRENT_SOURCE_DIR}/normalize.py" ) - add_test(spectest_library - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" - "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" - ) - - add_test(pathological_tests_library - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/pathological_tests.py" - "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" - ) + if (CMARK_SHARED) + add_test(spectest_library + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" + "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" + ) + + add_test(pathological_tests_library + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/pathological_tests.py" + "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" + ) + + add_test(roundtriptest_executable + ${PYTHON_EXECUTABLE} + "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip_tests.py" + "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" + "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" + ) + + add_test(entity_executable + ${PYTHON_EXECUTABLE} + "${CMAKE_CURRENT_SOURCE_DIR}/entity_tests.py" + "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" + ) + endif() add_test(spectest_executable ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--program" "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark" @@ -46,13 +63,6 @@ IF (PYTHONINTERP_FOUND) ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/smart_punct.txt" "--program" "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark --smart" ) - add_test(roundtriptest_executable - ${PYTHON_EXECUTABLE} - "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip_tests.py" - "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" - "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" - ) - add_test(regressiontest_executable ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" @@ -60,11 +70,6 @@ IF (PYTHONINTERP_FOUND) "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark" ) - add_test(entity_executable - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/entity_tests.py" - "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src" - ) - ELSE(PYTHONINTERP_FOUND) message("\n*** A python 3 interpreter is required to run the spec tests.\n") |