I am trying to set up an OpenCV C++ project using VS Code. I am able to compile the project just fine from the command line, by manually generating CMakeLists.txt:
# CMakeLists.txt
cmake_minimum_required(VERSION "3.17")
project(simple-demo)
# set OpenCV_DIR variable equal to the path to the cmake install
set(OpenCV_DIR /Users/tstoff/git/opencv/install/lib/cmake/opencv4)
# Tell compiler to use C++ 14 features
set(CMAKE_CXX_STANDARD 14)
# configure the necessary common CMake environment variables
# needed to include and link the OpenCV program into this
# demo project, namely OpenCV_INCLUDE_DIRS and OpenCV_LIBS
find_package( OpenCV REQUIRED )
# tell the build to include the headers from OpenCV
include_directories( ${OpenCV_INCLUDE_DIRS} )
# specify the executable target to be built
add_executable(simple-demo main.cpp)
# tell it to link the executable target against OpenCV
target_link_libraries(simple-demo ${OpenCV_LIBS} )
which I can build using make and cmake .. from a build directory. But I want to use the power of the VS Code CMake Tools library! How do I add external libraries to VS Code projects, preferably using CMake Tools? Many thanks!
Related
I am following ROS–Unity Integration tutorial for ROS2. I coppied unity_robotics_demo and unity_robotics_demo_msgs to my src folder from here. When building unity_robotics_demo_msgs gives me an error. I did source install/setup.bash and colcon build. Error:
CMake Error at CMakeLists.txt:7 (find_package):
By not providing "Findrosidl_default_generators.cmake" in CMAKE_MODULE_PATH
this project has asked CMake to find a package configuration file provided
by "rosidl_default_generators", but CMake did not find one.
Could not find a package configuration file provided by
"rosidl_default_generators" with any of the following names:
rosidl_default_generatorsConfig.cmake
rosidl_default_generators-config.cmake
Add the installation prefix of "rosidl_default_generators" to
CMAKE_PREFIX_PATH or set "rosidl_default_generators_DIR" to a directory
containing one of the above files. If "rosidl_default_generators" provides
a separate development package or SDK, be sure it has been installed.
I am not sure how to add the installation prefix. In foxy/share there is rosidl_default_generators:
I'm trying NetBeans as my new IDE for c++. I would love to use conan.io as package manager.
My conanfile.py looks like this (from the conan site):
class MyConanTestProj(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "Protobuf/3.1.0#inexorgame/stable", "Boost/1.64.0#conan/stable" # comma separated list of requirements
generators = "cmake", "txt"
default_options = "Poco:shared=True", "OpenSSL:shared=True", "Boost:shared=True"
def imports(self):
self.copy("*.dll", dst="bin", src="bin") # From bin to bin
self.copy("*.dylib*", dst="bin", src="lib") # From lib to bin
# self.copy('*.so*', dst='bin', src='lib')
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
My CMakeLists.txt:
project(MyTestProj)
cmake_minimum_required(VERSION 2.8.12)
add_definitions("-std=c++14")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(testProj testProj.cpp)
target_link_libraries(testProj ${CONAN_LIBS})
testProj.cpp: (just to see it compile and link...)
#include <boost/filesystem.hpp>
int main(void) { return 0; }
When I create a build dir and run conan install and so on it works:
mkdir build -p && cd build && conan install .. && cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release && cmake --build
But in NetBeans it shows me an unresolved include (netbeans has no idea there conan has stored the boost files).
How to configurate netbeans to use the include paths generated by conan?
Conan created conanbildinfo.cmake and conanbuildinfo.txt with the full paths included but i don't know how to use them in netbeans.
Hope someone could tell me how to setup this correctly (or give me a short example project for netbeans) - Thanks!
Netbeans might be using a particular build folder layout, as previous versions of CLion did in the past, just putting the "temporary" build folders somewhere in the system.
I guess that the CMake execution is complaining about not finding the conanbuildinfo.cmake file, not the Boost headers.
So, the first thing is to know which folder is being used by Netbeans as CMake binary dir. You could add to your CMakeLists.txt:
if(NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(FATAL_ERROR "Missing conanbuildinfo. Move to ${CMAKE_BINARY_DIR} folder, and run conan install there")
endif()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
Then, just cd to that folder, conan install with the respective configuration (note that this process may need to be run for different configurations, like Debug/Release).
I'm trying to integrate cmake into a project that contains a Unity3D project. I want to bypass checks for languages, as the CMakeLists.txt file really just houses a custom command that calls Unity3D's build process. I'm aware of the LANGUAGES NONE setting in the project() command, and also a similar setting in the set_target_properties() command. However, neither seem to be working. My complete CMakeLists.txt file is pasted below:
cmake_minimum_required (VERSION 3.8)
project (
"Test-App"
VERSION
1.0
LANGUAGES
NONE
)
# For the custom command to be marked as not actually creating a file,
# you need to set the symbolic property on it
#set_property (
# SOURCE
# UNITY_OUTPUT
# PROPERTY
# SYMBOLIC
#)
add_custom_command (
OUTPUT
UNITY_OUTPUT
COMMAND
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -buildOSXUniversalPlayer ${CMAKE_SOURCE_DIR}/Builds/Test-Build.app
COMMENT
"Building application..."
)
add_executable (
Test-Build
UNITY_OUTPUT
)
set_target_properties (
Test-Build
PROPERTIES
LINKER_LANGUAGE
NONE
)
However, in my tereminal output cmake is still complaining that an internal variable has not been set. I get the following output:
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_NONE_LINK_EXECUTABLE
-- Generating done
-- Build files have been written to: XXX
Note that the Makefile is still generated and I can still build stuff. I simply want to get rid of this annoying error, to be sure that I fully understand how CMake is operating.
While compiling Swift on Mac machine, there is a dynamic library libswiftDemangle.dylib created. I need the dynamic library created on Linux machine as well, however, the dynamic library isn't created after a compilation of a source code.
The file CMakeLists.txt at lib/SwiftDemangle/CMakeLists.txt contains:
add_swift_library(swiftDemangle SHARED
SwiftDemangle.cpp
MangleHack.cpp
LINK_LIBRARIES swiftBasic)
directive, however the library isn't created.
I use this command ./swift/utils/build-script -R -c --build-subdir build --install-prefix /mnt/servers/swift/install -j4 to build the project, eventually it runs cmake and ninja to build the project.
Any ideas?
I can take a shot at explaining why the library is not getting built on Linux, even if it's late probably.
The main subdirectory containing the library you mention is:
https://github.com/apple/swift/tree/master/lib
To build the libs in that directory, which are organized in subdirectories, the following CMakeLists.txt is used:
https://github.com/apple/swift/blob/master/lib/CMakeLists.txt.
As can be clearly seen in this file, the library that you mention is only built if the system is OSX/Darwin and not in the Linux case. The relevant code in the aforementioned CMakeLists.txt is:
add_subdirectory(RemoteAST)
add_subdirectory(Sema)
add_subdirectory(Serialization)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(SwiftDemangle)
endif()
add_subdirectory(SIL)
add_subdirectory(SILGen)
As you can see it,
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(SwiftDemangle)
endif()
prevents SwiftDemangle to be built on Linux.
A superficial double check can be to look at:
https://github.com/apple/swift/blob/master/lib/SwiftDemangle/CMakeLists.txt
which will install or simlynk only *.dylib files.
It it worth mentioning that the swift-demangle tool (different from what you asked)
https://github.com/apple/swift/tree/master/tools/swift-demangle
is built on Linux.
I am trying to create an eclipse project from a cmake project .
I used the following command
cmake -G "Eclipse CDT4 - Unix Makefiles" ./`
it gives the following error
CMake Error at CMakeLists.txt:119 (find_package):
By not providing "FindGlib.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Glib", but
CMake did not find one.
Could not find a package configuration file provided by "Glib" (requested
version 2.28) with any of the following names:
GlibConfig.cmake
glib-config.cmake
Add the installation prefix of "Glib" to CMAKE_PREFIX_PATH or set
"Glib_DIR" to a directory containing one of the above files. If "Glib"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
I have glib installed . actually it couldn't resolve the path i guess. wherever find is there in cmake file , it is giving the smiler errors. please i suggest a way out, i badly need to load this project in cmake. Thanks.
Here is line 119 where error message is pointing
find_package(Glib 2.28 REQUIRED)
include_directories(${Glib_INCLUDE_DIRS})
list(APPEND LIBS ${Glib_LIBRARIES})
add_definitions(${Glib_DEFINITIONS})
When you call find_package(MyPackage) in a CMake file, it tries to find a FindMyPackage.cmake configuration in its system path (/usr/share/cmake-2.8/Modules on my Ubuntu box), or in the directory you did specify as CMAKE_MODULE_PATH).
The solution to your problem is to create a directory for modules in your source tree (e.g. CMakeModules), put in it a FindGlib.cmake file that you can find using Google, and add
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
in your CMakeLists.txt before the actual call to find_package.
(your problem is not related to the Eclipse generator, you could remove that from the title of the question).