10000 cmake: only create target obj lib on new enough cmakes · libgit2/libgit2@db16c5e · GitHub
[go: up one dir, main page]

Skip to content

Commit db16c5e

Browse files
author
Edward Thomson
committed
cmake: only create target obj lib on new enough cmakes
1 parent 07f7b30 commit db16c5e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,27 @@ ENDIF()
602602

603603
SET(SRC_LIBGIT2 ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
604604

605-
# Compile the objects that make up our library; we will create an actual
606-
# shared/static library with them later.
607-
ADD_LIBRARY(git2_src OBJECT ${SRC_LIBGIT2})
608-
IDE_SPLIT_SOURCES(git2_src)
605+
# On a sufficiently new cmake, we can compile the objects that make up our
606+
# library as a separate target (without needing to link a library or an
607+
# executable). This will satisfy the dependency for our tests, and saves
608+
# us from having to recompile them.
609+
IF (${CMAKE_VERSION} VERSION_GREATER 2.8.7)
610+
ADD_LIBRARY(git2_src OBJECT ${SRC_LIBGIT2})
611+
IDE_SPLIT_SOURCES(git2_src)
612+
613+
SET(SRC_LIBGIT2 $<TARGET_OBJECTS:git2_src>)
614+
ENDIF()
609615

610616
# Compile and link libgit2
611-
ADD_LIBRARY(git2 $<TARGET_OBJECTS:git2_src> ${WIN_RC})
617+
ADD_LIBRARY(git2 ${SRC_LIBGIT2} ${WIN_RC})
612618
TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS})
613619
TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS})
614620
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
615621
TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES})
616622
TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES})
617623
TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES})
618624
TARGET_OS_LIBRARIES(git2)
625+
IDE_SPLIT_SOURCES(git2)
619626

620627
# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
621628
# Win64+MSVC+static libs = linker error
@@ -685,7 +692,7 @@ IF (BUILD_CLAR)
685692
${CLAR_PATH}/clar.c
686693
PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite)
687694

688-
ADD_EXECUTABLE(git2_tests ${SRC_CLAR} ${SRC_TEST} $<TARGET_OBJECTS:git2_src>)
695+
ADD_EXECUTABLE(git2_tests ${SRC_CLAR} ${SRC_TEST} ${SRC_LIBGIT2})
689696

690697
TARGET_LINK_LIBRARIES(git2_tests ${COREFOUNDATION_DIRS})
691698
TARGET_LINK_LIBRARIES(git2_tests ${SECURITY_DIRS})

0 commit comments

Comments
 (0)
0