D
D
dearname2016-01-31 14:07:47
C++ / C#
dearname, 2016-01-31 14:07:47

How to include static libraries in cmake?

Good afternoon. There is such a project structure:
project
src/
class1.cpp
class2.cpp
include/
class1.h
class2.h
and there is also a library consisting of two header files, which is in ubuntu in the usr/include/ folder. Couldn't connect, its ok in cmake. The files themselves are read by cmake, but how else to add this library to them.
here is my code, what lines should I add correctly to add the library?

cmake_minimum_required(VERSION 2.8.9)
project(directory_test)

include_directories(include)

file(GLOB SOURCES "src/*.cpp")

include_directories(~/usr/include)

add_executable(testStudent ${SOURCES})

target_link_libraries(libtest ${PROJECT_LINK_LIBS} )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2016-02-01
@SaNNy32

It can be so. This is to add the library as a separate project

FILE(
    GLOB
    LIBRARY_INCLUDE_FILES
    ~/usr/include/*.h
)
FILE(
    GLOB
    LIBRARY_SRC_FILES
    ~/usr/include/*.cpp
)
ADD_LIBRARY(
  ${LIBRARY_NAME}
  STATIC
  ${LIBRARY_SRC_FILES}
  ${LIBRARY_INCLUDE_FILES}
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question