How to make cmake finden eine shared-library in einem Unterordner

Ich versuche zu lernen, wie man eine gemeinsam genutzte Bibliothek. Und das folgende scheint zu funktionieren (bitte kommentieren, wenn Sie haben ein feedback zu dieser Methode, der ich im Grunde keine Ahnung, was ich mache).

In "meine Bibliothek" - Projekt, ich habe die header-Dateien in einen Ordner namens "include", und die source-Dateien in "src".

Meine Bibliothek CMakeLists.txt:

cmake_minimum_required(VERSION 2.4.0)

project(mycustomlib)

# Find source files
file(GLOB SOURCES src/*.cpp)

# Include header files
include_directories(include)

# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES})

# Install library
install(TARGETS ${PROJECT_NAME} DESTINATION lib)

# Install library headers
file(GLOB HEADERS include/*.h)
install(FILES ${HEADERS} DESTINATION include)

Meine Anwendung CMakeLists.txt:

cmake_minimum_required(VERSION 2.4.0)

project(myprogram)

# Find source files
file(GLOB SOURCES src/*.cpp)

# Create executable
add_executable(${PROJECT_NAME} ${SOURCES})

# Find and link library
find_library(MYCUSTOMLIB mycustomlib)
target_link_libraries(${PROJECT_NAME} ${MYCUSTOMLIB})

Und das ist arbeiten. Das problem ist, dass ich möchte sowohl den Header und die Bibliothek in Unterordner (speziell: /usr/local/include/mycustomlib/ für die Header, und die /usr/local/lib/mycustomlib/ für die Bibliothek).

Dies ist also mein Versuch:

Meine Bibliothek ist neu CMakeLists.txt:

cmake_minimum_required(VERSION 2.4.0)

project(mycustomlib)

# Find source files
file(GLOB SOURCES src/*.cpp)

# Include header files
include_directories(include)

# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES})

# Install library
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})

# Install library headers
file(GLOB HEADERS include/*.h)
install(FILES ${HEADERS} DESTINATION include/${PROJECT_NAME})

Meine Anwendung neuer CMakeLists.txt:

cmake_minimum_required(VERSION 2.4.0)

project(myprogram)

# Find source files
file(GLOB SOURCES src/*.cpp)

# Create executable
add_executable(${PROJECT_NAME} ${SOURCES})

# Find and link library
find_library(MYCUSTOMLIB mycustomlib/mycustomlib)
target_link_libraries(${PROJECT_NAME} ${MYCUSTOMLIB})

Und das ist nicht arbeiten. Nun, ich bin gezwungen, angeben .so-Datei der Bibliothek, wie diese:

find_library(MYCUSTOMLIB mycustomlib/libmycustomlib.so)

Wie kommt das?

InformationsquelleAutor gromit190 | 2016-07-01
Schreibe einen Kommentar