How do I install a package (consisting of .h and .lib .dll) with CMake?

213 Views Asked by At

I was provided a package which was released with .h .dll and .lib. Now, I'm trying to integrate this package into my cpp project with CMake.

I came along using the packetmanager vcpkg, so I tried adding this package to vcpkg by creating a port. Essentially, this port checks out a GitHub repository with vcpkg_from_github and installs the library with vcpkg_cmake_install.

So I created a GitHub repo containing only the .h .dll and .lib and a CMakeLists.txt, which (from my understanding) should install the binary and include files of the repository the moment vcpkg_cmake_install is called.

Now my question is what this CMakeLists.txt should look like. My arbitary try of this CMakeLists.txt:

cmake_minimum_required (VERSION 3.17)
project(medit-libs CXX)  

add_library(pcanbasic STATIC IMPORTED)
set_target_properties(pcanbasic PROPERTIES
    IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/lib/PCANBasic.lib"
)

target_include_directories(pcanbasic INTERFACE "{CMAKE_CURRENT_LIST_DIR}/include")

include(GNUInstallDirs)

install(TARGETS pcanbasic
    EXPORT pcanbasic-targets
    ARCHIVE DESTINATION lib
    INCLUDES DESTINATION include
)
install(EXPORT pcanbasic-targets
    FILE pcanbasic-targets.cmake
    NAMESPACE pcanbasic::
    DESTINATION lib/cmake/pcanbasic 
)
install(FILES pcanbasic.h
    DESTINATION include
)

failed.

Can anyone tell me

  1. if the approach I'm doing to integrate the library into my external project is correct/optimal
  2. what the CMakeLists.txt should actually look like?

I'm also happy to take other solutions integrating my library files into a CMake managed project.

0

There are 0 best solutions below