Converting a Jamroot file to CMakeLists - cmake

I'm currently working on a project and I'm trying to convert a jamroot script into a CMake script. Unfortunately, I'm facing some difficulties and I'm wondering if someone could help me.
in my jamroot I have the following:
import os ;
import common ;
local APVERSION = [ os.environ APVERSION ] ;
if ( --veracode in [ modules.peek : ARGV ] ) {
.gccflags = -gdwarf-2 -g3 -O0 -fno-builtin ;
}
project myProject
: requirements
<include>inc
<cxxflags>"-fPIC"
<define>QUICK_SUN=1
;
#library
use-project /system : $(G_ROOT)/system ;
alias tbb :/used_tbb//tbb/<link>shared/<optimization>speed ;
and this is what I did in my CMakeLists.txt file:
cmake_minimum_required (VERSION 2.8.11)
#Local Variables
set(APVERSION, [ os.environ APVERSION ]) #I don't know how to import os in CMake?
IF ( --veracode in [ modules.peek : ARGV ] )
.gccflags = -gdwarf-2 -g3 -O0 -fno-builtin
ENDIF()
project(myProject)
include_directories(inc)
IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} #[[-Wall -Wextra]] -fno-strict-aliasing -fPIC -speed ${.gccflags}")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -speed")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-DQUICK_SUN=1)
link_libraries(${G_ROOT}/system)
#for alias tbb, I can't figure out how to do it
can someone help me?
thank you

Related

How CMake automatically detects header dependencies

I wonder how CMake automatically detects that main.cpp depends on header.h
// header.h
int f() {
return 0;
}
// main.cpp
#include "header.h"
int main() {
return f();
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(Cppref)
add_executable(main main.cpp)
When I run cmake . -B build it creates the following make target in ./build/CMakeFiles/main.dir/build.make
CMakeFiles/main.dir/main.cpp.o: CMakeFiles/main.dir/compiler_depend.ts
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/nikolay/Cpp/Train/Cppref/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/main.dir/main.cpp.o"
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c /home/nikolay/Cpp/Train/Cppref/main.cpp
Pay attention to the -MD compiler option, as
it is used to dump dependencies visible to the preprocessor.
So after the first build it will create ./build/CMakeFiles/main.dir/main.cpp.o.d with the following content
CMakeFiles/main.dir/main.cpp.o: /home/nikolay/Cpp/Train/Cppref/main.cpp \
/home/nikolay/Cpp/Train/Cppref/header.h
So whenever you change header.h, the target main.o will be rebuilt.

Why No ops registered when I try to load frozen model in Android NDK?

I want to use c++ tensorflow API through ndk and cmake, I can create the library but when I load a frozen model a lot of errors like this when I try to load graph:
E/native: op_kernel.cc:1148 OpKernel ('op: "PopulationCount"
device_type: "CPU" constraint { name: "T" allowed_values { list {
type: DT_INT32 } } }') for unknown op: PopulationCount
So I understand that my library does not support the operations.
Do I need to add another library to support these operations?
I based my Cmake script on this Cmakelist and
I used the build_android_all.sh script to build the dependencies for armeabi-v7a.
This is how my cmake script looks like:
cmake_minimum_required(VERSION 3.4.1)
include(ExternalProject)
SET(PROJECT_NAME tf_native_lib)
SET(OpenCV_FOUND true )
SET(PREBUILT_DIR ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/gen)
SET(TARGET_NSYNC_LIB ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile /downloads/nsync/builds/${ANDROID_ABI}.android.c++11)
FIND_PACKAGE(OpenCV REQUIRED)
add_library( # Sets the name of the library.
${PROJECT_NAME}
SHARED
src/main/cpp/native-lib.h
src/main/cpp/native-lib.cpp
src/main/cpp/TensorflowInferenceHandler.h
src/main/cpp/TensorflowInferenceHandler.cpp
)
add_library(lib_proto STATIC IMPORTED )
set_target_properties(lib_proto PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/lib/libprotobuf.a)
add_library(lib_nsync STATIC IMPORTED )
set_target_properties(lib_nsync PROPERTIES IMPORTED_LOCATION
${TARGET_NSYNC_LIB}/libnsync.a)
add_library(lib_tf STATIC IMPORTED )
set_target_properties(lib_tf PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/lib/android_${ANDROID_ABI}/libtensorflow-core.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIS_SLIM_BUILD \
-std=c++11 -fno-rtti -fno-exceptions \
-O2 -Wno-narrowing -fomit-frame-pointer \
-mfpu=neon -mfloat-abi=softfp -fPIE -fPIC \
-ftemplate-depth=900 \
-DGOOGLE_PROTOBUF_NO_RTTI \
-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
-Wl,--allow-multiple-definition \
-Wl,--whole-archive \
-fPIE -pie -v")
# MESSAGE("tensorflow lib dir ${TENSORFLOW_LIB_DIR}")
target_link_libraries( # Specifies the target library.
${PROJECT_NAME}
${OpenCV_LIBS}
android
dl
log
m
z
jnigraphics
lib_tf
lib_proto
lib_nsync)
include_directories(
${OPENCV_INCLUDE_DIRS}
${PREBUILT_DIR}/proto
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/include
${PREBUILT_DIR}/nsync/public
${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/downloads/eigen
${TENSORFLOW_ROOT_DIR}/bazel-tensorflow/external/nsync/public
${TENSORFLOW_ROOT_DIR}/bazel-genfiles
${TENSORFLOW_ROOT_DIR}
../../../cpp_utils)
If this is not possible, where are the sources to link the tensorflow_inference.so with my Jni Sources?
Thanks in advance.
Unai.
The PopulationCount and few other Ops are declared in tensorflow/core/ops/bitwise_ops.cc. Add that file to the end of /tensorflow/contrib/makefile/tf_op_files.txt. Then recompile the Tensorflow. That is what worked for me.

including itensor library in my cmake project in clion

so I am very new to CLion and CMake, so sorry in advance for wrong usage of terminology. I am suffering the following problem:
In my project I want to include the ITensor library which is essentially a non-CMake project. I cloned the git to my computer and build the ITensor project. Next I wanted to use it in another project linking against it with CMake:
My Code in main.cpp:
#include <iostream>
#include "itensor.h"
int main() {
std::string some_string = "Hello world";
return 0;
}
and my CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.6)
project(tutorial)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(ITENSOR_DIR PATH/TO/ITENSOR)
include_directories(ITENSOR_DIR/itensor)
set(SOURCE_FILES
main.cpp
${ITENSOR_DIR}/itensor/itensor.h
${ITENSOR_DIR}/itensor/itensor.cc)
add_executable(tutorial ${SOURCE_FILES})
Unfortunately, the project 'tutorial' does not build in CLion. Likewise, CLion cannot resolve the dependency itensor.h.
Anybody an Idea for why this is, respectively how to fix it?
After trying Thomas5631's solution the compilation ran into linking issues with lapack. I solved this by adding some flags, though I'm not sure if all of them are required.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(my_project)
#Bring the headers into the project (full or relative path)
include_directories(itensor)
#Link the Itensor library
add_library(itensor STATIC IMPORTED)
set_property(TARGET itensor PROPERTY IMPORTED_LOCATION /home/david/my_project/itensor/lib/libitensor.a)
#Set a variable with all the new flags
set(ITENSOR_FLAGS "-DPLATFORM_lapack -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0")
set(ITENSOR_LINK_FLAGS "-DPLATFORM_lapack -L/home/david/my_project/itensor/lib -litensor -lpthread -L/usr/lib -lblas -llapack")
#Append the new flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${ITENSOR_FLAGS}")
add_executable(my_project main.cpp)
target_link_libraries(my_project itensor "${ITENSOR_LINK_FLAGS}")
Motivation: In the folder itensor/project_template there is a sample program which is simple enough to compile with make (from the terminal). The output of the compilation reveals the flags:
g++ -m64 -std=c++11 -c -I. -I/home/david/my_project/itensor -I/usr/include -O3 -DNDEBUG -Wall -DPLATFORM_lapack -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -Wno-unused-variable -o myappname.o myappname.cc
[... some warnings ...]
g++ -m64 -std=c++11 -c -I. -I/home/david/my_project/itensor -I/usr/include -O3 -DNDEBUG -Wall -DPLATFORM_lapack -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -Wno-unused-variable -o myclass.o myclass.cc
g++ -m64 -std=c++11 -I. -I/home/david/my_project/itensor -I/usr/include -O3 -DNDEBUG -Wall -DPLATFORM_lapack -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -Wno-unused-variable myappname.o myclass.o -o myappname -L/home/david/my_project/itensor/lib -litensor -lpthread -L/usr/lib -lblas -llapack
I got around the issue with the following main.cpp:
#include <iostream>
#include "itensor/itensor.h"
int main() {
std::string some_string = "Hello world";
return 0;
}
And the following CMakeLists.txt:
project(tutorial)
cmake_minimum_required(VERSION 3.6)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#Bring the headers into the project
include_directories(/home/tom/Documents/workspace/ITensor/)
#Link the library
add_library(itensor STATIC IMPORTED)
set_property(TARGET itensor PROPERTY IMPORTED_LOCATION /home/tom/Documents/workspace/ITensor/lib/libitensor.a)
set(SOURCE_FILES main.cpp)
add_executable(tutorial ${SOURCE_FILES})
Where the path to ITensor can be either relative (using the ${PROJECT_SOURCE_DIR} variable) or absolute as I have shown.

Converting cmake project to qmake

I am trying to convert a rather simple CMakeLists.txt to a qmake project. The project compiles fine but I can't get the output I want (the program files are the same!).
It shouldn't be a big deal, but I have spent the whole day and can't seem to figure out the problem. Any help would be greatly appreciated.
Here's the CMakeLists.txt that I am trying to convert:
cmake_minimum_required (VERSION 2.6)
PROJECT (sdpwrapper)
#set the default path for built executables to the "bin" directory
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
FIND_PACKAGE(OpenCV REQUIRED)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
ADD_LIBRARY(objdettrack
./src/MyPipe.cpp
./src/SDPWrapper.cpp
./src/online_tracker.cpp
./src/BaseObjectTracker2D.cpp)
INCLUDE_DIRECTORIES(include
/usr/include/python2.7
../dep/NOMT/include/
../dep/NOMT/dep/eigen/
../dep/NOMT/dep/libDAI-0.3.2/include/)
TARGET_LINK_LIBRARIES(objdettrack
${PROJECT_SOURCE_DIR}/../dep/NOMT/lib/libcppmodule.so
python2.7
${OpenCV_LIBS})
ADD_EXECUTABLE(example ./src/main.cpp)
TARGET_LINK_LIBRARIES(example objdettrack)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}")
ENDIF()
and here's the qmake project file I created:
QT += widgets
TARGET = ./build/DummyProject
#CONFIG += console
#CONFIG -= app_bundle
SOURCES += ./src/main.cpp \
./src/MyPipe.cpp \
./src/online_tracker.cpp \
./src/SDPWrapper.cpp \
./src/BaseObjectTracker2D.cpp
TEMPLATE = app
#TEMPLATE += lib
# ZEESHAN:INTEGRATION CODE
INCLUDEPATH += ./include
INCLUDEPATH += /usr/include/python2.7
INCLUDEPATH += /home/ma/zeeshan/code/Joint/KITTI_Jun2016/slam/app/faster-rcnn/dep/NOMT/include/
INCLUDEPATH += /home/ma/zeeshan/code/Joint/KITTI_Jun2016/slam/app/faster-rcnn/dep/NOMT/dep/eigen/
INCLUDEPATH += /home/ma/zeeshan/code/Joint/KITTI_Jun2016/slam/app/faster-rcnn/dep/NOMT/dep/libDAI-0.3.2/include/
QMAKE_LIBDIR += /home/ma/zeeshan/code/Joint/KITTI_Jun2016/slam/app/faster-rcnn/dep/NOMT/lib
LIBS += -lcppmodule
LIBS += -lpython2.7
LIBS += -lpynomt
QMAKE_LIBDIR += ../../faster-rcnn/cpp/lib
LIBS += -Lobjdettrack
CONFIG += link_pkgconfig
PKGCONFIG += opencv
QMAKE_CXXFLAGS+= -fopenmp
QMAKE_LFLAGS += -fopenmp
Any suggestions would be highly appreciated.
Zeeshan

Cmake test program cannot find -lgcc_s

I'm using cmake with custom GCC(with shared libraries) and during cmake compiler test I get following error:
The C compiler "/path/to/gcc/bin/gcc" is not able to compile a simple test program.
...
/path/to/gcc/x86_64-unknown-linux-gnu/bin/ld:
cannot find -lgcc_s
Here's a simple "testme.cpp" file:
#include <iostream>
int main( int argc, char * argv[] ) {
std::cout << "Hello world" << std::endl;
return 0;
}
and here's a CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.2)
project(testme)
file( GLOB srcs "testme.cpp" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -std=c++11")
set(CMAKE_LDFLAGS "${CMAKE_LDFLAGS} -L/path/to/gcc/lib/gcc/x86_64-unknown-linux-gnu/lib64")
add_executable(testme ${srcs})
to build with my custom GCC I'm exporting CXX and CC:
export CXX=/path/to/gcc/bin/g++
export CC=/path/to/gcc/bin/gcc
and then hit:
cmake .
make
and the result is that it can't find libgcc_s.so which is located in the "lib/gcc/x86_64-unknown-linux-gnu/lib64" folder.
However, when I invoke gcc like this:
/path/to/gcc/bin/g++ testme.cpp -L/path/to/gcc/lib/gcc/x86_64-unknown-linux-gnu/lib64
it compiles successfully. I've tried to add it to LD_LIBRARY_PATH but that doesn't seem to help.
So, is there a way to pass library path to CMake compiler check?
Chrono Kitsune was sort of right ... /path/to/gcc/x86_64-unknown-linux-gnu/bin/ld was build with "--enable-shared" and libraries where not in systems search path.