Recently, I do my project with openvino and write the CMakeLists.txt for compilation and generating the target , as I do :
find_package(InferenceEngine 2.1 QUIET)
And from InferenceEngineConfig.cmake , I know follwing variable would be defined :
# This will define the following variables:
# InferenceEngine_FOUND - True if the system has the
# Inference Engine library
# InferenceEngine_INCLUDE_DIRS - Inference Engine include
directories
# InferenceEngine_LIBRARIES - Inference Engine libraries
After doing find_package() , I do :
include_directories(${OpenCV_INCLUDE_DIRS} ${InferenceEngine_INCLUDE_DIRS} )
And do all the things it needs to getenrate the shared library which is exactly what I need.
However , When I delete this line :
#include_directories(${OpenCV_INCLUDE_DIRS} ${InferenceEngine_INCLUDE_DIRS} )
Everthing still works fine which really confuses me...May Somebody tell me the logic behind all of this ? Thanks in advance!
Related
In my project I need to include different files for different build configurations and thus far I've been unable to find a way to do it via CMake.
My build command looks the following way:
cmake -DCMAKE_CONFIGURATION_TYPES=Debug2017;Debug2018;Debug2019;Release2017;Release2018;Release2019 -G"Visual Studio 14 2015" #and so on
In my CMakeLists.txt I want to have something that looks like:
if ($<$<CONFIG:Debug2017>: )
set (MAYA_DIRECTORY "C:/Program Files/Autodesk/Maya2017" )>
endif()
if ($<$<CONFIG:Debug2018>: )
set (MAYA_DIRECTORY "C:/Program Files/Autodesk/Maya2018" )>
endif()
#and so on; obviously script above don't work. I posted it just as an example of what I want to achieve
variable MAYA_DIRECTORY is used later on to set different other variables that are used for include_directories(…) and link_directories(…) calls.
If there is a way to do this by something other than generator expressions that would also work.
Thanks!
You don't. It is possible for single config generators to use CMAKE_BUILD_TYPE but that strategy fails for for multi-config generators like Visual Studio. This is mixing up what happens at configuration time and build time. The active configuration happens at build time.
Therefore you need a separate MAYA_DIRECTORY for each build config. Then you need to include each Maya into the build (I'm guessing they are external projects or something). Then you need to use a generator expressions to pick which Maya you want to use in the executable.
It would be something like this.
target_include_directories(myApp PRIVATE
$<$<CONFIG:Debug2016>:${MAYA_2016_INCS}>
$<$<CONFIG:Debug2017>:${MAYA_2017_INCS}> )
target_link_libraries(myApp PRIVATE
$<$<CONFIG:Debug2016>:${MAYA_2016_LIBS}>
$<$<CONFIG:Debug2017>:${MAYA_2017_LIBS} )
FYI, If you are creating multiple configuration types you need to seed them properly. That is make sure you create a *_Debug2017 with the debug flags and so on.
I have a simple CMakeLists for my shader code which currently just looks like this -
target_sources( JonsEngine
PRIVATE
AmbientPixel.hlsl
AvgLuminance.hlsl
BoxBlurPixel.hlsl
Common.hlsl
Constants.h
DepthReadback.hlsl
DirectionalLightPixel.hlsl
DirectionalLightPCF2X2Pixel.hlsl
DirectionalLightPCF3X3Pixel.hlsl
DirectionalLightPCF5X5Pixel.hlsl
DirectionalLightPCF7X7Pixel.hlsl
FullscreenTriangle.hlsl
FullscreenTriangleTexcoord.hlsl
FXAA.hlsl
FXAAPixel.hlsl
GBufferPixel.hlsl
GBufferVertex.hlsl
GBufferVertexAnimated.hlsl
GBufferVertexStatic.hlsl
OptimizedPCF.hlsl
PointLightPixel.hlsl
SDSMFinalCompute.hlsl
SDSMInitialCompute.hlsl
SimpleColorPixel.hlsl
SimpleTexturePixel.hlsl
SkyboxPixel.hlsl
SkyboxVertex.hlsl
SSAOPixel.hlsl
TerrainDomain.hlsl
TerrainHull.hlsl
TerrainPixel.hlsl
TerrainPixelDebug.hlsl
Tonemapping.hlsl
TransformAnimatedVertex.hlsl
TransformStaticInstancedVertex.hlsl
TransformStaticVertex.hlsl
)
I am trying to add a bunch of compile flags to some of them using like -
set_source_files_properties( AmbientPixel.hlsl PROPERTIES COMPILE_FLAGS "/E\"ps_main\" /ps\"_5_0\"" )
However when I generate the solution via CMake it seems to ignore this when I look at the compile options for that source file. What am I doing wrong?
EDIT: CMake 3.14+
CMake treats HLSL files as source extra, as it is not a first class language in CMake. Others have had your issue as well, which prompted CMake to add the VS_SHADER_FLAGS option.
Try something like this instead:
add_executable(JonsEngine)
# Set HLSL source file properties with VS_SHADER_FLAGS.
set_source_files_properties( AmbientPixel.hlsl PROPERTIES VS_SHADER_FLAGS "/E\"ps_main\" /ps\"_5_0\"")
# Associate these source extras with the executable defined above.
target_sources(JonsEngine PRIVATE
AmbientPixel.hlsl
AvgLuminance.hlsl
#
# ... other code files here ...
#
)
There are several other shader options CMake created for the Visual Studio generator, such as VS_SHADER_TYPE and VS_SHADER_ENTRYPOINT which provide additional build information to the shader compiler.
I have an AndroidStudio project with 'C' files in. I can compile and run as-is.
My native files are in
src/main/jni/aes
src/main/jni/libjpeg
src/main/jni/smuglib
I am trying to move the source to a location external to the Android studio project so that I can use it from several locations/projects to avoid copy/paste/mistake cycle.
I have defined the include path in CMakeLists.txt
include_directories(src/main/jni/aes src/main/jni/libjpeg src/main/jni/smuglib)
And have specified the files in the add_library command
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/jni/aes/aes.c
src/main/jni/smuglib/smuglib.c
.... etc
How do I set up a variable to refer to these paths, eg 'src/main/jni/aes' so that I can use it in both the include and in the source list?
I tried variations on
set(aes_src, src/main/jni/aes)
but uses of it as ${aes_src} either in the include path statement or in the source list give me all sorts of arcane errors which I am at a loss to understand.
I will generate some of these and include them if folk think it would help, but I am likely barking up the wrong kettle of fish with this approach.
Is there a better approach?
It is set(VAR_NAME item1 item2 item3). No commas needed.
I need to use a property from an external project. So far I'm successfully doing that this way:
ExternalProject_Add(
some_ep_name
...
)
# Get source dir
ExternalProject_Get_Property(some_ep_name SOURCE_DIR)
# Set source dir value into less generically named variable
set(SOME_EP_NAME_SOURCE_DIR "${SOURCE_DIR}")
This works, but it seems unnecessarily verbose, and it annoys me a little. I was hoping I could use a generator expression, like so:
"$<TARGET_PROPERTY:some_ep_name,SOURCE_DIR>"
But it seems like this doesn't work. Before I give up, I wanted to check if I was doing something wrong or if anyone knows a better way.
All "properties" of ExternalProject are known at configuration time. So they don't require support of generator expressions, which main intention is usage for values not known at configuration time (but known at build time).
If you found "unnecessarily verbose" having several lines of code for save external project' property into the variable, you may create a macro/function for incorporate all these lines. Then calling the macro/function will use only single line of code:
function(ExternalProject_Property_to_Var VAR eproject prop)
ExternalProject_Get_Property(${eproject} ${eprop})
set(${VAR} ${${eprop}} PARENT_SCOPE)
endfunction()
...
ExternalProject_Property_to_Var(SOME_EP_NAME_SOURCE_DIR some_ep_name SOURCE_DIR)
I'm trying to serve a model exported from syntaxnet but the parser_ops are not available. The library file with the ops is found (out-of-tree) at:
../models/syntaxnet/bazel-out/local-opt/bin/syntaxnet/parser_ops.so
I'm currently hacking the mnist_inference example, (because I don't know how to build anything out-of-tree with bazel), and the command I'm running is:
./bazel-out/local-opt/bin/tensorflow_serving/example/mnist_inference --port=9000 /tmp/model/00000001
And the error I'm getting is:
F tensorflow_serving/example/mnist_inference.cc:208] Check failed: ::tensorflow::Status::OK() == (bundle_factory->CreateSessionBundle(bundle_path, &bundle)) (OK vs. Not found: Op type not registered 'FeatureSize')
And FeatureSize is definitely defined in the parser_ops.so, I just don't know how to load it.
I'm not too familiar with TF (I work on Bazel) but it looks like you need to add parser_ops as a dependency of mnist_inference.
There is a right way to do this and a wrong (easier) way.
The Right Way
Basically you add syntaxnet as a dependency of the example you're building. Unfortunately, the syntax net project and the tensorflow serving project import tensorflow itself under different names, so you have to do some mangling of the serving WORKSPACE file to get this working.
Add the following to the tensorflow_serving WORKSPACE file:
local_repository(
name = "syntaxnet",
path = "/path/to/your/checkout/of/models/syntaxnet",
)
This allows you to refer to the targets in syntaxnet from the tensorflow project (by prefixing them with "#syntaxnet"). Unfortunately, as mentioned above, you also have to get all of syntaxnet's external dependencies into the WORKSPACE file, which is annoying. You can test out if it's working with bazel build #syntaxnet//syntaxnet:parser_ops_cc.
Once you've done that, then add the cc_library #syntaxnet//syntaxnet:parser_ops_cc (parser_ops.so is a cc_binary, which can't be used as a dependency) to mnist_inference's deps:
deps = [
"#syntaxnet//syntaxnet:parser_ops_cc",
"#grpc//:grpc++",
...
Note that this still won't quite work: parser_ops_cc is a private target in syntaxnet (so it can't be depended on from outside its package) but you could add an attribute to it like visibility = ["//visibility:public"] if you're just trying things out:
cc_library(
name = "parser_ops_cc",
srcs = ["ops/parser_ops.cc"],
visibility = ["//visibility:public"]
...
The Wrong Way
You have a .so, which you can add a src file for your binary. Add the directory it's in as a new_local_repository() and add it to srcs in the BUILD file.
WORKSPACE file:
new_local_repository(
name = "hacky_syntaxnet",
path = "/path/to/syntaxnet/bazel-out/local-opt/bin/syntaxnet",
build_file_content = """
exports_files(glob(["*"])) # Make all of the files available.
""",
)
BUILD file:
srcs = [
"mnist_inference.cc",
"#hacky_syntaxnet//:parser_ops.so"
],