cmakesfmlvcpkg

How to connect tmxlite to cmake SFML project with VCPKG or any other means (Decided)


Decided(Alexander Neumann):

  1. In any directory convenient for you, create a file 'Findtmxlite.cmake'
  2. Write the paths, they may differ with us.

#Findtmxlite.cmake
set(VCPKG_PATH "${USER_PROFILE}/vcpkg")
set(VCPKG_INCLUDE_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/include")
set(VCPKG_LIBRARY_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/lib")

# Set up tmxlite search

# Find path to tmxlite header files
find_path(tmxlite_INCLUDE_DIR NAMES tmxlite/Map.hpp PATHS VCPKG_INCLUDE_DIR)

# Find the tmxlite library
find_library(tmxlite_LIBRARY NAMES tmxlite PATHS VCPKG_LIBRARY_DIR)

# Create an imported target for tmxlite
add_library(tmxlite INTERFACE)

# Specify the path to the tmxlite header files
target_include_directories(tmxlite INTERFACE ${tmxlite_INCLUDE_DIR})

# Link the tmxlite library to the target
target_link_libraries(tmxlite INTERFACE ${tmxlite_LIBRARY})

  1. Add the following line to the project
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "path/to/Findtmxlite.cmake/dir")

After these steps you can use tmxlite in your project

find_package(tmxlite REQUIRED)
add_executable (tester "main.cpp")
target_link_libraries(tester PRIVATE tmxlite)

tmxlite developers please help Severity Code Description Project File String Suppression status CMake Error at C:/Users/Agenteec/vcpkg/scripts/buildsystems/vcpkg.cmake:843 (_find_package): By not providing "Findtmxlite.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "tmxlite", but CMake did not find one.

Could not find a package configuration file provided by "tmxlite" with any of the following names:

tmxliteConfig.cmake tmxlite-config.cmake

Add the installation prefix of "tmxlite" to CMAKE_PREFIX_PATH or set "tmxlite_DIR" to a directory containing one of the above files. If "tmxlite" provides a separate development package or SDK, be sure it has been installed. C:/Users/Agenteec/vcpkg/scripts/buildsystems/vcpkg.cmake 843 Maybe I misspelled the package name. Vcpkg list: tmxlite:x64-windows 1.3.0#1 A lightweight C++14 parsing library for tmx map .. tmxlite:x86-windows 1.3.0#1 A lightweight C++14 parsing library for tmx map ..

find_package(tmxlite REQUIRED)
add_executable (tester "main.cpp")
target_link_libraries(tester PRIVATE tmxlite)
#does not work

set(VCPKG_PATH "${USER_PROFILE}/vcpkg")
set(VCPKG_INCLUDE_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/include")
set(VCPKG_LIBRARY_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/lib")
add_executable (tester "main.cpp")
target_link_libraries(project PRIVATE ${VCPKG_LIBRARY_DIR}/tmxlite.lib)
#does not work

set(VCPKG_PATH "${USER_PROFILE}/vcpkg")
set(VCPKG_INCLUDE_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/include")
set(VCPKG_LIBRARY_DIR "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}/lib")
find_package(tmxlite REQUIRED HINTS "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}")
add_executable (tester "main.cpp")
target_link_libraries(project PRIVATE tmxlite)
#does not work


Solution

  • You need to write your own Find<Module>.cmake for tmxlite since it neither install pkg-config files nor cmake files.

    In the Find<Module>.cmake you need to do the following:

    (and no you don't need any vcpkg specific hacks here.)