I've next project tree:
>googletest
>libgit2
>src
>tests
The code in main CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(project_name)
add_subdirectory(src)
add_subdirectory(tests)
The code CMakeLists.txt in src folder:
cmake_minimum_required(VERSION 2.8)
project(project_name)
set(libgit2_src ../libgit2/src)
include_directories(../libgit2 ../libgit2/include)
add_library(gitlib STATIC ${libgit2_src})
add_executable(project_name main.cpp)
target_link_libraries(project_name gitlib)
When I attempting to generate the project, I'm getting next error:
CMake Error: CMake can not determine linker language for target: gitlib
How correctly to build and include library libgit2 in my project?
EDIT
In main CMakeLists.txt I've added next command:
cmake_minimum_required(VERSION 2.8)
project(project_name)
add_subdirectory(libgit2)
add_subdirectory(src)
add_subdirectory(tests)
After, I've changed the code CMakeLists.txt in src folder:
cmake_minimum_required(VERSION 2.8)
project(project_name)
pkg_check_modules(LIBGIT2 REQUIRED libgit2)
set(LIBGIT2_LIBS_ABSOLUTE)
foreach(lib ${LIBGIT2_LIBRARIES})
# Choose name of variable, which will contain result of `find_library`
# for specific library.
set(var_name LIBGIT2_${lib}_ABS)
# Search library under dirs, returned by pkg-config.
find_library(${var_name} ${lib} ${LIBGIT2_LIBRARY_DIR})
list(APPEND LIBGIT2_LIBS_ABSOLUTE ${${var_name}})
endforeach()
include_directories(${LIBGIT2_INCLUDE_DIRS})
add_executable(project_name main.cpp)
target_link_libraries(project_name ${LIBGIT2_LIBS_ABSOLUTE})
But when I configuring the project, I'm getting the error:
CMake Error at D:/Program/CMake/share/cmake-3.10/Modules/FindPkgConfig.cmake:590 (if):
if given arguments:
"NOT" "DEFINED" "__pkg_config_checked_LIBGIT2" "OR" "__pkg_config_checked_LIBGIT2" "LESS" "OR" "NOT" "LIBGIT2_FOUND" "OR" "(" "NOT" "libgit2" "STREQUAL" "" "AND" "NOT" "" "STREQUAL" "REQUIRED;libgit2" ")" "OR" "(" "libgit2" "STREQUAL" "" "AND" "NOT" "" "STREQUAL" "REQUIRED" ")"
Unknown arguments specified
Call Stack (most recent call first):
src/CMakeLists.txt:5 (pkg_check_modules)
I do not understand how correctly to link and build this library to my project.
EDIT2 I've built library libgit2 separately. After, I've changed the main CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(project_name)
add_subdirectory(src)
add_subdirectory(tests)
Also, I've changed CMakeLists.txt in src folder:
cmake_minimum_required(VERSION 3.10)
project(project_name)
add_executable(project_namemain.cpp)
target_include_directories(project_name PUBLIC ../libgit2/include)
target_link_libraries(project_name ../libgit2/build/Debug/git2)
I'm getting the project that configures and generate normally. But when I starting build project I get the error:
fatal error LNK1104: cannot open file 'libgit2/build/Debug/git2.lib'
How to fix this error? I've tried different ways fix this error, but nothing succeeded.