I have tried to use QHull and libqhullcpp as an external project in CMake, but I was not successful.
So far I've used these commands which is a modified version of this:
include(ExternalProject)
ExternalProject_add(qhull
GIT_REPOSITORY "https://github.com/qhull/qhull.git"
GIT_TAG "2019.1"
GIT_PROGRESS TRUE
SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/qhull
BINARY_DIR ${CMAKE_BINARY_DIR}/thirdparty-build/qhull
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/thirdparty-install"
CMAKE_CACHE_ARGS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true"
)
### qhullstatic reentrant library
add_library(libqhullstatic_r STATIC IMPORTED)
set_property(TARGET libqhullstatic_r PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/${CMAKE_STATIC_LIBRARY_PREFIX}qhullstatic_r${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET libqhullstatic_r PROPERTY IMPORTED_LOCATION_DEBUG ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/Debug/${CMAKE_STATIC_LIBRARY_PREFIX}qhullstatic_r${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET libqhullstatic_r PROPERTY IMPORTED_LOCATION_RELEASE ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/Release/${CMAKE_STATIC_LIBRARY_PREFIX}qhullstatic_r${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(libqhullstatic_r qhull)
### qhullcpp library
add_library(libqhullcpp STATIC IMPORTED)
set_property(TARGET libqhullcpp PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/${CMAKE_STATIC_LIBRARY_PREFIX}qhullcpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET libqhullcpp PROPERTY IMPORTED_LOCATION_DEBUG ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/Debug/${CMAKE_STATIC_LIBRARY_PREFIX}qhullcpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET libqhullcpp PROPERTY IMPORTED_LOCATION_RELEASE ${CMAKE_BINARY_DIR}/thirdparty-build/qhull/Release/${CMAKE_STATIC_LIBRARY_PREFIX}qhullcpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET libqhullcpp PROPERTY INTERFACE_LINK_LIBRARIES libqhullstatic_r)
add_dependencies(libqhullcpp qhull)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${libqhullcpp})
My project cannot find any file of the Qhull code and if I add
#include <libqhullcpp/Qhull.h>
orgQhull::Qhull qhull;
to my project it will throw this compile error:
CMakeFiles/MyProject.dir/src/main.cpp.o: In function `main':
~/MyProject/src/main.cpp:108: undefined reference to `orgQhull::Qhull::Qhull()'
~/MyProject/src/main.cpp:108: undefined reference to `orgQhull::Qhull::~Qhull()'
~/MyProject/src/main.cpp:108: undefined reference to `orgQhull::Qhull::~Qhull()'
collect2: error: ld returned 1 exit status
CMakeFiles/MyProject.dir/build.make:83: recipe for target 'MyProject' failed
make[3]: *** [MyProject] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/MyProject.dir/all' failed
make[2]: *** [CMakeFiles/MyProject.dir/all] Error 2
CMakeFiles/Makefile2:111: recipe for target 'CMakeFiles/MyProject.dir/rule' failed
make[1]: *** [CMakeFiles/MyProject.dir/rule] Error 2
Makefile:131: recipe for target 'MyProject' failed
make: *** [MyProject] Error 2
I've modified your
CMakeLists.txt
file and done some optimization, so you don't build in source. Mytree
gives this:with
CMakeLists.txt
:and
CMakeLists.txt.in
contents this:If you
cd build && cmake ../QHull
, it'll download and start building qhull for you.The only drawback: the
ExternalProjects
keep the${CMAKE_SOURCE_DIR}\QHull\src
asINCLUDE_DIRECTORIES
instead of the needed${CMAKE_BINARY_DIR}\qhull-src\src
.As I couldn't fix this, my work-around is to replace
-I${CMAKE_SOURCE_DIR}\QHull\src
with-I${CMAKE_SOURCE_DIR}\QHull\src
in the generator script (e.g.build.ninja
in my case) after cmake configure step.After that, I was able to build my own example
main.cpp
.