Build zLib with CMake - c++

I'm trying to build Zlib and quazip automatic with the rest of my project. I want to do it in a similar way as I add googletest to my project.
zLib and Quazip shall be linked static to my App.
I want to to this because of CI/ CD reasons and if somebody else wants to build the project he do not have to worry about those dependencies (especially under windows)...
Download it at configure time with CMake ExternalProject_Add
add it on target level
My structure is like the following:
project/
├── CMakelists.txt (1)
├── sources/
│ ├── APP/
│ │ ├── CMakeLists.txt (2)
│ │ ├── thirdparty/
│ │ │ ├── CMakeLists.txt (3)
│ │ │ ├── zlib
│ │ │ │ ├── CMakeLists.txt.in
│ │ │ ├── quazip
│ │ │ │ ├── CMakeLists.txt.in
│ │ │ │ ├── CMakeListsBuild.txt.in
Thats complicated enough but let me show you what I do where...
(1) CMakeLists.txt
Noting special just adding all the packages together like APP
(2) CMakeLists.txt
cmake_minimum_required(VERSION 3.15.2)
project(Project VERSION 0.0.1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#Add the needed Qt Components
find_package(Qt5 COMPONENTS
Core
Network
REQUIRED)
add_subdirectory(thirdparty)
SET(INCLUDES
...
)
SET(SOURCES
...
)
target_compile_options(${PROJECT_NAME} PUBLIC
...
)
target_compile_definitions(${PROJECT_NAME} PUBLIC
QUAZIP_STATIC )
target_include_directories(${PROJECT_NAME} PRIVATE
OtherIncludes
"${QUAZIP_INCLUDE_DIR}"
)
target_link_libraries(${PROJECT_NAME}
Qt5::Network
Qt5::Core
SomeOtherDep
quazip_static <---- adding static targets here
zlibstatic <---- adding static targets here
)
(3) CMakeLists.txt
# Download and unpack at configure time
configure_file(zlib/CMakeLists.txt.in zlib-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/zlib-download"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/zlib-download"
)
add_subdirectory("${CMAKE_BINARY_DIR}/zlib-src"
"${CMAKE_BINARY_DIR}/zlib-build"
)
# Download and unpack at configure time
configure_file(quazip/CMakeLists.txt.in quazip-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/quazip-download"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/quazip-download"
)
configure_file(quazip/CMakeListsBuild.txt.in ${CMAKE_BINARY_DIR}/quazip-src/CMakeLists.txt COPYONLY)
add_subdirectory("${CMAKE_BINARY_DIR}/quazip-src"
"${CMAKE_BINARY_DIR}/quazip-build"
)
set(QUAZIP_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/quazip-src/quazip" PARENT_SCOPE)
The two CMakeLists.txt.in have nearly the same Content...
cmake_minimum_required(VERSION 2.8.2)
include(ExternalProject)
project(quazip-download NONE)
ExternalProject_Add(quazip
GIT_REPOSITORY git://github.com/stachenov/quazip.git
GIT_TAG v0.8.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/quazip-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/quazip-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
cmake_minimum_required(VERSION 2.8.2)
include(ExternalProject)
project(zlib-download NONE)
ExternalProject_Add(zlib
GIT_REPOSITORY git://github.com/madler/zlib.git
GIT_TAG v1.2.11
SOURCE_DIR "${CMAKE_BINARY_DIR}/zlib-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/zlib-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Then there is the last CMakeListsBuild.txt.in in the quazip folder. I'm just editing the original one and feed the zlib dependencies directly in. It looks like this:
cmake_minimum_required(VERSION 2.6)
project(QuaZip)
...
EVERYTHING ORIGINAL
...
# Use system zlib on unix and Qt ZLIB on Windows
# will be set from outside ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS
--------------------ADDED BY ME REMOVED find_packages...
set(ZLIB_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/zlib-src
${CMAKE_BINARY_DIR}/zlib-build)
if(UNIX)
set(ZLIB_LIBRARIES
"${CMAKE_BINARY_DIR}/zlib-build/libz.a")
elseif(MINGW)
set(ZLIB_LIBRARIES
"${CMAKE_BINARY_DIR}/zlib-build/libzlibstatic.a")
endif()
...
EVERYTHING ORIGINAL
...
Question
Downloading and building the static lib of zlib works but I get the following error while compiling under linux.
/home/linuxmint/someDirectory/build/zlib-src/test/example.c:8:10: fatal error: zlib.h: No such file or directory
#include "zlib.h"
^~~~~~~~
compilation terminated.
zlib-build/CMakeFiles/example.dir/build.make:75: recipe for target 'zlib-build/CMakeFiles/example.dir/test/example.o' failed
make[2]: *** [zlib-build/CMakeFiles/example.dir/test/example.o] Error 1
CMakeFiles/Makefile2:1355: recipe for target 'zlib-build/CMakeFiles/example.dir/all' failed
make[1]: *** [zlib-build/CMakeFiles/example.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
This is the strange part I dont understand. If I have a look in the CMakeLists of zlib. (LINK)
They add everything of of the source and binary folder to the include with this:
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
So I don't understand why the example of zlib (and everything else which need zlib.h) can't be build...
Perhabs somebody has a hint...
Thanks...
Edit
If I install the headers with apt building works... But why ;) Since nowhere find_package is called...

Thanks to #squarekittles who pointed me in the right direction.
In the CMakeLists.txt of zlib the include dir is specified as ${CMAKE_SOURCE_DIR}. This is of course the wrong directory...
I added a additional CMakeLists.txt.in for zlib which will replace the original one. It's all the same only two lines are different:
...
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
^~~~~~~~~~~~~ Added in
#============================================================================
# zlib
#============================================================================
set(ZLIB_PUBLIC_HDRS
${CMAKE_CURRENT_BINARY_DIR}/zconf.h
${CMAKE_CURRENT_SOURCE_DIR}/zlib.h
) ^~~~~~~~~~~~~ Added in
...
Now the examples compile...
Also I needed to add the headers of zlib to my project did it by editing CMakeLists.txt (3)
...
configure_file(zlib/CMakeListsBuild.txt.in ${CMAKE_BINARY_DIR}/zlib-src/CMakeLists.txt COPYONLY) <--- Replacing CMakeLists.txt for zlib
...
set(QUAZIP_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/quazip-src/quazip"
${ZLIB_INCLUDE_DIR} PARENT_SCOPE)
^~~~~~~~~~~~ Added in
...

Related

CMake warning: CMake Targets may link only to libraries. CMake is dropping the item [duplicate]

This question already has answers here:
Understanding "requests linking to directory" cmake warning
(1 answer)
CMake link to external library
(6 answers)
Closed 10 months ago.
I am making an anpr algorithm that requires tesseract to decode the image to text. When running cmake .. inside my build dir, I get a warning saying:
┌──(user㉿MacBookArch)-[~/dev/anpr/build]
└─$ cmake ..
-- Configuring done
CMake Warning at CMakeLists.txt:15 (target_link_libraries):
Target "main" requests linking to directory
"/home/user/dev/anpr/build/libs/leptonica". Targets may link only to
libraries. CMake is dropping the item.
CMake Warning at CMakeLists.txt:16 (target_link_libraries):
Target "main" requests linking to directory
"/home/user/dev/anpr/build/libs/tesseract". Targets may link only to
libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /home/user/dev/anpr/build
This leads me into the thoughts that I have made something wrong. I have copied the repos for leptonica and tesseract into the libs directory for portability.
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.2.2)
project( ANPR )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
include_directories(${PROJECT_SOURCE_DIR}/libs/tesseract/include)
include_directories(${PROJECT_SOURCE_DIR}/libs/leptonica/include)
link_directories(${PROJECT_SOURCE_DIR}/libs/tesseract)
link_directories(${PROJECT_SOURCE_DIR}/libs/leptonica)
add_executable( main src/main.cpp )
target_link_libraries( main ${OpenCV_LIBS} )
target_link_libraries( main ${CMAKE_CURRENT_BINARY_DIR}/libs/leptonica)
target_link_libraries( main ${CMAKE_CURRENT_BINARY_DIR}/libs/tesseract)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/samples/001.jpg
${CMAKE_CURRENT_BINARY_DIR}/samples/001.jpg
COPYONLY
)
and this is my project structure:
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── LeptonicaTargets.cmake
│ ├── libs
│ ├── main
│ ├── Makefile
│ └── samples
├── CMakeLists.txt
...
├── include
│ └── main.hpp
├── libs
│ ├── leptonica
│ └── tesseract
...
├── samples
│ └── 001.jpg
└── src
└── main.cpp
The contents of the build dir is auto generated with cmake.
make command inside the build dir goes fine without errors even after make clean:
┌──(user㉿MacBookArch)-[~/dev/anpr/build]
└─$ make
[ 50%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
[100%] Linking CXX executable main
[100%] Built target main
How can I resolve this warning? I am open to all improvements, thank you!

Generate grpc files for a library target in CMAKE

In the following project structure(from my previous question):
root/
├─ CMakeLists.txt
├─ protocol/
│ ├─ msg.proto
│ ├─ myrpc.proto
│ ├─ CMakeLists.txt
├─ app/
│ ├─ main.cpp
│ ├─ CMakeLists.txt
I could generate the protobuf files and add them as dependency into the app target. Now I am trying to generate grpc files inside the same library.
Something is not right with the grpc generation function, which is based on this answer and blog post;as the following error message is printed:
-- Configuring done
-- Generating done
-- Build files have been written to: /media/davids91/Work/rafko/src/main/cxx/build
[ 1%] Running grpc protocol buffer compiler on /usr/local/bin/grpc_cpp_plugin
/usr/local/bin/grpc_cpp_plugin: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
make[2]: * [protocol/CMakeFiles/protocol.dir/build.make:138: /media/usr/local/bin/grpc_cpp_plugin.grpc.pb.h] Error 1
make[1]: * [CMakeFiles/Makefile2:276: protocol/CMakeFiles/protocol.dir/all] Error 2
make: * [Makefile:103: all] Error 2
I can see that the install folder looks correct, as that is where the grpc library was installed from source.
root CMakeLists.txt:
cmake_minimum_required(VERSION 3.18.4)
project(
root
VERSION 0.1
LANGUAGES CXX
)
add_subdirectory(protocol)
add_subdirectory(app)
protocol CMakeLists.txt:
add_library(protocol)
target_include_directories(protocol
PUBLIC
.
${CMAKE_CURRENT_BINARY_DIR}
${Protobuf_INCLUDE_DIRS}
)
find_package(Protobuf REQUIRED)
find_package(gRPC CONFIG REQUIRED)
target_link_libraries(protocol ${Protobuf_LIBRARIES})
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
protobuf_generate( TARGET protocol LANGUAGE CPP PROTOS msg.proto )
protobuf_generate(
TARGET
protocol
LANGUAGE
grpc
PROTOS
myrpc.proto
PLUGIN
"protoc-gen-grpc=${grpc_cpp_plugin_location}"
)
app CMakeLists.txt:
add_library(app)
target_link_libraries(app PUBLIC protocol)
target_include_directories(app PUBLIC .)
target_sources(app
PRIVATE
main.cpp
)
What might be missing from this solution to generate out the grpc files based on the plugins?
After some experimenting and closely looking at the example here I figured it out!
I updated protocol CMakeLists.txt:
changed
find_package(Protobuf REQUIRED)
to
find_package(Protobuf CONFIG REQUIRED)
I figure it tells CMake that the proto files are being procesed at configuration time, but any deeper explanation is welcome!

CMake No such file or directory

I have a problem building my Qt5 project via cmake.
I run the command cmake .. && make from the directory build and I receive the following error:
/usr/bin/ld: cannot find -lengine-lib
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/blacklist-engine-cli.dir/build.make:102: src/blacklist-engine-cli] Error 1
make[1]: *** [CMakeFiles/Makefile2:117: src/CMakeFiles/blacklist-engine-cli.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I have searched this topic briefly, however when I ran this project without Qt5Sql, using only Qt5Core I have no problem at all building the project. In order to build the project without Qt5Sql I just have to remove the db folder, and delete lines referring to that in my other CMakeLists.txt files. My question is:
Why does it work if I want to include only Qt5Core, and why does it not work when I also include Qt5Sql? What am I doing wrong including Qt5Sql?
Please do not include answers related to QtCreator, or Qt installation errors. I have checked my Qt installation folder, and I have Qt5Core and Qt5Sql on the same directory level installed.
I am using Ubuntu 20.04, cmake version 3.16.3, Qt version 5.12.8
ls /usr/lib/x86_64-linux-gnu/cmake
Qt5 Qt5Core Qt5Gui Qt5OpenGL Qt5PrintSupport Qt5Test Qt5Xml
Qt5Concurrent Qt5DBus Qt5Network Qt5OpenGLExtensions Qt5Sql Qt5Widgets
I have the following structure in my project:
root
├── CMakeModules
│ └── Qt.cmake
├── build
├── src
│ ├── db
│ │ ├── dbmanager.cpp
│ │ ├── dbmanager.h
│ │ └── CMakeLists.txt
│ ├── engine
│ │ ├── scanner.cpp
│ │ ├── scanner.h
│ │ └── CMakeLists.txt
│ ├── CMakeLists.txt
│ └── main.cpp
└── CMakeLists.txt
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(blacklist-engine)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
add_subdirectory(src)
CMakeModules/Qt.cmake:
set(CMAKE_AUTOMOC ON)
find_package(Qt5 REQUIRED COMPONENTS Core Sql)
src/CMakeLists.txt:
include(Qt)
add_subdirectory(
db
engine
)
add_executable(blacklist-engine-cli main.cpp)
target_link_libraries(
blacklist-engine-cli
Qt5::Core
Qt5::Sql
engine-lib
db-lib
)
src/main.cpp:
#include <QtCore>
#include "db/dbmanager.h"
#include "engine/scanner.h"
...
src/db/CMakeLists.txt (updated):
set (db-lib-source
dbmanager.h
dbmanager.cpp
)
add_library(db-lib ${db-lib-source})
target_link_libraries(
db-lib
Qt5::Sql
)
src/db/dbmanager.h:
#include <QtSql/QSqlDatabase>
...
src/db/dbmanager.cpp:
#include "dbmanager.h"
#include <QtSql/QSqlQuery>
...
src/engine/CMakeLists.txt:
set(engine-lib-source
scanner.h
scanner.cpp
)
add_library(engine-lib ${engine-lib-source})
src/engine/scanner.h:
#include <QtCore>
...
src/engine/scanner.cpp:
#include "scanner.h"
...
The reason for the error is because engine-lib is never built, and its CMake file is never even processed. The offending line in your CMake file is this one:
add_subdirectory(
db
engine
)
When using add_subdirectory in this manner, the second argument becomes the binary directory for the generated content related to db. As a result, you may notice that CMake placed some build artifacts in your src/engine directory, which is probably not what you want.
To fix this, you must call add_subdirectory consecutive times for including multiple sub-directories.
add_subdirectory(db)
add_subdirectory(engine)

Creating and using a static library with CMake

I am trying to first create a static library and then link it to an executable using CMake. My project file structure looks like this:
├── CMakeLists.txt
├── build
├── lib
│   ├── CMakeLists.txt
│   ├── build
│   ├── include
│   │   └── Point.hpp
│   └── src
│   └── Point.cpp
└── mainApp.cpp
I first build the library like so.
cmake_minimum_required(VERSION 2.8.9)
project(CAST3)
set(CMAKE_BUILD_TYPE Release)
include_directories(include)
file(GLOB SOURCES "src/*.cpp")
add_library(CAST3 STATIC ${SOURCES})
However, when i try to link the library to my executable I get an error.
This is my executable
#include"Point.hpp"
int main(int argc, char *argv[]){
Point p = Point(1,2,3);
return 0;
}
This is my CMake file to link the library to the executable.
cmake_minimum_required(VERSION 2.8.9)
project (CAST3)
set ( PROJECT_LINK_LIBS libCAST3.a )
link_directories( ${CMAKE_CURRENT_SOURCE_DIR}/lib/build)
add_executable(libtest mainApp.cpp)
target_link_libraries(libtest ${PROJECT_LINK_LIBS} )
When I run that I get the this error
/mainApp.cpp:1:9: fatal error: 'Point.hpp' file not found
#include"Point.hpp"
^~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/libtest.dir/mainApp.cpp.o] Error 1
make[1]: *** [CMakeFiles/libtest.dir/all] Error 2
make: *** [all] Error 2
What am I missing?
What am I missing?
You are missing target_include_directories(CAST3 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) inside lib/CMakeLists.txt.
You are missing add_subdirectory(lib) from root CMakeLists.txt.
The set ( PROJECT_LINK_LIBS libCAST3.a ) and target_link_libraries(libtest ${PROJECT_LINK_LIBS} ) and link_directories( ${CMAKE_CURRENT_SOURCE_DIR}/lib/build) could be removed. Then you are missing just target_link_libraries(libtest PUBLIC CAST3). Cmake will automatically find the proper .a file and propagate include paths with target_link_libraries.
So your lib/CMakeLists.txt could look like this:
cmake_minimum_required(VERSION 3.0) # I would advise to update
project(CAST3)
include_directories(include)
file(GLOB sources src/*.cpp) # upper case variable names reserved for exported variables by convention
add_library(CAST3 ${sources}) # STATIC by default
target_include_directories(CAST3 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
And root CMakeLists.txt could look like this:
cmake_minimum_required(VERSION 3.0) # I would advise to update
project(CAST3)
add_subdirectory(lib)
add_executable(libtest mainApp.cpp)
target_link_libraries(libtest CAST3)

CMake Visibility for Imported Libraries

I have an imported library that I am trying to link using CMake. However, the library always shows up empty (or not found). I know that imported libraries have different visibility rules (according to this thread) than the standard libraries, but no matter what I try the library always ends up missing. To start, here's my folder structure:
Root
├── build
├── cmake
├── src
│ ├── external
│ │ ├── openvdb
│ │ │ ├── openvdb
│ │ │ ├── cmake
│ │ │ ├── CMakeLists.txt
│ │ ├── tbb
│ │ ├── zlib
│ │ ├── CMakeLists.txt
│ ├── CMakeLists.txt
├── CMakeLists.txt
In my Root CMakeLists.txt file I add the libraries called TBB_LIBS and TBBMALLOC_LIBS like this:
cmake_minimum_required(VERSION 3.2.2 FATAL_ERROR)
include(ExternalProject)
project(openVDBBuild)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (WIN32)
set(CMAKE_CXX_FLAGS "-bigobj /EHsc")
endif ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
if(NOT CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX debug)
endif()
if(NOT CMAKE_RELEASE_POSTFIX)
set(CMAKE_RELEASE_POSTFIX release)
endif()
set(BUILD_VARIANTS "release debug")
set(TBB_PREFIX "tbb")
set(TBB_LIBS_DIR "${CMAKE_SOURCE_DIR}/src/external/tbb/build/${TBB_PREFIX}_")
set(TBB_ROOT ${CMAKE_SOURCE_DIR}/src/external/tbb)
set(TBB_INCLUDE_DIR ${TBB_ROOT}/include)
#********** Here I create the library and add the Global Flag ***********
add_library(TBBMALLOC_LIBS SHARED IMPORTED GLOBAL)
add_library(TBB_LIBS SHARED IMPORTED GLOBAL)
if (WIN32)
#********** Here I set different paths for debug and release versions of the library ***********
set_property(TARGET TBBMALLOC_LIBS PROPERTY IMPORTED_LOCATION_RELEASE ${CMAKE_BINARY_DIR}/lib/tbbmalloc.dll )
set_property(TARGET TBBMALLOC_LIBS PROPERTY IMPORTED_LOCATION_DEBUG ${CMAKE_BINARY_DIR}/lib/tbbmalloc_${CMAKE_DEBUG_POSTFIX}.dll )
set_property(TARGET TBB_LIBS PROPERTY IMPORTED_LOCATION_RELEASE ${CMAKE_BINARY_DIR}/lib/tbb.dll )
set_property(TARGET TBB_LIBS PROPERTY IMPORTED_LOCATION_DEBUG ${CMAKE_BINARY_DIR}/lib/tbb_${CMAKE_DEBUG_POSTFIX}.dll )
add_custom_command(
TARGET ProjectTbbExternal
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<$<CONFIG:debug>:${TBB_LIBS_DIR}${CMAKE_DEBUG_POSTFIX}/tbb_${CMAKE_DEBUG_POSTFIX}.dll>$<$<CONFIG:release>:${TBB_LIBS_DIR}${CMAKE_RELEASE_POSTFIX}/tbb.dll>" "${CMAKE_BINARY_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E copy "$<$<CONFIG:debug>:${TBB_LIBS_DIR}${CMAKE_DEBUG_POSTFIX}/tbbmalloc_${CMAKE_DEBUG_POSTFIX}.dll>$<$<CONFIG:release>:${TBB_LIBS_DIR}${CMAKE_RELEASE_POSTFIX}/tbbmalloc.dll>" "${CMAKE_BINARY_DIR}/lib"
COMMAND ${CMAKE_COMMAND} -E copy "$<$<CONFIG:debug>:${TBB_LIBS_DIR}${CMAKE_DEBUG_POSTFIX}/tbbmalloc_proxy_${CMAKE_DEBUG_POSTFIX}.dll>$<$<CONFIG:release>:${TBB_LIBS_DIR}${CMAKE_RELEASE_POSTFIX}/tbbmalloc_proxy.dll>" "${CMAKE_BINARY_DIR}/lib"
)
endif ()
add_subdirectory("src")
Now, down inside the CMakeLists.txt in the src/external/openvdb directory I try to link the libraries like this:
project(OpenVDBCore)
#define OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER 4
#define OPENVDB_LIBRARY_MINOR_VERSION_NUMBER 0
#define OPENVDB_LIBRARY_PATCH_VERSION_NUMBER 0
#*********** I'm going to omit some lines here since **********
#*********** they're standard for the OpenVDB build ***********
SET_SOURCE_FILES_PROPERTIES ( ${OPENVDB_LIBRARY_SOURCE_FILES}
PROPERTIES
COMPILE_FLAGS "-DOPENVDB_PRIVATE -DOPENVDB_USE_BLOSC ${OPENVDB_USE_GLFW_FLAG}"
)
ADD_LIBRARY ( openvdb_static STATIC ${OPENVDB_LIBRARY_SOURCE_FILES} )
ADD_LIBRARY ( openvdb_shared SHARED ${OPENVDB_LIBRARY_SOURCE_FILES} )
TARGET_LINK_LIBRARIES ( openvdb_static
zlib
TBB_LIBS
TBBMALLOC_LIBS
)
TARGET_LINK_LIBRARIES ( openvdb_shared
zlib
TBB_LIBS
TBBMALLOC_LIBS
)
MESSAGE(STATUS "TBB_LIBS library location is ${TBB_LIBS}")
MESSAGE(STATUS "TBBMALLOC_LIBS library location is ${TBBMALLOC_LIBS}")
You can see that I put a status message in CMake to see what the ${TBB_LIBS} and ${TBBMALLOC_LIBS} variables are... but that part is always empty. Accordingly, the openvdb_shared and openvdb_static project files that get generated by CMake also do not link the libraries correctly (since those libraries are unknown). Does anyone know why this occurs (and how to fix it)?