8000 cmake: use a library target to avoid recompilation · libgit2/libgit2@e352ccb · GitHub
[go: up one dir, main page]

Skip to content

Commit e352ccb

Browse files
author
Edward Thomson
committed
cmake: use a library target to avoid recompilation
Instead of listing the sources separately for the git2 target and the libgit2_clar target, create an "object library" target (for more information, see at https://cmake.org/Wiki/CMake/Tutorials/Object_Library). The object library will then be used to link both the git2 library target and the libgit2_clar target instead of having to compile all the source twice.
1 parent 89c332e commit e352ccb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,11 @@ ELSE()
595595
MESSAGE(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
596596
ENDIF()
597597

598-
# Compile and link libgit2
599-
ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1} ${WIN_RC})
598+
# Compile and link a static version of libgit2; we will use this to link both
599+
# a shared library (unless disabled) and clar.
600+
ADD_LIBRARY(git2-objects OBJECT ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
601+
602+
ADD_LIBRARY(git2 ${WIN_RC} $<TARGET_OBJECTS:git2-objects>)
600603
TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS})
601604
TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS})
602605
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
@@ -614,8 +617,8 @@ ENDIF()
614617
IDE_SPLIT_SOURCES(git2)
615618

616619
IF (SONAME)
617-
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
618-
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION})
620+
# SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
621+
# SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION})
619622
IF (LIBGIT2_FILENAME)
620623
ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
621624
SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
@@ -633,11 +636,11 @@ IF (MSVC_IDE)
633636
ENDIF ()
634637

635638
# Install
636-
INSTALL(TARGETS git2
637-
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
638-
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
639-
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
640-
)
639+
#INSTALL(TARGETS git2
640+
# RUNTIME DESTINATION ${BIN_INSTALL_DIR}
641+
# LIBRARY DESTINATION ${LIB_INSTALL_DIR}
642+
# ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
643+
#)
641644
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
642645
INSTALL(DIRECTORY include/git2 DESTINATION ${INCLUDE_INSTALL_DIR} )
643646
INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} )
@@ -673,7 +676,7 @@ IF (BUILD_CLAR)
673676
${CLAR_PATH}/clar.c
674677
PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite)
675678

676-
ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
679+
ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} $<TARGET_OBJECTS:git2-objects>)
677680

678681
TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS})
679682
TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})

0 commit comments

Comments
 (0)
0