I have a problem when I include ZBar in my C++ script. I already tried adding it via a CMakelists.txt:
cmake_minimum_required(VERSION 2.8.12)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} ${ZBARCV_SOURCE_DIR} )
set(CMAKE_MODULE_PATH ${ZBARCV_SOURCE_DIRS})
add_compile_options(-std=c++11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries( program src ${OpenCV_LIBS} ${ZBAR_LIBRARIES} zbar )
I'm on mac. I looked and my zbar.h file is located in /usr/local/include/ where it's supposed to be.
I include it like this: #include <zbar.h>
I hope someone is able to help me. Thanks in advance!
EDIT:
Full make error log:
/Users/mathijs/Documents/Barcode-cpp/src/Barcodes.h:7:10: fatal error: 'zbar.h' file not found
#include <zbar.h>
^~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/src.dir/src/VideoVeed.cpp.o] Error 1
make[1]: *** [CMakeFiles/src.dir/all] Error 2
make: *** [all] Error 2
I just checked; the Brew package for ZBar includes a packageconfig file (zbar.pc)
That means you can use modern CMake tooling instead of cargo culting:
cmake_minimum_required(VERSION 3.8)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries(program src ${OpenCV_LIBS})
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBar REQUIRED IMPORTED_TARGET zbar)
target_link_libraries(program PkgConfig::ZBar)
The pkg_check_modules will read the zbar.pc file and generate an IMPORTED target named PkgConfig::ZBar that will automatically set both include paths and linker paths for program.
Related
I was trying to build GTest from source and then link my target to it using cmake. But I see this error
mygtest % cmake --build build
[ 50%] Building CXX object CMakeFiles/hello_test.dir/mytest.cpp.o
/path/to/test/mygtest/mytest.cpp:1:10: fatal error: 'gtest/gtest.h' file not found
#include <gtest/gtest.h>
^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/hello_test.dir/mytest.cpp.o] Error 1
make[1]: *** [CMakeFiles/hello_test.dir/all] Error 2
make: *** [all] Error 2
My question is what may I miss here?
This is my CMakeList File
cmake_minimum_required(VERSION 3.14)
project(my_project)
set(CMAKE_CXX_STANDARD 14)
find_library(
GTEST_MAIN
gtest_main
PATHS /path/to/googletest/build/lib/
NO_DEFAULT_PATH
)
enable_testing()
add_executable(
hello_test
mytest.cpp
)
target_link_libraries(
hello_test
${GTEST_MAIN}
)
include(GoogleTest)
gtest_discover_tests(hello_test)
What did I try?
Printing the target's link libraries
get_target_property(HELLO_TEST_LIBRARIES hello_test LINK_LIBRARIES)
include(CMakePrintHelpers)
cmake_print_variables(HELLO_TEST_LIBRARIES)
// OUTPUT
-- HELLO_TEST_LIBRARIES="/path/to/googletest/build/lib/libgtest_main.a"
using find_package(GTest) and then linking GTest::gtest works, but I don't want to use a precompiled version -- it seems to cause the error "Unfound Symbol" as mentioned here
I am open to any other better answers, but would post my current solution for those who might be interested.
Thanks #Alex Reinking and #SpacePotatoes for comments. based on what's suggested, inserting the following piece of codes to your CMakeLists.txt would allow you to automate the process of downloading googletest and building from source.
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
SUBBUILD_DIR ${PROJECT_BINARY_DIR}/googletest-subbuild
BINARY_DIR ${PROJECT_BINARY_DIR}/googletest-build
SOURCE_DIR ${PROJECT_BINARY_DIR}/googletest-src
)
FetchContent_Populate(
googletest
)
execute_process(COMMAND cmake -S. -B${googletest_BINARY_DIR} WORKING_DIRECTORY ${googletest_SOURCE_DIR})
execute_process(COMMAND cmake --build . WORKING_DIRECTORY ${googletest_BINARY_DIR})
set(GTEST_LIBRARY ${googletest_BINARY_DIR}/lib/libgtest.a)
set(GTEST_INCLUDE_DIR ${googletest_SOURCE_DIR}/googletest/include)
set(GTEST_MAIN_LIBRARY ${googletest_BINARY_DIR}/lib/libgtest_main.a)
find_package(GTest REQUIRED)
Then you might be able to link to your target with
target_link_libraries(<target> GTest::gtest_main)
Hello I was working on a C++ project, and had a cmake file that was working just fine, until I tried to add cuda into the C++ project. I am building this project on the NVIDIA Jetson Nano.
I get this error while building:
nvlink fatal : Could not open input file 'CMakeFiles/MY_APP.dir/src/MY_APP.cpp.o' (target: sm_35)
The rest of the error underneath that looks like this:
CMakeFiles/MY_APP.dir/build.make:552: recipe for target
'CMakeFiles/MY_APP.dir/cmake_device_link.o' failed
make[2]: *** [CMakeFiles/MY_APP.dir/cmake_device_link.o] Error 1
make[2]: Leaving directory '/home/me/Code/MyApp/build'
CMakeFiles/Makefile2:127: recipe for target 'CMakeFiles/MY_APP.dir/all' failed
make[1]: *** [CMakeFiles/MY_APP.dir/all] Error 2
make[1]: Leaving directory '/home/me/Code/MY_APP/build'
Makefile:155: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/home/me/Code/MY_APP/build'
I run my cmake file using a script I called confgure.sh, which looks like this:
#!/bin/sh
cmake -S . -B build -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-10.2/bin/nvcc
I run my make file using a script I called build.sh, which looks like this:
#!/bin/sh
make -C build
My Cmake File looks like this:
cmake_minimum_required(VERSION 3.21.0)
project(MY_APP VERSION 0.0.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
enable_language(CUDA)
# Pass options to NVCC
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3 -gencode arch=compute_35,code=sm_35
)
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
FILE(GLOB_RECURSE MY_CUDA_SRCS src/*.cu)
configure_file(src/MyAppConfig.h.in MyAppConfig.h)
#collect cpp files
FILE(GLOB_RECURSE SRC src/*.cpp)
find_package(CUDA QUIET)
if(CUDA_FOUND)
SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
include_directories(${CUDA_INCLUDE_DIRS})
get_filename_component(CUDA_LIBRARY_DIR ${CUDA_CUDART_LIBRARY} DIRECTORY)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-L${CUDA_LIBRARY_DIR}")
SET(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})
#${CUDA_CUDART_LIBRARY}
#${CMAKE_CUDA_RUNTIME_LIBRARY}
#)
SET(LIBS ${LIBS} ${ALL_CUDA_LIBS})
message(STATUS "CUDA_LIBRARIES: ${CUDA_INCLUDE_DIRS} ${ALL_CUDA_LIBS}")
set(CUDA_PROPAGATE_HOST_FLAGS ON)
set(CUDA_SEPARABLE_COMPILATION ON)
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_35,code=sm_35)
#collect CUDA files
FILE(GLOB_RECURSE CUDA_SRC src/*.cu)
#build static library
#CUDA_ADD_LIBRARY(my_cuda_lib ${CUDA_SRC} STATIC)
cuda_compile(cuda_objs ${CUDA_SRC})
SET(SRC ${cuda_objs} ${SRC})
SET(LIBS ${LIBS} ${my_cuda_lib})
endif()
link_libraries(${cuda_objs})
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CUDA)
message("using cuda_add_executable")
cuda_add_executable(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} ${LIBS})
#DOWNLOAD ALL THE SUBMODULES
find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE, "Check submodules during build" ON)
if (GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE}
submodule update --init --recursvie
WORKING_DIRECTORY {CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE_GIT_SUBMOD_RESULT)
if (NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR
"git submodule update --init failed with ${GIT_SUMOD_RESULT},
please check submodule")
endif()
endif()
endif()
#CHECK ALL THE SUBMODULES
if (NOT EXISTS
"${PROJECT_SOURCE_DIR}/external/Simple-Websocket-Server/CMakeLists.txt")
message(FATAL_ERROR
"The Simple-Websocket-Server submodule was not downloaded!
GIT_SUBMODULE was turned off or failed. Please update submodule")
endif()
add_subdirectory(external/Simple-Websocket-Server)
include_directories(PUBLIC external/Simple-Websocket-Server)
find_package(PythonLibs REQUIRED)
find_package(pybind11 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}
curl pthread crypto boost_system jsoncpp ${PYTHON_LIBRARIES} cudart
#<some-of-my-other-libraries>
)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/MyAppConfig.h" DESTINATION include)
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${MY_APP_VERSION_PATCH}")
include(CPack)
set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
"${CMAKE_CUDA_COMPILER} ${_CMAKE_CUDA_EXTRA_FLAGS} -c ${MY_CUDA_SRCS}")
message(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION)
I am lost on how to get CUDA added to my project that already contains a bunch of C++ files, and I need to be able to call my .cu files from a .cpp file other then main.cpp, and I need to get this building in CMake, and I am doing it on the jetson nano. Any help on solving this error?
You are mixing up a lot of CUDA-related definitions and commands, including some from an earlier "era" of CUDA support in CMake.
Among other things:
Your CMakeLists.txt is overriding your environment setting for the CUDA compiler location.
... and actually, you shouldn't bother setting that location anyway, since you've already set the CUDA toolkit root.
Don't use find_package(CUDA) with CMake versions of 3.17 or 3.18, or later. For all relevant toolkit-related paths, use find_package(CUDAToolkit)`, which does... well, less but also more.
Don't use cuda_add_+suffix commands. Since CMake supports CUDA natively, you use regular add_executable, add_library etc.
There are further issues with your CMakeLists.txt file - not all of them CUDA-related, but that should be enough to get you started. It may not in itself resolve the specific bottom-line problem you have, though.
You may want to have a look at public repositories using CUDA and recent CMake versions to get an idea of how this is done.
I have two git repositories with CMake, one is a game engine, and the other is a game that I am making with the game engine.
It turns out, this game engine has a submodule that is included in the project's CMakeLists.txt, and in the game repository, the game engine is added as a submodule that is also included in CMakeLists.txt. However, when compiling the two projects, the Game Engine compiles everything normal without errors, I update the game repository to update the submodules, and when compiling the game, it does not find the game engine submodule for some unknown reason.
Game Engine CMakeLists:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Enel")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/spdlog/include"
"${PROJECT_SOURCE_DIR}/libs/spdlog/src"
)
file(GLOB SRC_FILES
"${PROJECT_SOURCE_DIR}/include/**/*.h"
"${PROJECT_SOURCE_DIR}/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/include/**/*.hpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
)
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
Game CMakeLists:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Minicraft")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/enel/include"
"${PROJECT_SOURCE_DIR}/libs/enel/src"
)
link_directories(${PROJECT_SOURCE_DIR}/libs/enel)
file(GLOB SRC_FILES
"${PROJECT_SOURCE_DIR}/include/**/*.h"
"${PROJECT_SOURCE_DIR}/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/include/**/*.hpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.c"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.h"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${SRC_FILES})
Build Output:
[ 33%] Building CXX object CMakeFiles/Minicraft.dir/src/MC/Game.cc.o
In file included from /home/yorichii/repos/minicraft/libs/enel/include/Enel/Platform/EntryPoint.hh:4,
from /home/yorichii/repos/minicraft/src/MC/Game.cc:2:
/home/yorichii/repos/minicraft/libs/enel/include/Enel/Util/Log.hh:3:10: fatal error: spdlog/spdlog.h: Arquivo ou diretório inexistente
3 | #include <spdlog/spdlog.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/Minicraft.dir/build.make:76: CMakeFiles/Minicraft.dir/src/MC/Game.cc.o] Erro 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/Minicraft.dir/all] Erro 2
make: *** [Makefile:84: all] Erro 2
If you use directory based property like include_directory or link_directory, you'll have to repeat requirements:
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/enel/include"
"${PROJECT_SOURCE_DIR}/libs/enel/src"
# Repeat all requirements
"${PROJECT_SOURCE_DIR}/libs/enel/libs/spdlog/include"
"${PROJECT_SOURCE_DIR}/libs/enel/libs/spdlog/src"
)
This is why you should strongly consider target based property, as all modern build system are using, including modern CMake:
In Enel:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Enel")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
# If you can install spdlog in a local directory in the project,
# prefer find_package(spdlog REQUIRED)
add_subdirectrory(libs/spdlog)
file(GLOB SRC_FILES
"strongly/consider/not/globbing/**/*.cpp"
)
add_library(Enel STATIC ${SRC_FILES})
target_link_libraries(Enel PUBLIC spdlog)
target_include_directories(Enel PUBLIC src include)
Then in your game, do this:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Minicraft")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
add_subdirectory(libs/enel)
file(GLOB SRC_FILES
...
)
add_executable(Minicraft ${SRC_FILES})
# Links to all required libraries, add all required include directories
target_link_libraries(Minicraft PUBLIC Enel)
target_include_directory(Minicraft PUBLIC include src)
I have a simple cmake project going that I can't get to compile on OS X 10.8.4. The cmake/make process works great on Linux but on OS X I am getting this error:
Linking CXX static library libImageFilter.a
ar: no archive members specified
...
make[2]: *** [lib/libImageFilter.a] Error 1
make[1]: *** [lib/CMakeFiles/ImageFilter.dir/all] Error 2
make: *** [all] Error 2
I am using the Eclipse CDT4 Generator Unix MakeFile on both platforms. This seems like something to with the difference between ar on the two systems. But, I couldn't find much on google to help me troubleshoot.
Here is some more info for you
src/CMakeList.txt
make_minimum_required(VERSION 2.8)
project(itkNormals)
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
add_subdirectory(test)
add_subdirectory(lib)
src/lib/CMakeList.txt
add_library(DotImageFilter itkDotImageFilter.h)
SET_TARGET_PROPERTIES(DotImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(DotImageFilter ${ITK_LIBRARIES})
add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})
src/test/CMakeLists.txt:
include_directories(${PROJECT_SOURCE_DIR}/lib)
add_executable(itkNormalsMain itkNormals.cxx)
TARGET_LINK_LIBRARIES(itkNormalsMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(itkNormalsMain ImageFilter)
TARGET_LINK_LIBRARIES(itkNormalsMain DotImageFilter)
add_executable(dotTestMain dotTester.cxx)
TARGET_LINK_LIBRARIES(dotTestMain ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(dotTestMain ImageFilter)
TARGET_LINK_LIBRARIES(dotTestMain DotImageFilter)
add_executable(IST ImageSourceTest.cxx)
TARGET_LINK_LIBRARIES(IST ${ITK_LIBRARIES})
TARGET_LINK_LIBRARIES(IST ImageFilter)
You can't create library from one header file:
add_library(ImageFilter itkImageFilter.hxx)
SET_TARGET_PROPERTIES(ImageFilter PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(ImageFilter ${ITK_LIBRARIES})
that's the reason why you set LINKER_LANGUAGE explicitly - there is nothing to link and cmake is confused.
So include_directories is enough:
include_directories(${PROJECT_SOURCE_DIR}/lib)
BTW:
You don't need to check ITK_FOUND if you specify REQUIRED:
FIND_PACKAGE (ITK REQUIRED)
IF( ITK_FOUND )
include( ${ITK_USE_FILE} )
ENDIF( ITK_FOUND )
from documentation:
The REQUIRED option stops processing with an error message if the package cannot be found.
PROJECT_SOURCE_DIR is not necessary equal itkNormals_SOURCE_DIR (you may use this file from other project):
include_directories(${PROJECT_SOURCE_DIR}/lib)
Can be fixed one of this way:
include_directories(${itkNormals_SOURCE_DIR}/lib)
include_directories(${CMAKE_CURRENT_LIST_DIR}/../lib)
or simply include from parent file:
# src/CMakeLists.txt
include_directories("./lib")
I was able to successfully configure and generate the build folder (KinectSLAM6D/build.). However, when I try to build it using make, I got an error saying gsl is not found. I am pretty sure this is just a configuration issue as I have gsl installed (they're in usr/local), but I am unable to configure it. I have tried adding the following lines to CMakeList:
include_directories(${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GSL_LIBRARIES} ${GSLCBLAS_LIBRARIES})
I have copied the pertinent output below. I have found a couple of answers to compiling with gsl (adding -lgsl). However, I have no clue where to put that in CMakeLists or the generated MakeList and MakeList2 files.
Here's the generated output.
....
[ 44%] Building CXX object CMakeFiles/Kinect6DSLAM.dir/src/GraphOptimizer_G2O.cpp.o
[ 45%] Building CXX object CMakeFiles/Kinect6DSLAM.dir/src/CKinect2DRawlog.cpp.o
Linking CXX executable Kinect6DSLAM
/usr/bin/ld: warning: libopencv_core.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_core.so.2.4
/usr/bin/ld: warning: libopencv_imgproc.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: warning: libopencv_highgui.so.2.3, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmrpt-base.so, may conflict with libopencv_highgui.so.2.4
../gicp/libgicp.a(gicp.o): In function `dgc::gicp::GICPPointSet::ComputeMatrices()':
gicp.cpp:(.text+0x462): undefined reference to `gsl_vector_alloc'
gicp.cpp:(.text+0x470): undefined reference to `gsl_vector_alloc'
... a bunch more undefined references to gsl
collect2: ld returned 1 exit status
make[2]: *** [Kinect6DSLAM] Error 1
make[1]: *** [CMakeFiles/Kinect6DSLAM.dir/all] Error 2
make: *** [all] Error 2
This if the full CMakeList.txt. I am trying to run Miguel Algaba's SLAM project.
PROJECT(KinectSLAM6D)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
endif(COMMAND cmake_policy)
# Set the output directory for the build executables
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
#Add here your project dependencies
FIND_PACKAGE(MRPT REQUIRED hwdrivers maps graphslam) #Add here your project dependencies
FIND_PACKAGE(PCL REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED )
INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCL_LIBRARY_DIRS})
ADD_DEFINITIONS(${PCL_DEFINITIONS})
# Required by StanfordGICP
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
FIND_PACKAGE(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GSL_LIBRARIES} ${GSLCBLAS_LIBRARIES})
FIND_PACKAGE(Boost COMPONENTS system program_options REQUIRED)
include_directories(${PROJECT_SOURCE_DIR}/gicp)
include_directories(${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/include/ANN)
# G2O library
# Set up the top-level include directories
SET( G2O_INCLUDE ${PROJECT_SOURCE_DIR}/EXTERNAL/g2o CACHE PATH "Directory of G2O")
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${G2O_INCLUDE})
# Add g2o lib dir
LINK_DIRECTORIES( ${LINK_DIRECTORIES} "${G2O_INCLUDE}/lib" )
#Generate config.h
configure_file(g2o/trunk/config.h.in ${PROJECT_BINARY_DIR}/g2o/config.h)
include_directories(${PROJECT_BINARY_DIR})
INSTALL(FILES ${PROJECT_BINARY_DIR}/g2o/config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/g2o)
# Include the subdirectories
ADD_SUBDIRECTORY(g2o/trunk)
INCLUDE_DIRECTORIES(${CSPARSE_INCLUDE_DIR}) #You can use CPARSE or CHOLMOD
INCLUDE_DIRECTORIES(${CHOLMOD_INCLUDE_DIR})
set(G2O_DIR ${PROJECT_SOURCE_DIR}/g2o/trunk)
include_directories(${G2O_DIR})
link_directories(${G2O_DIR}/lib)
# Declare the target (an executable)
ADD_EXECUTABLE(Kinect6DSLAM kinect6DSLAM.cpp
./include/KinectGrabber.h
./include/KinectGrabber_OpenNI.h
./src/KinectGrabber_OpenNI.cpp
./include/KinectGrabber_Rawlog.h
./src/KinectGrabber_Rawlog.cpp
./include/KinectGrabber_Rawlog2.h
./src/KinectGrabber_Rawlog2.cpp
./include/KinectGrabber_MRPT.h
./src/KinectGrabber_MRPT.cpp
./include/VisualFeatureDescriptorExtractor.h
./include/VisualFeatureDescriptorExtractor_SURF_GPU.h
./include/VisualFeatureDescriptorExtractor_Generic.h
./include/VisualFeatureDescriptorExtractor_ORB.h
./include/VisualFeatureMatcher.h
./include/VisualFeatureMatcher_Generic.h
./include/PointCloudViewer.h
./include/PointCloudViewer_MRPT.h
./src/VisualFeatureDescriptorExtractor_SURF_GPU.cpp
./src/VisualFeatureDescriptorExtractor_Generic.cpp
./src/VisualFeatureDescriptorExtractor_ORB.cpp
./src/VisualFeatureMatcher_Generic.cpp
./src/PointCloudViewer_MRPT.cpp
./include/Visual3DRigidTransformationEstimator.h
./include/Visual3DRigidTransformationEstimator_SVD.h
./src/Visual3DRigidTransformationEstimator_SVD.cpp
./include/Visual3DRigidTransformationEstimator_RANSAC.h
./src/Visual3DRigidTransformationEstimator_RANSAC.cpp
./include/ICPPoseRefiner.h
./include/ICPPoseRefiner_PCL.h
./src/ICPPoseRefiner_PCL.cpp
./include/ICPPoseRefiner_StanfordGICP.h
./src/ICPPoseRefiner_StanfordGICP.cpp
./include/Miscellaneous.h
./src/Miscellaneous.cpp
./include/FrameRGBD.h
./src/FrameRGBD.cpp
./include/PointCloudDownsampler.h
./src/PointCloudDownsampler.cpp
./include/KeyframeLoopDetector.h
./src/KeyframeLoopDetector.cpp
./include/GraphOptimizer.h
./include/GraphOptimizer_MRPT.h
./src/GraphOptimizer_MRPT.cpp
./include/GraphOptimizer_G2O.h
./src/GraphOptimizer_G2O.cpp
./include/CKinect2DRawlog.h
./src/CKinect2DRawlog.cpp
)
TARGET_LINK_LIBRARIES(Kinect6DSLAM ${MRPT_LIBS}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${Boost_LIBRARIES}
#GICP
${GSL_LIBRARIES}
${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/lib/libANN.a
${PROJECT_SOURCE_DIR}/gicp/libgicp.a
#G2O
core math_groups types_slam3d
solver_csparse #You can use CPARSE or CHOLMOD
solver_cholmod ${CHOLMOD_LIBRARIES}
)
# Declare the target (an executable)
ADD_EXECUTABLE(PairwiseAlignmentSteps PairwiseAlignmentSteps.cpp
./include/KinectGrabber.h
./include/KinectGrabber_OpenNI.h
./src/KinectGrabber_OpenNI.cpp
./include/KinectGrabber_Rawlog.h
./src/KinectGrabber_Rawlog.cpp
./include/KinectGrabber_MRPT.h
./src/KinectGrabber_MRPT.cpp
./include/VisualFeatureDescriptorExtractor.h
./include/VisualFeatureDescriptorExtractor_SURF_GPU.h
./include/VisualFeatureDescriptorExtractor_Generic.h
./include/VisualFeatureDescriptorExtractor_ORB.h
./include/VisualFeatureMatcher.h
./include/VisualFeatureMatcher_Generic.h
./include/PointCloudViewer.h
./include/PointCloudViewer_MRPT.h
./src/VisualFeatureDescriptorExtractor_SURF_GPU.cpp
./src/VisualFeatureDescriptorExtractor_Generic.cpp
./src/VisualFeatureDescriptorExtractor_ORB.cpp
./src/VisualFeatureMatcher_Generic.cpp
./src/PointCloudViewer_MRPT.cpp
./include/Visual3DRigidTransformationEstimator.h
./include/Visual3DRigidTransformationEstimator_SVD.h
./src/Visual3DRigidTransformationEstimator_SVD.cpp
./include/Visual3DRigidTransformationEstimator_RANSAC.h
./src/Visual3DRigidTransformationEstimator_RANSAC.cpp
./include/ICPPoseRefiner.h
./include/ICPPoseRefiner_PCL.h
./src/ICPPoseRefiner_PCL.cpp
./include/ICPPoseRefiner_StanfordGICP.h
./src/ICPPoseRefiner_StanfordGICP.cpp
./include/Miscellaneous.h
./src/Miscellaneous.cpp
./include/FrameRGBD.h
./src/FrameRGBD.cpp
./include/PointCloudDownsampler.h
./src/PointCloudDownsampler.cpp
)
TARGET_LINK_LIBRARIES(PairwiseAlignmentSteps ${MRPT_LIBS}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${Boost_LIBRARIES}
#GICP
${GSL_LIBRARIES}
${PROJECT_SOURCE_DIR}/gicp/ann_1.1.1/lib/libANN.a
${PROJECT_SOURCE_DIR}/gicp/libgicp.a
)
# Set optimized building:
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mtune=native")
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
target_link_libraries(Kinect6DSLAM ${LIBS})
Something tells me, that adding target_link_libraries(Kinect6DSLAM ${LIBS}) will help you.
Also, instead of constructs like
set(VAR ${VAR} somethingelse)
you can use this:
list(APPEND VAR somethingelse)