I came to a problem that I do not understand why this works in such a ways. I am linking static libraries, specially libgmp-10 and libmpfr-4. These are static libraries from CGAL.
This does not work:
list(APPEND petras_include_paths
#cgal
"${CMAKE_BINARY_DIR}/install/cgal/include"
"${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/include"
"${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib"
#"C:/msys64/mingw64/lib/" #GCC
)
target_include_directories(${PROJECT_NAME} PRIVATE "$<BUILD_INTERFACE:${petras_include_paths}>") #header for the library
target_link_libraries(${PROJECT_NAME} PRIVATE
libgmp-10
libmpfr-4
)
This works:
target_link_libraries(${PROJECT_NAME} PRIVATE
"${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib/libgmp-10.lib"
"${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib/libmpfr-4.lib"
)
Why? I thought that target_include_directories add the path to libraries, so that in target_link_libraries I should only need to specify the name of the library, not the full path.
CodePudding user response:
Absolute paths should NEVER appear in CMakeLists.txt
.
Proper way to do it is:
find_package(CGAL)
...
target_link_libraries(${PROJECT_NAME} CGAL::CGAL)
As it is documented.
cgal
should be just properly installed on a system.
CodePudding user response:
target_include_directories
adds #include
directories, not library search paths. target_link_directories
adds link directories.
Before proceeding, you might want to read https://doc.cgal.org/latest/Manual/devman_create_and_use_a_cmakelist.html