summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-01-06 13:55:01 +0100
committerGitHub <noreply@github.com>2017-01-06 13:55:01 +0100
commit3894dbddbf4142748bc0dd72c5460b860dd8b5ef (patch)
tree681a8b3b3b6b57cf67c223eee61716b94df732ff /src
parentc786cacc291418d68b52636f951af778fefa214f (diff)
parentc9c18fff2fd8b3d0bef0120fe3db3b6ab0beeb9b (diff)
Merge pull request #179 from winterheart/cmake
CMake impovement
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt97
1 files changed, 50 insertions, 47 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0cb6530..f52ded6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -49,25 +49,11 @@ set(PROGRAM_SOURCES
main.c
)
-# We make LIB_INSTALL_DIR configurable rather than
-# hard-coding lib, because on some OSes different locations
-# are used for different architectures (e.g. /usr/lib64 on
-# 64-bit Fedora).
-if(NOT LIB_INSTALL_DIR)
- set(LIB_INSTALL_DIR "lib" CACHE STRING
- "Set the installation directory for libraries." FORCE)
-endif(NOT LIB_INSTALL_DIR)
-
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_INSTALL_DIR}/pkgconfig)
-
include (GenerateExportHeader)
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
@@ -91,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_INSTALL_DIR}
- ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+ 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_INSTALL_DIR}/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)