I am developing a static library and I am using CMake. This library needs Boost. So I did the following:
set(LIBRARY_NAME "MyLib")
set(LIBRARY_VERSION 1.0.0)
project(${LIBRARY_NAME} VERSION ${LIBRARY_VERSION})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS system filesystem regex thread date_time log log_setup REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
add_library(${LIBRARY_NAME} STATIC xx.cpp)
target_link_libraries(${LIBRARY_NAME} PUBLIC ${Boost_LIBRARIES})
Everything is fine till now.
Now, I need to make this library install-able. So, I follow this tutorial https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
Everything looks fine on my machine. However, when I moved the installed files (The files that are generated by calling make-install) into another machine and tried to use it using find_package(MyLib), problem raised saying that it could find boost in the in a place supposed to be on my original machine. I dig into the file MyLibTargets.cmake and I saw absolute paths of Boost library!
Why this is happining? how can I prevent this?