I want to build a project that uses OpenCascade. I also want to build all the libraries. It depends on freetype, tcl and tk. So I want to build all these, too. I'm struggling with how to do it properly. I'm using Windows, if that matters. So, before I start fiddling around with trial/error just to get it somehow working, I'd like to ask what's the "proper" way to do this using QtCreator and CMake. Assume, my toolchain(s) are set up properly to build Qt applications.
Assume my sub-folder structure is a fresh download of the libraries:
mylibrary/main.cpp occt-7_8_0/ freetype-2.10.4/ tcl8.5.0/ tk8.5.0/ I don't want to use VTK and my main.cpp might look like:
#include #include
void makeBox(){ gp_Pnt gp1(0,0,0); gp_Pnt gp2(1,1,1); TopoDS_Solid box = BRepPrimAPI_MakeBox(gp1, gp2).Solid(); } And the CMakesList.txt of mylibrary/ is
message("=== Occt wrapper as a lib ===") add_library(mylibrary_lib SHARED) if (CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-Wa,-mbig-obj) endif() if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif() # find_package() uses Config.cmake-file in _DIR path find_package(OpenCASCADE REQUIRED) target_include_directories(mylibrary_lib PRIVATE "${OpenCASCADE_INCLUDE_DIR}") # OCC is needed if(NOT OpenCASCADE_FOUND) message(FATAL_ERROR "Cannot build the executable without OpenCASCADE. Please set the variable OpenCASCADE_DIR.") else() message(" found OpenCASCADE " ${OpenCASCADE_VERSION}) # include target_include_directories(mylibrary_lib PUBLIC ${OpenCASCADE_INCLUDE_DIR}) message(" found OpenCASCADE_INCLUDE_DIR: ${OpenCASCADE_INCLUDE_DIR}" ) # link target_link_libraries(mylibrary_lib PUBLIC ${OpenCASCADE_LIBRARIES}) # This should be private! message(" found OpenCASCADE_LIBRARIES: ${OpenCASCADE_LIBRARIES}" ) endif() target_sources(mylibrary_lib PUBLIC "./main.cpp") UPDATE: I try to use vcpkg as suggested. Here's what I did:
-
Install vcpkg: https://learn.microsoft.com/de-de/vcpkg ... =shell-cmd
Follow Step 1 "Set up vcpkg" - Find and remember the path to the vcpkg folder.
- Open a CMD in that folder.
- Install opencascade package by typing: vcpkg --install opencascade
Setup QtCreator
- Install and activate the plugin "Vcpkg"
-
Go to the meun Edit/Preferences/CMake
Under the tab Vcpkg: Browse for the path of the vcpkg directory - Under the tab General: Check the option "Package manager auto setup"
Restart QtCreator
[*]
make vcpkg.json in src directory of the library which reads:
{ "dependencies": [ "opencascade", "freetype", "tcl", "tk" ] } [*]Or use the wizzard in QtCreator: https://doc.qt.io/qtcreator/creator-how ... files.html
[*]
In the CMakesList.txt add: find_package(OpenCASCADE CONFIG REQUIRED)
Then I cleand the project and clicked "Run CMake". The output is, however:
Could not find a package configuration file provided by "opencascade" with any of the following names: opencascadeConfig.cmake opencascade-config.cmake Add the installation prefix of "opencascade" to CMAKE_PREFIX_PATH or set "opencascade_DIR" to a directory containing one of the above files. If "opencascade" provides a separate development package or SDK, be sure it has been installed. The CMakeCache.txt contains
//Value Computed by CMake. CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=C:/path/to/build/build-projectname-Desktop_Qt_5_15_2_MSVC2015_64bit-Debug/CMakeFiles/pkgRedirects This folder, however is empty.
Источник: https://stackoverflow.com/questions/781 ... sing-cmake