zlib in Qt - QtZlib not present - c++

I am using QuaZip library, which has zlib dependency. I want to compile my CMake managed application under Archlinux and Windows 7, in both I have Qt 5.3.0 installed.
On Linux:
I have read here "how to add zlib to an existing qt installation" that zlib is a native part of Qt installation. But in archlinux there is no such directory.
Of cause I searched through all other Qt include directories including QtCore, but there was no sign of zlib. On the other hand system installation of zlib can be found on archlinux through FindZLIB.cmake module.
On Windows:
In the Windows installation of Qt there is QtZlib folder in Qt include directory, so it can be included. Nevertheless, compiler always complain that he cannot link zlib functions from library, error log here. I've also tried to set external zlib library manually through TARGET_LINK_LIBRARIES but with no success.
Have anybody experiance with linking Zlib under Qt5 using CMake ?

Qt's zlib is an internal implementation detail. You're not supposed to use it. You need to link your own copy of zlib, just as you would need to if you weren't using Qt at all.

1) You should use your package manager on Archlinux and your own installation on Windows. Do not rely on the Qt third-party installation. It may be there today, but disappear at any certain moment when a new release comes out.
This is what I would suggest you doing on your Archlinux box:
pacman -S zlib
2) Also, you should use FindZLIB.cmake for finding zlib the following way in your CMakeLists.txt:
find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
include_directories( ${ZLIB_INCLUDE_DIRS} )
target_link_libraries( YourProject ${ZLIB_LIBRARIES} )
endif( ZLIB_FOUND )

Related

What's the easiest way to build Adobe's XMP toolkit as a shared library with CMake on OSX?

I'm putting together a little project that's supposed to be cross-platform, built with CMake, and it needs to link with Adobe's XMP toolkit (libxmp). Ideally I'd like CMake to be responsible for building the dependencies, including libxmp, in one fell swoop.
Unfortunately the XMP toolkit is designed to be built with XCode on OSX and CMake on Linux. The CMake build process doesn't appear to work out of the box on OSX.
What's the minimal change I can make to the XMP toolkit to get it to build with CMake on OSX? Should I just keep hacking away at it until it works, or is this a known/solved problem? And, more generally, what additions should I make to my own CMakeLists.txt file to integrate this project with my own?
I've learnt a few things today and several misconceptions have apparently evaporated.
After fulfilling the third-party dependency requirements (expat and zlib; this is just a matter of extracting files from source tarballs into a designated location), this was pretty easy once I realised that XCode can be leveraged here from the commandline, and that XMP's own "build system" has sufficient tools to do everything I need.
In short, from the build directory:
./cmake.command 64 Dynamic WarningAsError ToolchainLLVM.cmake
cd xcode/dynamic/intel_64
xcodebuild -scheme ALL_BUILD build
Then, the framework files are found under public/libraries/macintosh/intel_64/Debug, and the includes were already available under public/include.
After some liberal symlinking, in my own project's CMakeLists.txt it's just a matter of:
target_compile_definitions(myProject
PUBLIC
MAC_ENV
)
target_include_directories(
myProject
PRIVATE
include/libxmp
)
# Add build dir to path for finding frameworks (libmxp)
set_target_properties(
myProject
PROPERTIES
LINK_FLAGS "-Wl,-F${CMAKE_BINARY_DIR}/Frameworks"
)
target_link_libraries(
myProject
PRIVATE
catch
"-framework XMPCore"
"-framework XMPFiles"
)
It surely could be finessed, but this does otherwise "just work".
If you are using the XMP Toolkit 2016.07 (and, at time of writing, there is no newer version) and have Xcode 10+ & Mojave, you will need to put together a few patches before you build:
Xcode version detect fix
stdlib config fix
Map/pair type alias fixes
Furthermore, if you use expat 2.2.2 or newer:
Define HAVE_ARC4RANDOM_BUF or XML_POOR_ENTROPY at the top of expat's xmlparse.c (because the libxmp build system won't do this for you)

Obtaining the CUDA include dir in C++ targets with native-CUDA-support CMake?

In CMake version 3.8, native support for CUDA as a language was introduced. When a project has CUDA as one of its languages, CMake will proceed to locate CUDA (e.g. it locates the nvcc binary).
As long as you only compile CUDA code - this is enough. But what if you want to compile a C++ target in that project? The CUDA includes are not -I'ed automatically, and CMakeCache.txt does not seem to contain the CUDA include path anywhere.
Do I actually have to run something find_package(CUDA 9.0 REQUIRED) even when CMake itself has already located CUDA? Or - can I obtain the include directory some other way?
The include directories, which are used by the compiler set by CMAKE_CUDA_COMPILER, can be retrieved from the CMake variable CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.
For getting the libraries, the best way is probably to use find_library() in combination with CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES.
Example:
cmake_minimum_required(VERSION 3.9)
project(MyProject VERSION 1.0)
enable_language(CUDA)
find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
add_executable(
binary_linking_to_cudart
my_cpp_file_using_cudart.cpp
)
target_include_directories(
binary_linking_to_cudart
PRIVATE
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
)
target_link_libraries(
binary_linking_to_cudart
${CUDART_LIBRARY}
)
This issue is also discussed on the CMake bug tracker: Provide target libraries for cuda libraries.
Update: CMake 3.17.0 adds FindCUDAToolkit
Instead of doing find_library() manually, the best way as of CMake 3.17.0 would be to use the CUDAToolkit module.
find_package(CUDAToolkit)
add_executable(
binary_linking_to_cudart
my_cpp_file_using_cudart.cpp
)
target_link_libraries(binary_linking_to_cudart PRIVATE CUDA::cudart)
For support with earlier CMake versions, you can ship the CUDATookit module file with minimal changes in your repository.
These days, with CMake 3.18 and later, you can get most of what you need by examining the targets provided by find_package(CUDAToolkit) - which you do need even if CUDA has located the CUDA compiler. But actually, you may just depend on one of those targets and avoid using the include directories directly.
PS - If you happen to use cuda-api-wrappers (e.g. via find_package(cuda-api-wrappers)), it will take care of the dependencies for you.

Enabling curses in both Linux and Windows

I am working on small project in C++ and I am using curses for user interface. I am pretty nicely able to make it work in my arch-linux installation, because it is pretty simple to set up ncurses to work there. But with my cmake setting which is working nicely at Linux I am not able to properly make it work at Windows.
Here is my CMakeList.txt
cmake_minimum_required(VERSION 3.9)
project(fighting_pit)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 11)
include_directories( ./include)
include_directories( ./src)
add_executable(fighting_pit
include/Arena.h
include/cursor.h
include/Player.h
include/spell.h
include/Turns.h
include/weapon.h
include/Draw.h
src/Arena.cpp
src/cursor.cpp
src/Player.cpp
src/spell.cpp
src/Turns.cpp
src/weapon.cpp
src/Draw.cpp
main.cpp )
target_link_libraries(fighting_pit ${CURSES_LIBRARIES})
I tried several approaches to make it work on Windows too.
1. Downloading sources
I tried to build pdcurses with mingw32-make. It created pdcurses.a I added it to same location as project, but it still shows it cannot find curses library.
2. Downloading via mingw32-get
I used installation manager from mingw and let it download both .dll and dev package of libpdcurses. Just trying to run cmake through clion showed it is still not found. So I copied it both into windows32 and project folder but it still didn't help.
I don't know what I should do. Unfortunately I am neither C++ user neither Windows user.
I needed to build a cross-platform project that uses ncurses on Linux and MacOS but uses pdcurses on Windows. Some variant of curses is usually installed on popular distributions of Linux. ncurses is also available on MacOS as well. The same isn't quite true for Windows. My solution was to download the pdcurses sources and write a cmake script for building it on Windows. if (WIN32 or MSVC) build pdcurses else() find ncurses. You might also want to create a proxy header that #includes pdcurses or ncurses depending on the platform.
After cloning the GitHub repo, I copied the headers in ., the C files in ./pdcurses, the sources in ./wincon into a new directory in my project. Then I wrote a CMakeLists.txt file to compile all of these files into a library. It looked something like this:
cmake_minimum_required(VERSION 3.2)
add_library(PDcurses
# all of the sources
addch.c
addchstr.c
addstr.c
attr.c
beep.c
# ...
)
target_include_directories(PDcurses
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
My main CMakeLists.txt file compiled the pdcurses sources if the target is windows.
if(WIN32 OR MSVC)
add_subdirectory(pdcurses)
target_link_libraries(MyTarget
PRIVATE
PDcurses
)
else()
# find ncurses and use that
endif()
PDCurses seems to be a (more or less) drop-in replacement for ncurses in most situations. I was able to compile the example programs that came with PDcurses on my Mac using curses without any troubles.

CMake CEGUI / GTK2 Configuration Error

I am trying to build and use CEGUI (Crazy Eddie's GUI) as a library for Ogre. I am using CMake, but during the configuring step for the dependencies, I got the following error:
Some or all of the gtk libraries were not found. (missing: GTK2_GTK_LIBRARY GTK2_GTK_INCLUDE_DIR GTK2_GDK_INCLUDE_DIR GTK2_GDKCONFIG_INCLUDE_DIR GTK2_GDK_LIBRARY GTK2_GLIB_INCLUDE_DIR GTK2_GLIBCONFIG_INCLUDE_DIR GTK2_GLIB_LIBRARY)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_INCLUDE_DIR (ADVANCED)
used as include directory in directory C:/Cegui/cegui-0.8.3/cegui/src/RendererModules/Ogre
CEGUI 0.8.3
cegui-deps-0.8.x-src.zip
Make sure that you have GTK2 installed on your machine (as far as I can tell, it is not part of the CEGUI dependency download archive).
Ensure that CMake can find the library and all it needs. From having a look at the official CMake FindGKT2 script (and I couldn't find a custom one for CEGUI, so the official one is most likely used), the following locations are checked:
/usr/local/lib64
/usr/local/lib
/usr/lib64
/usr/lib
/opt/gnome/include [and /lib]
/opt/openwin/include [and /lib]
/sw/include [and /lib]
/opt/local/include [and /lib]
/usr/pkg/lib
/usr/pkg/include/glib
$ENV{GTKMM_BASEPATH}/include [and /lib]
[HKEY_CURRENT_USER\SOFTWARE\gtkmm\2.4;Path]/include
[HKEY_CURRENT_USER\SOFTWARE\gtkmm\2.4;Path]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\gtkmm\2.4;Path]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\gtkmm\2.4;Path]/lib
So if you are on windows, setting the environment variable GTKMM_BASEPATH will probably be the easiest way. Alternatively, you can also directly enter the paths to your GTK2 installation in the advanced CEGUI view.

How to link QtMain in CMake with Qt5?

I upgraded my project code from Qt4 to Qt5. It uses CMake.
The conversion got well except for one line of Cmake commands related to Qt.
I can’t find in current documentation, like
http://qt-project.org/doc/qt-5.0/qtdoc/cmake-manual.html
http://qt-project.org/doc/qt-5.0/qtdoc/qtmain.html
How to link with QtMain from CMake (with Qt5)?
It is the only missing bit to convert my project.
Can someone point me to a doc explaining this or explain how to do it with Qt5? My Qt4 code worked correctly but I can't find the Cmake macro for Qt5.
EDIT> Here is the CMake file I have at the moment: https://bitbucket.org/klaim/aos_qt5/src/593c195c4c6889f6968d68fca018ef425783a063/tools/aosdesigner/CMakeLists.txt?at=wip_qt5
All qt5 necessary CMake macros have been set correctly I belive, the only thing that don't work is the linking to QtMain that do nothing, as expected since there should be a Qt5 specific way of doing it that I don't find in the Qt5 documentation.
You can browse the file history to see how it was working with Qt4.
From the Qt docs you linked to, it seems you can find Qt5Core instead of Qt5Widgets. That will create an imported target named Qt5::WinMain. From the Qt docs:
Imported targets are created for each Qt module. That means that the Qt5<Module>_LIBRARIES contains a name of an imported target, rather than a path to a library.
...
Each module in Qt 5 has a library target with the naming convention Qt5::<Module>
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Core REQUIRED )
...
add_executable( aosdesigner WIN32 ${AOSDESIGNER_ALL_FILES} )
target_link_libraries( aosdesigner
${Boost_LIBRARIES}
utilcpp
aoslcpp
Qt5::WinMain # <-- New target available via find_package ( Qt5Core )
)
qt5_use_modules( aosdesigner Widgets )
I'd also recommend that you remove your two link_libraries calls since it's a deprecated command and I'd specify CMake version 2.8.9 rather than just 2.8 as the minimum required at the top of your CMakeLists.txt, since that's required for qt5_use_modules.
As of CMake 2.8.11 and Qt 5.1, linking to Qt5::WinMain is automatic/implicit if you specify WIN32 in your add_executable call, or otherwise set the WIN32_EXECUTABLE target property.
The presentation at
https://devdays.kdab.com/wp-content/uploads/2012/cmake.pdf
with video at
http://www.youtube.com/watch?feature=player_detailpage&v=GJ0kMsLbk6Q#t=751
describes the features which made it into CMake 2.8.11.
For more about CMake with Qt see
http://www.kdab.com/modern-cmake-with-qt-and-boost/
EDIT : Thanks to Archi comment (see below), simply add
target_link_libraries(<your_app> Qt5::WinMain)
or
target_link_libraries(<your_app> ${Qt5Core_QTMAIN_LIBRARIES})
in your application's CMakeLists.txt. Both syntaxes worked for me.