I am using the experimental GLM hash features in a CMake project.
Everything works fine unless the project is generated by Clion.
When building the Clion generated project GLM raises the error "GLM_GTX_hash requires C++11 standard library support" (see CMake logs) although C++11 is enabled.
Building the same, clion generated, project from a terminal fails with the same error.
However, when generating and building the project with cmake 'manually' (without Clion even knowing about it) everything works fine. As expected.
GLM is not directly included in the CMakeList. GLFW includes/imports it.
Example CMakeLists.txt
(...)
set(CMAKE_CXX_STANDARD 11)
add_executable(Test main.cpp)
(...)
add_subdirectory("glfw" ${CMAKE_CURRENT_BINARY_DIR}/glfw)
target_include_directories(Test PUBLIC ${GLFW_INCLUDE_DIRS})
target_link_libraries(Test ${GLFW_LIBRARIES} glfw)
Example main.cpp
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
int main() {
return 0;
}
Clion build output:
/usr/bin/cmake --build /home/lukas/Test/cmake-build-debug --target Test -- -j 2
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
In file included from /home/lukas/Test/main.cpp:8:
/usr/include/glm/gtx/hash.hpp:46:3: error: "GLM_GTX_hash requires C++11 standard library support"
# error "GLM_GTX_hash requires C++11 standard library support"
^
1 error generated.
make[3]: *** [CMakeFiles/Test.dir/build.make:63: CMakeFiles/Test.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/Test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/Test.dir/rule] Error 2
make: *** [Makefile:118: Test] Error 2
Terminal output (as expected)
$ cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build
Scanning dependencies of target glfw
[ 5%] Building C object glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 10%] Building C object glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 15%] Building C object glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 21%] Building C object glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 26%] Building C object glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 31%] Building C object glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 36%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_init.c.o
[ 42%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_monitor.c.o
[ 47%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_window.c.o
[ 52%] Building C object glfw/src/CMakeFiles/glfw.dir/xkb_unicode.c.o
[ 57%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_time.c.o
[ 63%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 68%] Building C object glfw/src/CMakeFiles/glfw.dir/glx_context.c.o
[ 73%] Building C object glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 78%] Building C object glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 84%] Building C object glfw/src/CMakeFiles/glfw.dir/linux_joystick.c.o
[ 89%] Linking C static library libglfw3.a
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
[100%] Built target Test
Now I am actually curious about rather I messed up somewhere or if it is simply a bug. And if so, where should I report it?
[Clion/Jetbrains?, GLM?, GLFW?, CMake?]
Thanks in advance
Update
I am using the latest available (for me) builds:
CMake version: 3.14.4
Operating System: Arch Linux 5.0.18-1 x86_64 GNU/Linux
GLFW version/commit: d834f01c
GLM version/commit: fce2abd0
Clion: 2019.1.3
Clion EAP: 2019.2 EAP
Final update / 'Solution'
I just discovered that the problem is Clang, not Clion or anything else.
Clion simply defaulted to Clang (instead of GCC).
There are bug reports for GLM and Clang already existing (with potential fixes!):
https://github.com/g-truc/glm/issues/620
https://github.com/g-truc/glm/issues/646
Thank you very much everyone ~
Related
I have been trying on and off for the past year to import the NLopt library into my work. I have been unsuccessful, and I am desperate for help.
Here is some of my CMAKE file
cmake_minimum_required(VERSION 3.21)
project(DynamicRRT)
set(CMAKE_CXX_STANDARD 17)
set(CONAN_CMAKE_CXX_STANDARD 17)
include_directories(/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3/)
find_library(nlopt /Users/brandon/Extern/nlopt_install/ NAMES libnlopt nlopt NLopt)
include_directories(/Users/brandon/Extern/nlopt_install/include/ )
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
#INCLUDE_DIRECTORIES(/Users/brandon/CLionProjects/nlopt/)
#INCLUDE_DIRECTORIES(/opt/homebrew/Cellar/nlopt/2.7.1/include/)
#include_directories(/usr/local/include/)
#add_library(nlopt /Users/brandon/Extern/nlopt_install/include)
#add_compile_options(-Wa,-mbig-obj)¡
add_executable(DynamicRRT main.cpp utilities.cpp utilities.h rrt_star.cpp rrt_star.h tree.cpp tree.h Nodes.cpp Nodes.h Obstacles.cpp Obstacles.h macro_rrt_star.cpp macro_rrt_star.h collisions.cpp collisions.h dynamic_rrt_star.cpp dynamic_rrt_star.h trajectory.cpp trajectory.h transformer.cpp transformer.h print_utilities.cpp print_utilities.h random_utilities.cpp random_utilities.h)# inverse_kinematics.cpp inverse_kinematics.h)# rrt_star.cpp rrt_star.h)#rrt_star_util.cpp rrt_star_util.h
target_link_libraries(DynamicRRT nlopt)
You can see that I've commented out a number of attempts at getting this imported. CMake does not throw any errors. However, if I try building the project, I get:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/brandonmeng/CLionProjects/DynamicRRT/cmake-build-default-gcc --target all -- -j 8
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/Obstacles.cpp.o
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/utilities.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/macro_rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/Nodes.cpp.o
[ 42%] Building CXX object CMakeFiles/DynamicRRT.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/DynamicRRT.dir/tree.cpp.o
[ 57%] Building CXX object CMakeFiles/DynamicRRT.dir/collisions.cpp.o
[ 64%] Building CXX object CMakeFiles/DynamicRRT.dir/dynamic_rrt_star.cpp.o
[ 71%] Building CXX object CMakeFiles/DynamicRRT.dir/trajectory.cpp.o
[ 78%] Building CXX object CMakeFiles/DynamicRRT.dir/transformer.cpp.o
[ 85%] Building CXX object CMakeFiles/DynamicRRT.dir/print_utilities.cpp.o
[ 92%] Building CXX object CMakeFiles/DynamicRRT.dir/random_utilities.cpp.o
[100%] Linking CXX executable bin/DynamicRRT
ld: library not found for -lnlopt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/DynamicRRT] Error 1
make[1]: *** [CMakeFiles/DynamicRRT.dir/all] Error 2
make: *** [all] Error 2
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
The library to link with is likely not in the include directory with the header files. It's more likely they're in a lib directory:
link_directories(/Users/brandon/Extern/nlopt_install/lib)
I am trying to install the following C library:
https://github.com/kwhat/libuiohook
I did the described steps which seem to work with no error.
$ git clone https://github.com/kwhat/libuiohook
$ cd uiohook
$ mkdir build && cd build
$ cmake -S .. -D BUILD_SHARED_LIBS=ON -D BUILD_DEMO=ON -DCMAKE_INSTALL_PREFIX=../dist
$ cmake --build . --parallel 2 --target install
The problem is I don't know what to do next.
I tried to copy the code from the simple hook example and tried to execute the code in a different executable with the following CMakeLists.txt.
cmake_minimum_required(VERSION 3.20)
project(libuihook_test)
include_directories("/Users/ahoehne/libuiohook/dist/include")
find_library(lib uiohook)
if(NOT lib)
message(FATAL_ERROR "uiohook library not found")
endif()
set(CMAKE_CXX_STANDARD 17)
add_executable(libuihook_test main.cpp)
target_link_libraries(libuihook_test lib)
which doesn't work and results in a
CMake Error at CMakeLists.txt:9 (message):
uiohook library not found
the log from installing is the following:
[ 14%] Building C object CMakeFiles/uiohook.dir/src/darwin/input_helper.c.o
[ 14%] Building C object CMakeFiles/uiohook.dir/src/logger.c.o
[ 21%] Building C object CMakeFiles/uiohook.dir/src/darwin/input_hook.c.o
[ 28%] Building C object CMakeFiles/uiohook.dir/src/darwin/post_event.c.o
[ 35%] Building C object CMakeFiles/uiohook.dir/src/darwin/system_properties.c.o
[ 42%] Linking C shared library libuiohook.dylib
[ 42%] Built target uiohook
[ 57%] Building C object CMakeFiles/demo_post.dir/demo/demo_post.c.o
[ 57%] Building C object CMakeFiles/demo_properties.dir/demo/demo_properties.c.o
[ 71%] Linking C executable demo_properties
[ 71%] Linking C executable demo_post
[ 71%] Built target demo_post
[ 71%] Built target demo_properties
[ 78%] Building C object CMakeFiles/demo_hook.dir/demo/demo_hook.c.o
[ 85%] Building C object CMakeFiles/demo_hook_async.dir/demo/demo_hook_async.c.o
[ 92%] Linking C executable demo_hook
[100%] Linking C executable demo_hook_async
[100%] Built target demo_hook
[100%] Built target demo_hook_async
Install the project...
-- Install configuration: ""
-- Installing: /Users/ahoehne/libuiohook/dist/lib/libuiohook.1.2.0.dylib
-- Up-to-date: /Users/ahoehne/libuiohook/dist/lib/libuiohook.1.dylib
-- Up-to-date: /Users/ahoehne/libuiohook/dist/lib/libuiohook.dylib
-- Up-to-date: /Users/ahoehne/libuiohook/dist/include/uiohook.h
-- Installing: /Users/ahoehne/libuiohook/dist/lib/cmake/uiohook/uiohook-config.cmake
-- Installing: /Users/ahoehne/libuiohook/dist/lib/cmake/uiohook/uiohook-config-noconfig.cmake
-- Installing: /Users/ahoehne/libuiohook/dist/bin/demo_hook
-- Installing: /Users/ahoehne/libuiohook/dist/bin/demo_hook_async
-- Installing: /Users/ahoehne/libuiohook/dist/bin/demo_post
-- Installing: /Users/ahoehne/libuiohook/dist/bin/demo_properties
-- Installing: /Users/ahoehne/libuiohook/dist/lib/pkgconfig/uiohook.pc
I consulted the CMAKE Docs but honestly right now confuses me more than it helps. I am sure at some point I will have an aha moment and connect the dots. Most tutorials do an excellent job of explaining you C/C++ but they all lack the more advanced stuff around build tools, testing, debugging, and so on, everything you basically need to build more complex projects. So I am also grateful for book/video suggestions.
I also tried different combinations of include_directories, add, link library also an absolute path but nothing seems to work and I get a library not found error or uiohook.h not found.
I am well aware that C and C++ are completely different languages and different practices apply I am not sure If I could have fixed this question to one. But basically try to learn C++ but need to access a lot of C libs.
As the library provides a uiohook-config.cmake you should use that to link to the library via find_package rather than using find_library.
Something like this should work:
set(CMAKE_PREFIX_PATH /Users/ahoehne/libuiohook/dist/lib/cmake/uiohook/)
find_package(uiohook REQURIED)
target_link_libraries(libuihook_test uiohook)
I've been writing a compiler using LLVM as the backend. The CMake files I've written so far have worked on Linux, but I haven't had any luck on Windows. The project is split into a library and "driver" executable with their own CMakeLists.txt in separate subdirectories.
The top level CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.7.0)
project (compiler)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
find_package (LLVM REQUIRED CONFIG)
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories (${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory (Compiler_Lib)
add_subdirectory (Compiler_exe)
The CMakeLists.txt for the library:
cmake_minimum_required (VERSION 3.7.0)
add_library (compiler_lib
AST.cpp
AST.h
parser.cpp
parser.h
scanner.cpp
scanner.h
token.cpp
token.h
visualizer.cpp
visualizer.h
codegen.cpp
codegen.h)
target_include_directories (compiler_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(compiler_lib LLVM)
And the CMakeLists.txt for the executable (which is where linking to the libraries fails):
cmake_minimum_required (VERSION 3.7.0)
project (compiler_exe)
add_executable (compiler_exe Compiler_exe.cpp getopt.h getopt.cpp)
target_link_libraries (compiler_exe LINK_PUBLIC LLVM compiler_lib)
I run the command "c:\Program Files\CMake\bin\cmake.exe" .. -G"MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:\Users\James\llvm+clang-7.0.0-win64-msvc-release where C:\Users\James\llvm+clang-7.0.0-win64-msvc-release is the path to prebuilt LLVM libraries. However, running mingw32-make afterwards fails with the output
Scanning dependencies of target compiler_lib
[ 10%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/AST.cpp.obj
[ 20%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/parser.cpp.obj
[ 30%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/scanner.cpp.obj
[ 40%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/token.cpp.obj
[ 50%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/visualizer.cpp.obj
[ 60%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/codegen.cpp.obj
[ 70%] Linking CXX static library libcompiler_lib.a
[ 70%] Built target compiler_lib
Scanning dependencies of target compiler_exe
[ 80%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/Compiler_exe.cpp.obj
[ 90%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/getopt.cpp.obj
[100%] Linking CXX executable compiler_exe.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lLLVM
collect2.exe: error: ld returned 1 exit status
Compiler_exe\CMakeFiles\compiler_exe.dir\build.make:102: recipe for target 'Compiler_exe/compiler_exe.exe' failed
mingw32-make[2]: *** [Compiler_exe/compiler_exe.exe] Error 1
CMakeFiles\Makefile2:176: recipe for target 'Compiler_exe/CMakeFiles/compiler_exe.dir/all' failed
mingw32-make[1]: *** [Compiler_exe/CMakeFiles/compiler_exe.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
This is the first time I've used CMake so I could have missed something obvious, but as I say it seems to work on Linux.
For the linking to succeed two things need to be true:
1) the file libLLVM.a needs to exist
2) that file has to be in a directory in the library search path
There should be a way to get cmake to tell you the list of places it searches for libraries, and you need to find a way to get wherever libLLVM.a exists into that list of dirs.
Apologies for the partial answer, but that's the troubleshooting path...
To resolve this error I tried to add extra module opencv-contrib-master from https://github.com/opencv/opencv_contrib.git I followed the steps given in the readme.md file but while running 'make' I am getting the following output:
[ 4%] Built target libwebp
[ 4%] Built target opencv_core_pch_dephelp
[ 4%] Built target pch_Generate_opencv_core
Scanning dependencies of target opencv_core
[ 4%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o
Linking CXX shared library ../../lib/libopencv_core.so
[ 7%] Built target opencv_core
[ 7%] Built target opencv_ts_pch_dephelp
[ 7%] Built target pch_Generate_opencv_ts
[ 7%] Built target opencv_imgproc_pch_dephelp
[ 8%] Built target pch_Generate_opencv_imgproc
Linking CXX shared library ../../lib/libopencv_imgproc.so
[ 11%] Built target opencv_imgproc
[ 11%] Built target opencv_imgcodecs_pch_dephelp
[ 11%] Built target pch_Generate_opencv_imgcodecs
Linking CXX shared library ../../lib/libopencv_imgcodecs.so
[ 12%] Built target opencv_imgcodecs
[ 12%] Built target opencv_videoio_pch_dephelp
[ 12%] Built target pch_Generate_opencv_videoio
Linking CXX shared library ../../lib/libopencv_videoio.so
[ 13%] Built target opencv_videoio
[ 13%] Built target opencv_highgui_pch_dephelp
[ 13%] Built target pch_Generate_opencv_highgui
Linking CXX shared library ../../lib/libopencv_highgui.so
[ 14%] Built target opencv_highgui
[ 14%] Built target opencv_ts
[ 14%] Built target opencv_perf_core_pch_dephelp
[ 14%] Built target pch_Generate_opencv_perf_core
Linking CXX executable ../../bin/opencv_perf_core
[ 16%] Built target opencv_perf_core
[ 16%] Built target opencv_test_core_pch_dephelp
[ 16%] Generating test_precomp.hpp.gch/opencv_test_core_RELEASE.gch
In file included from <command-line>:0:0:
/usr/include/stdc-predef.h:1:0: fatal error: can’t create precompiled header /home/chandu/Opencv/opencv/release/modules/core/test_precomp.hpp.gch/opencv_test_core_RELEASE.gch: Permission denied
/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
^
compilation terminated.
Preprocessed source stored into /tmp/cchn5Yvk.out file, please attach this to your bugreport.
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/_usr_lib_gcc_x86_64-linux-gnu_4.9_cc1plus.1000.crash'
make[2]: *** [modules/core/test_precomp.hpp.gch/opencv_test_core_RELEASE.gch] Error 1
make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_test_core.dir/all] Error 2
make: *** [all] Error 2
Somewhere it was told that there may be problem in gcc version but I updated gcc version but no success. I am using gcc of version 4.9.4 and ubuntu of version 14.04.1. Before 'make' step I ran:
cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules /usr/local .. -DWITH_IPP=OFF -DWITH_OPENGL=ON -DWITH_QT=ON -DBUILD_EXAMPLES=ON
I approached many resources but no results. Any kind of help is appreciable.
Did you tried prepending the command with sudo?
The problem is that xfeatures2d was not being exported from opencv-contrib module. So, when I was running 'make' command it was not able to add that module to opencv build module.
I ran the following command followed by make command:
export xfeatures2d=/path/to/opencv_contrib/modules/
It worked for me.
Talking about a Qt 5.3.2 project which is buildt using cmake.
This is a calling order problem between UIC execution and target_link_libraries... unfortunately not in that order.
Below this text you will find
1.) a (still functional) excerpt section of my CMakeLists.txt and
2.) an excerpt of the the output of the command 'cmake .'
3.) the output of a following call to 'make' without using the
generated headers like 'ui_main.h'.
If (in the source of my library libqt.a) I require 'ui_main.h' the
make process crashes not finding the header. Looking at the
non-crashing make output shows why:
[..]
Scanning dependencies of target qt
[ 29%] Building CXX object CMakeFiles/qt.dir/home/kochmn/projects/sentinel/src/qt/form_main.cpp.o
[ 35%] Building CXX object CMakeFiles/qt.dir/qt_automoc.cpp.o
Linking CXX static library libqt.a
[..]
[ 52%] Generating ui_main.h
[..]
Make would generate libqt.a before generating the required header file.
So I experimented using code like
target_link_libraries(sentinel
${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Core_LIBRARIES})
add_library(optimization "${DIR_SRC}/optimization/linalg.cpp")
add_library(qt "${DIR_SRC}/qt/form_main.cpp")
target_link_libraries(sentinel qt optimization)
to no avail. The question: How can I motivate cmake to first run UIC generating the ui-header files and then compiling my libqt.a?
Appendix
# 2.8.11 instead of 2.8 required for automatic linking to the qtmain.lib
# library if this ever should expand to Windows.
# (http://doc.qt.io/qt-5/cmake-manual.html)
cmake_minimum_required(VERSION 2.8.11)
project(sentinel)
set( CMAKE_AUTOMOC ON )
# CMake uses uic in order to generate header files from .ui forms from designer.
set ( CMAKE AUTOUIC ON )
# Auto-generating functions write their headers into the build directory.
# Hence the build directory should be included.
set( CMAKE_INCLUDE_CURRENT_DIR ON )
#> Getting the Qt essentials. ----------------------------------------
# Widgets finds its own dependencies (QtGui and QtCore).
find_package(Qt5Widgets REQUIRED)
message ("Found Qt5Widgets Version ${Qt5Widgets_VERSION_STRING}")
# All those darling variables are explained here:
# http://doc.qt.io/qt-5/cmake-manual.html
message("Core FOUND: ${Qt5Core_FOUND}")
message("Gui FOUND: ${Qt5Gui_FOUND}")
message("Widgets FOUND: ${Qt5Widgets_FOUND}")
message("Core VERSION: ${Qt5Core_VERSION_STRING}")
message("Gui VERSION: ${Qt5Gui_VERSION_STRING}")
message("Widgets VERSION: ${Qt5Widgets_VERSION_STRING}")
message("Core INCLUDE: ${Qt5Core_INCLUDE_DIRS}")
message("Gui INCLUDE: ${Qt5Gui_INCLUDE_DIRS}")
message("Widgets INCLUDE: ${Qt5Widgets_INCLUDE_DIRS}")
message("Core LIBRARIES: ${Qt5Core_LIBRARIES}")
message("Gui LIBRARIES: ${Qt5Gui_LIBRARIES}")
message("Widgets LIBRARIES: ${Qt5Widgets_LIBRARIES}")
message("Core DEFINITIONS: ${Qt5Core_DEFINITIONS}")
message("Gui DEFINITIONS: ${Qt5Gui_DEFINITIONS}")
message("Widgets DEFINITIONS: ${Qt5Widgets_DEFINITIONS}")
message("Core COMPILE_DEFINITIONS: ${Qt5Core_COMPILE_DEFINITIONS}")
message("Gui COMPILE_DEFINITIONS: ${Qt5Gui_COMPILE_DEFINITIONS}")
message("Widgets COMPILE_DEFINITIONS: ${Qt5Widgets_COMPILE_DEFINITIONS}")
message("Core EXECUTABLE_COMPILE_FLAGS: ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
message("Gui EXECUTABLE_COMPILE_FLAGS: ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS}")
message("Widgets EXECUTABLE_COMPILE_FLAGS: ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
include_directories(
${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
#add_definitions(${Qt5Core_DEFINITIONS}) # Unnecessary. In Widgets.
#add_definitions(${Qt5Gui_DEFINITIONS}) # Unnecessary. In Widgets.
#< -------------------------------------------------------------------
set (DEBUG 1)
set (SENTINEL_NAME "Sentinel GL")
set (SENTINEL_VERSION_MAJOR "0")
set (SENTINEL_VERSION_MINOR "1")
set (SENTINEL_VERSION "${SENTINEL_VERSION_MAJOR}.${SENTINEL_VERSION_MINOR}")
## Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
# ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} #<-- redundant.
if(CMAKE_COMPILER_IS_GNUCXX)
message("Using GnuCXX compiler.")
add_definitions("-O0 -std=c++0x -lSOIL -llapacke -lblas")
endif()
if (DEBUG MATCHES 1)
message("\nBuilding DEBUG build.")
add_definitions(-Wall)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(DIR_BASE "${PROJECT_SOURCE_DIR}/..")
set(DIR_SRC "${PROJECT_SOURCE_DIR}/../src")
set(DIR_RES "${PROJECT_SOURCE_DIR}/../resources")
set(DIR_BUILD "${PROJECT_SOURCE_DIR}/../build")
# Generated using uic FormMain.ui > ui_FormMain.h
set(qt_H
"${DIR_BUILD}/ui_main.h" "${DIR_BUILD}/ui_dialog_setup_game.h")
# Generated using the trusty QtDesigner.
set(qt_UI
"${DIR_SRC}/ui/main.ui" "${DIR_SRC}/ui/dialog_setup_game.ui")
# My own hand-written XML describing the internal resources.
set(qt_QRC "${DIR_RES}/application.qrc")
# generate rules for building source files that moc generates
QT5_WRAP_CPP(qt_H_MOC ${qt_H})
# generate rules for building header files from the ui files
QT5_WRAP_UI(qt_UI_H ${qt_UI})
# Resource Handling. QRC: "Qt Resource Collection"
QT5_ADD_RESOURCES(qt_RCCS ${qt_QRC})
# btw.: rcc generates a C program from ./resources/application.qrc
# However, this is not needed. cmake sees to that. :-)
#< -------------------------------------------------------------------
include_directories("${DIR_SRC}/include" "${PROJECT_SOURCE_DIR}")
add_executable(sentinel "${DIR_SRC}/sentinel.cpp" ${qt_H_MOC} ${qt_UI_H} ${qt_RCCS})
# Available modules are listed here: http://doc.qt.io/qt-5/qtmodules.html
# find /usr/lib/x86_64-linux-gnu/cmake -iname "*.cmake*" | less
# Note: http://stackoverflow.com/questions/20266235/cmake-error-qglwidget-no-such-file-or-directory
qt5_use_modules(sentinel Widgets Gui Core)
add_library(optimization "${DIR_SRC}/optimization/linalg.cpp")
add_library(qt "${DIR_SRC}/qt/form_main.cpp")
target_link_libraries(sentinel
${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Core_LIBRARIES}
qt optimization
)
kochmn#Ulyss:~/projects/sentinel/build$ cmake .
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Found Qt5Widgets Version 5.3.2
Core FOUND: 1
Gui FOUND: 1
Widgets FOUND: 1
Core VERSION: 5.3.2
Gui VERSION: 5.3.2
Widgets VERSION: 5.3.2
Core INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Gui INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtGui;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Widgets INCLUDE: /usr/include/x86_64-linux-gnu/qt5/;/usr/include/x86_64-linux-gnu/qt5/QtWidgets;/usr/include/x86_64-linux-gnu/qt5/QtGui;/usr/include/x86_64-linux-gnu/qt5/QtCore;/usr/lib/x86_64-linux-gnu/qt5//mkspecs/linux-g++-64
Core LIBRARIES: Qt5::Core
Gui LIBRARIES: Qt5::Gui
Widgets LIBRARIES: Qt5::Widgets
Core DEFINITIONS: -DQT_CORE_LIB
Gui DEFINITIONS: -DQT_GUI_LIB;-DQT_CORE_LIB
Widgets DEFINITIONS: -DQT_WIDGETS_LIB;-DQT_GUI_LIB;-DQT_CORE_LIB
Core COMPILE_DEFINITIONS: QT_CORE_LIB
Gui COMPILE_DEFINITIONS: QT_GUI_LIB;QT_CORE_LIB
Widgets COMPILE_DEFINITIONS: QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB
Core EXECUTABLE_COMPILE_FLAGS: -fPIE
Gui EXECUTABLE_COMPILE_FLAGS: -fPIE
Widgets EXECUTABLE_COMPILE_FLAGS: -fPIE
Using GnuCXX compiler.
Building DEBUG build.
Sentinel GL -- C++ Project V 0.1.
(c) Markus-Hermann Koch, mhk#markuskoch.eu, 2015/04/28-?
Primary directory is /home/kochmn/projects/sentinel/build
System is Linux
Generating configuration header: "/home/kochmn/projects/sentinel/build/../build/mhk_cmake_config.h"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kochmn/projects/sentinel/build
kochmn#Ulyss:~/projects/sentinel/build$ make
Scanning dependencies of target optimization_automoc
[ 5%] Automatic moc for target optimization
[ 5%] Built target optimization_automoc
Scanning dependencies of target optimization
[ 11%] Building CXX object CMakeFiles/optimization.dir/home/kochmn/projects/sentinel/src/optimization/linalg.cpp.o
[ 17%] Building CXX object CMakeFiles/optimization.dir/optimization_automoc.cpp.o
Linking CXX static library liboptimization.a
[ 17%] Built target optimization
Scanning dependencies of target qt_automoc
[ 23%] Automatic moc for target qt
[ 23%] Built target qt_automoc
Scanning dependencies of target qt
[ 29%] Building CXX object CMakeFiles/qt.dir/home/kochmn/projects/sentinel/src/qt/form_main.cpp.o
[ 35%] Building CXX object CMakeFiles/qt.dir/qt_automoc.cpp.o
Linking CXX static library libqt.a
[ 35%] Built target qt
Scanning dependencies of target sentinel_automoc
[ 41%] Automatic moc for target sentinel
[ 41%] Built target sentinel_automoc
[ 47%] Generating qrc_application.cpp
[ 52%] Generating ui_main.h
[ 58%] Generating moc_ui_main.cpp
/home/kochmn/projects/sentinel/build/ui_main.h:0: Note: No relevant classes found. No output generated.
[ 64%] Generating ui_dialog_setup_game.h
[ 70%] Generating moc_ui_dialog_setup_game.cpp
/home/kochmn/projects/sentinel/build/ui_dialog_setup_game.h:0: Note: No relevant classes found. No output generated.
Scanning dependencies of target sentinel
[ 76%] Building CXX object CMakeFiles/sentinel.dir/home/kochmn/projects/sentinel/src/sentinel.cpp.o
[ 82%] Building CXX object CMakeFiles/sentinel.dir/moc_ui_main.cpp.o
[ 88%] Building CXX object CMakeFiles/sentinel.dir/moc_ui_dialog_setup_game.cpp.o
[ 94%] Building CXX object CMakeFiles/sentinel.dir/qrc_application.cpp.o
[100%] Building CXX object CMakeFiles/sentinel.dir/sentinel_automoc.cpp.o
Linking CXX executable sentinel
[100%] Built target sentinel
CMake generation order is computed from dependencies between files and targets. If your qt library depends on headers generated from .ui files, then you have to add ${qt_UI_H} in inputs of target qt:
QT5_WRAP_UI(qt_UI_H ${qt_UI})
[...]
add_library(qt "${DIR_SRC}/qt/form_main.cpp" ${qt_UI_H})
And CMake should normally execute UIC on .ui files before compiling libqt
By the way using target_link_libraries only set dependencies between targets at link time. At compile time, the normal behavior is "All source files should be found". In your case, some headers are generated, so setting these headers as input of a target ensures that the macro which generates them (QT5_WRAP_UI) will be executed before the compilation of the target.