How do I build OpenCV with TesseractOCR? - c++

I'm trying to build OpenCV with the Tesseract OCR module to use on a raspberry pi.
There is very little information online on how to build this, and what is available is very incomplete.
I'm building using Visual Studio 2017 on windows 10 using the VisualGDB plugin for cross compilation.
I can load the OpenCV CMake project and build it without issues.
I downloaded the OpenCV-contrib modules, and pointed the OPENCV_EXTRA_MODULES_PATH to C:/opencv/opencv_contrib-master/modules
I can see there is a text module that contains some sources for tesseract-ocr.
There are also entries for Tesseract_INCLUDE_DIR and Tesseract_LIBRARY
Does this mean I need to download Tesseract separately? Or can I just use the files that came with OpenCV contrib?
I cloned https://github.com/tesseract-ocr/tesseract
But there is no include folder anywhere. There is an src folder that contains headers and source files, but no include folder anywhere.
Do I need to build tesseract first? And when its built, it creates lib and include files?
I tried to build tesseract, but it required leptonica.
I was able to build leptonica. but I cannot manage to include it in Tesseract cmake.
I added the lines
add_subdirectory(${CMAKE_SOURCE_DIR}/../leptonica)
add_subdirectory(${CMAKE_SOURCE_DIR}/../leptonica/build)
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
But I'm getting errors:
add_subdirectory not given a binary directory but the given source C:\opencv\tesseract\CMakeLists.txt
Could not find a package configuration file provided by "Leptonica" C:\opencv\tesseract\CMakeLists.txt 124
Thanks,

I got tesseract to build, here is what I added:
To tesseract/CMakeLists.txt on line 105 comment out and add
#if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
# if (NOT Leptonica_DIR AND NOT MSVC)
# find_package(PkgConfig REQUIRED)
# pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
# link_directories(${Leptonica_LIBRARY_DIRS})
# else()
# find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
# endif()
#else()
# if (STATIC)
# set(CPPAN_BUILD_SHARED_LIBS 0)
# else()
# set(CPPAN_BUILD_SHARED_LIBS 1)
# endif()
# add_subdirectory(.cppan)
#endif()
set(Leptonica_DIR "C:/opencv/leptonica/build")
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
find_package(OpenCL QUIET)
Then some build options need to be changed. Same file, line 260.
Set all the PROPERTIES COMPILE_FLAGS "-marm" otherwise it wont compile
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/arch/dotproductsse.cpp
PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/arch/intsimdmatrixsse.cpp
PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/arch/dotproductavx.cpp
PROPERTIES COMPILE_FLAGS "-mavx")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/arch/intsimdmatrixavx2.cpp
PROPERTIES COMPILE_FLAGS "-mavx2")
Then, copy the endianness.h and config_auto.h from C:\opencv\leptonica\build\src to C:\opencv\leptonica\src , again otherwise it wont build
Then it will complain about undefined PACKAGE_VERSION in tessdatamanager.cpp, so define it in the CMakeLists or just directly in the source file.
After that it should build, if your directories match.
My directory structure is as follows:
Tesseract git repository located in C:\opencv\tesseract
Tesseract build directory C:\opencv\tesseract\build
Leptonica repository located in C:\opencv\leptonica
Leptonica build directory in C:\opencv\leptonica\build (contains LeptonicaConfig.cmake,
Leptonica library files, (libleptonica.so, libleptonica.so.1.77.0, libleptonica.so.5.3.0) are in C:\opencv\leptonica\build\src

Related

Do I need a Shared library in a CMAKE project with several subdirectories? How do I do it?

I need to implement a StatisticsLogger library on to a C++/C solution built with cmake and compiled with VS#2010. The project uses the ADTF API, since is built for the ADTF framework.
The solution is composed by different modules/projects, which include their own CMakeLists.txt.
My doubt/problem is regarding the library and Cmake, I need it to be accesible to every single module, but it can't be copied, them all should access the same StatisticsLogger library, that I have implemented with a Singleton.
When I run the framework, the concurrent execution accesses StatsLogger constructor once on each module, like if I had created one StatsLogger on each module, making it unable to trace together all the data I want to log and difficulting file handling.
This is how I added the library in CMakeLists.txt:
add_library(loggerModule
${DSTD_DIR}/dstdfloat.h
${DSTD_DIR}/dstdint.h
${DSTD_DIR}/dstdbool.h
${SUPT_DIR}/logg/statslogger.h
${SUPT_DIR}/logg/statslogger_c_connector.h
${SUPT_DIR}/logg/statslogger_c_connector.cpp
${SUPT_DIR}/logg/statslogger.cpp
)
#set_target_properties(loggerModule PROPERTIES VERSION ${PROJECT_VERSION})
#set_target_properties(loggerModule PROPERTIES PUBLIC_HEADER include/mylib.h)
link_libraries(loggerModule)
It would seem that adding SHARED property to the command add_library would do the job, but Im not capable of getting it working. It returns several link problems.
So, regarding my doubt, Is this the way to get the desired funcionality, to make the library SHARED? What am I doing wrong?
Main CMakeLists.txt:
# CMAKE for test filter build
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
# Set default install prefix
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
# Set project name
project(${PROJECT_NAME})
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Environment checks
find_package(ADTF 2.14.2 REQUIRED)
IF (NOT DEFINED ADTF_FOUND)
MESSAGE( FATAL_ERROR "ADTF was NOT found!!!")
ENDIF()
find_package(ADTF_DISPLAY_TOOLBOX REQUIRED)
IF (NOT DEFINED ADTF_DISPLAY_TOOLBOX_FOUND)
MESSAGE( FATAL_ERROR "ADTF_DISPLAY_TOOLBOX was NOT found!!!")
ENDIF()
set(COMPLETE_PROJECT_BINARY_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/${PROJECT_BINARY_OUTPUT_DIRECTORY})
# Set path to sw module dependencies
set(COMMON_DIR ${CMAKE_SOURCE_DIR}/common)
set(DSTD_DIR ${CMAKE_SOURCE_DIR}/common/dstd)
set(INTF_DIR ${CMAKE_SOURCE_DIR}/common/intf)
set(SUPT_DIR ${CMAKE_SOURCE_DIR}/common/supt)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
#option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
include_directories(${DSTD_DIR})
include_directories(${SUPT_DIR}/logg)
add_library(loggerModule SHARED
${DSTD_DIR}/dstdfloat.h
${DSTD_DIR}/dstdint.h
${DSTD_DIR}/dstdbool.h
${SUPT_DIR}/logg/statslogger.h
${SUPT_DIR}/logg/statslogger_c_connector.h
${SUPT_DIR}/logg/statslogger_c_connector.cpp
${SUPT_DIR}/logg/statslogger.cpp
)
#set_target_properties(loggerModule PROPERTIES VERSION ${PROJECT_VERSION})
#set_target_properties(loggerModule PROPERTIES PUBLIC_HEADER include/mylib.h)
link_libraries(loggerModule)
# Set commands for BB nodes generation
# ...and dependencies for generation
# Go into sub-directory with filter sources
add_subdirectory(${CMAKE_SOURCE_DIR}/tool/adtf/af_acca)
#[33 other add_subdirectories commands]
Example subdirectory CMakeLists.txt:
# External required components have to be provided with path variables
# Internal required components have to be connected to the source file list
if(NOT DEFINED DSTD_DIR)
message( FATAL_ERROR "AF_CDAS requires DSTD_DIR" )
endif()
if(NOT DEFINED INTF_DIR)
message( FATAL_ERROR "AF_CDAS requires INTF_DIR" )
endif()
if(NOT DEFINED SUPT_DIR)
message( FATAL_ERROR "AF_CDAS requires SUPT_DIR" )
endif()
set(CDAS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../)
include_directories(${COMMON_DIR})
[some more includes]
#
# CDAS FILES
#
set(CDAS_FILES
${CDAS_DIR}/src/cdas/cdas.c
${CDAS_DIR}/src/cdas/cdas.h)
source_group("cdas\\files" FILES ${CDAS_FILES})
#
# CDAS ADTF WRAPPER
#
set(CDAS_ADTF_WRAPPER
${CDAS_DIR}/tool/adtf/af_cdas/af_cdas_conf.h
${CDAS_DIR}/tool/adtf/af_cdas/af_cdas.h
${CDAS_DIR}/tool/adtf/af_cdas/af_cdas.cpp)
source_group("cdas\\adtf" FILES ${CDAS_ADTF_WRAPPER})
adtf_add_filter(CDAS
# List source and header files of your filter and its required components
# ${MAIN_FILES}
${CDAS_FILES}
${CDAS_ADTF_WRAPPER}
)
# stdafx.h workaround
if (MSVC)
set_target_properties(CDAS PROPERTIES COMPILE_FLAGS "/Y-")
endif(MSVC)
# MANDATORY PATH SETTING !!!
install (TARGETS CDAS DESTINATION ${COMPLETE_PROJECT_BINARY_OUTPUT_DIR}/debug CONFIGURATIONS Debug)
install (TARGETS CDAS DESTINATION ${COMPLETE_PROJECT_BINARY_OUTPUT_DIR}/release CONFIGURATIONS Release)
adtf_set_folder(CDAS filter)
When using this files, I get the following error:
LINK : fatal error LNK1181: cannot open input file '......\Release\loggerModule.lib' [C:\Users\inno\Desktop\rad
ar_processing\test\adtf\build\win64_vc100\tool\adtf\af_aoca\AOCA.vcxproj]
There isn't any loggerModule.lib in the Release folder, but a loggerModule.dll. In the Debug folder there is a .lib, but copying it to Release won't solve the problem.
I never got too familiar with Cmake, and I am trying to learn it, so I don't know what is going on here, if I am doing something wrong, or my approach wasn't good from the beggining.

Cant compile OpenCV Source file with my project

This question is a continuation of one I asked before
I have a project that uses the librealsense library and OpenCV. librealsense works but I cannot include OpenCV in my project for the life of me. There is currently only 1 CPP file and 1 HPP file, this is the cmake file of the root
project(peoplecounting)
add_subdirectory(libs/librealsense-master)
add_subdirectory(libs/opencv-4.3.0)
set(OpenCV_DIR ${CMAKE_BINARY_DIR}/libs/opencv-4.3.0)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable (CMakeRealSense "CMakeRealSense.cpp" "CMakeRealSense.h")
find_library(realsense2 HINTS libs/librealsense-master)
find_library(opencv HINTS ${CMAKE_BINARY_DIR}/libs/opencv-4.3.0)
target_link_libraries(CMakeRealSense ${OpenCV_LIBS} realsense2)
I have both source files in a libs folder(so directory would look like root/libs/opencv-4.3.0). I am new to cmake so I just might be missing something but its driving me nuts
Some extra notes
1, OpenCV does build the libs when I can build the project, if I remove any include from my self written code it wont make errors which lets me build the project. This does make the opencv librairys which makes me think the linking is the issue
2, If I dont add a project as a executable it does see a opencv include
3, I am doing this to make the project portable, it has to work on a rpi down the line so being able to build it all from source could make it much more portable
EDIT 1
So I did some diging in my files, the exe gets outputted into
root\out\build\x64-Debug\bin but this folder does not only contain the librealsense dll but also the opencv ones. This would make it seem that the exe knows about the library but doesnt want to use it some how? This is very strange to me too
EDIT 2
I managed to find_package(OpenCV) by setting
CMAKE_PREFIX_PATH to win-install which contained a config file, problem now is that iam missing the include dir in said folder
EDIT 3
New error seems to be
Target "opencv_highgui" INTERFACE_INCLUDE_DIRECTORIES property contains
path:
"root/opencv-4.3.0/modules/dnn/include"
which is prefixed in the source directory.
I read somewhere that OpenCV prevents source files being used or something to prevent corruption but now now again at a end when it comes to what iam suppose to be doing
Updated CMake file
project(peoplecounting)
add_subdirectory(librealsense-master)
add_subdirectory(opencv-4.3.0)
set(OpenCV_DIR ${CMAKE_BINARY_DIR})
set(INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/")
set(BUILD_SHARED_LIBS OFF)
find_package(OpenCV CONFIG REQUIRED)
add_library(opencv INTERFACE)
include_directories(${OpenCV_INCLUDE_DIRS})
#add_executable (CMakeRealSense "CMakeRealSense.cpp" "CMakeRealSense.h")
add_executable(RealSenseTest "TestRealSense.cpp")
find_library(realsense2 HINTS librealsense-master)
message(" cv_libs: " ${OpenCV_INSTALL_PATH})
message(" cv_includes: " ${OPENCV_INCLUDE_DIRS})
target_include_directories(opencv INTERFACE "${OpenCV_INCLUDE_DIRS}")
target_link_libraries(RealSenseTest "${OpenCV_LIBS}" realsense2)```

Specify Crypto++ library in a CMakeLists file

I am trying to specify the Crypto++ library in my CMakeLists file but I always get an error.
Here is my CMakeLists file:
cmake_minimum_required(VERSION 2.8)
project( Recognition )
find_package( OpenCV REQUIRED )
find_package ( CURL REQUIRED )
find_package ( CRYPTOPP REQUIRED )
add_executable( Recognition Recognition.cpp )
target_link_libraries( Recognition ${OpenCV_LIBS} ${CURL_LIBRARY} ${CRYPTOPP_LIBRARY})
And here is the errors I get:
By not providing "FindCRYPTOPP.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CRYPTOPP",
but CMake did not find one.
Could not find a package configuration file provided by "CRYPTOPP" with any
of the following names:
CRYPTOPPConfig.cmake
cryptopp-config.cmake
Add the installation prefix of "CRYPTOPP" to CMAKE_PREFIX_PATH or set
"CRYPTOPP_DIR" to a directory containing one of the above files. If
"CRYPTOPP" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
Thank you for your help!
CMake doesn't have a module for the Crypto++ library in the package so you have to provide your own. You can try the following(I've used it once) or google for the "Find CryptoPP cmake".
When you are done with the file, place it somewhere and point CMake to search for the file in that location. Suppose you have placed it under your sources directory in contrib/cmake subfolder, then CMake code will be:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/contrib/cmake")
So you set the path for the modules search now you need to use find_package, note, however, that you should provide the package name in the same fashion your .cmake file is named. For example, if you have CryptoPP.cmake, then you should put the following:
find_package ( CryptoPP REQUIRED )

How to work around CMake + XCode 4 paths dependencies?

I have projects structured like so:
Libs/
Apps1/
Apps2/
In each folder is a CMakeLists.txt. I would like to generate a project file for each of the folders, and each AppsN references Libs. My method of doing that is by calling CMake's add_subdirectory(../Libs/Source/LibN) etc.
Now when I do this, CMake says add_subdirectory must specify a unique absolute path for the binary output folder.
See this post:
Xcode dependencies across different build directories?
XCode can not handle dependencies when the build output folder is unique per target. It needs one folder. And CMake does this by default, it just refuses to when the folder is not a subdir.
I tried altering and changing the output path after the target is created. This will build the objects to the output folder, XCode sees them, but all references to this target in the CMake script will use the unique path.
Proposed solutions are:
include project files in App1/Projects/Subdir and duplicate projects in an irrelevant location
reorganize my folders to a shared parent folder to avoid this CMake craziness, which presents some security problems for me (as some dirs are not public)
never refer to the target by its CMake name, instead using the shared path name. Not sure how to do this properly
try and get this patched on the CMake side somehow
switch to premake
Try to add the following to the root CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
PROJECT (ContainerProject)
SET (LIBRARY_OUTPUT_PATH ${ContainerProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${ContainerProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all executables.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
# for common headers (all project could include them, off topic)
INCLUDE_DIRECTORIES(ContainerProject_SOURCE_DIR/include)
# for add_subdirectory:
# 1) do not use relative paths (just as an addition to absolute path),
# 2) include your stuffs in build order, so your path structure should
# depend on build order,
# 3) you could use all variables what are already loaded in previous
# add_subdirectory commands.
#
# - inside here you should make CMakeLists.txt for all libs and for the
# container folders, too.
add_subdirectory(Libs)
# you could use Libs inside Apps, because they have been in this point of
# the script
add_subdirectory(Apps1)
add_subdirectory(Apps2)
In Libs CMakeLists.txt:
add_subdirectory(Source)
In Source CMakeLists.txt:
add_subdirectory(Lib1)
# Lib2 could depend on Lib1
add_subdirectory(Lib2)
In this way all Apps could use all libraries. All binary will be made to your binary ${root}/bin.
An example lib:
PROJECT(ExampleLib)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
SET(ExampleLibSrcs
...
)
ADD_LIBRARY(ExampleLib SHARED ${ExampleLibSrcs})
An example executable (with dependency):
PROJECT(ExampleBin)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${ExampleLib_SOURCE_DIR}
)
SET(ExampleBinSrcs
...
)
# OSX gui style executable (Finder could use it)
ADD_EXECUTABLE(ExampleBin MACOSX_BUNDLE ${ExampleBinSrcs})
TARGET_LINK_LIBRARIES(ExampleBin
ExampleLib
)
Here is a stupid and working example.

splitting a project into a library and a application

I'm using cmake for my project. No I want to split some parts into a library and use this for 2 different applications.
Now I don't how how to do this subprojects in cmake. My first attempt was to use the add_subdirectory command:
cmake_minimum_required(VERSION 2.8)
add_subdirectory(MSI)
message("Building MsiQtWizard with: ${MSI_INCLUDE_DIR}")
add_subdirectory(MsiQtWizard)
So MSI would be my library. Inside the MSI folder is another cmakelists which is basically a standalone list for building the library. I thought I could make the MsiQtWizard project also a standalone cmakelists, so I could theoretically build MSI and use the library to build MsiQtWizard (and other projects).
The cmakelists in the root directory would just be a helper to build the library and the GUI in one single step.
The problem is, for building MsiQtWizard, I need the include path to msi and the static library binaries. I tried to do something like that at the end of MIS/CMakelists.txt:
### Set variables, other scripts may use ###
SET(MSI_INCLUDE_DIR include)
MESSAGE("Include directory is: ${MSI_INCLUDE_DIR}")
and in the MsiQtWizard/CMakelists:
##### external libraries #####
#MSI
find_path(MSI_INCLUDE_DIR REQUIRED msi/Image.hpp
PATH_SUFFIXES MSI/include include)
My intend is, that MsiQtWizard will search for msi, if the varaible was not previously set (so that you could use this cmakelists as a standalone). When building MSI, I want to save the include path (and later binary locations) and pass it to MsiQtWizard - but the value is gone as soon as I'm back in my root cmakelists.
So that is, what I tried. My Question is now: How would I correctly split my project into a library and a (later multiple) application and can I do it in a way that I can also build them independently?
Or, more specific: How can I pass values from a node CMakelist to the root CMakeList (like I tried with MSI_INCLUDE_DIR)?
If your building a library - its best to completely separate it from the application build. Otherwise you are coupling your library with your application with cmake, which in my view defeats the purpose of building a library.
When building your library you will want something like
project (MSILibrary)
ADD_LIBRARY(MSILibrary src/MSI1.cpp src/MSI2.cpp)
install (TARGETS MSILibrary DESTINATION lib)
where src contains your library code. You can then make then sudo make install your library to your standard library location (e.g. /usr/lib).
You can then use your library in any subsequent project. Put these in a new directory and create a new CMakeLists.txt for them.
You will want something like,
#include find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
project (MSI-project-1)
find_package(MSILibrary REQUIRED)
IF(MSILibrary_FOUND)
include_directories(${MSILibrary_INCLUDE_DIRS}
ENDIF(MSILibrary_FOUND )
target_link_libraries (MSI-project-1 ${MSILibrary_LIBRARIES})
install (TARGETS MSI-project-1 DESTINATION bin)
Now all you need to do is help cmake find you library.
You can include a module for this. In the file ./cmake/Modules/FindMSILibrary.cmake type something like:
# - Try to find MSILibrary library
# Once done, this will define
#
# MSILibrary_FOUND - system has MSILibrary
# MSILibrary_INCLUDE_DIRS - the MSILibrary include directories
# MSILibrary_LIBRARIES - link these to use MSILibrary
## Google this script (I think its fairly standard, but was not bundled with my CMAKE) - it helps find the macros.
include(LibFindMacros)
# Dependencies
libfind_package(MSILibrary)
# Use pkg-config to get hints about paths
libfind_pkg_check_modules(MSILibrary_PKGCONF MSILibrary)
# Include dir
find_path(MSILibrary_INCLUDE_DIR
NAMES MSI.hpp
PATHS ${MSI_Library_PKGCONF_INCLUDE_DIRS}
)
# Finally the library itself
find_library(MSILibrary_LIBRARY
NAMES MSILibrary
PATHS ${MSILibrary_PKGCONF_LIBRARY_DIRS}
)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(MSILibrary_PROCESS_INCLUDES MSILibrary_INCLUDE_DIR MSILibrary_INCLUDE_DIRS)
set(MSILibrary_PROCESS_LIBS MSILibrary_LIBRARY MSILibrary_LIBRARIES)
libfind_process(MSILibrary)
That should be it.
EDIT:
If you really want to package your applications with your library (perhaps some example applications), then you can do something like so:
In your root CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (MSIProject)
# The version number.
set (MSIProject_VERSION_MAJOR 0)
set (MSIProject_VERSION_MINOR 1)
set (MSIProject_PATCH_LEVEL 3 )
# project options
OPTION( BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON )
OPTION( BUILD_EXAMPLES "Set to OFF to skip building the examples" ON )
# Put the libaries and binaries that get built into directories at the
# top of the build tree rather than in hard-to-find leaf
# directories.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
##########################################################################
# Build the library
##########################################################################
add_subdirectory(MSI-src)
##################
# Build your example Apps if requested
############
IF( BUILD_EXAMPLES )
add_subdirectory(example/MSI-project-1)
add_subdirectory(example/MSI-project-2)
ENDIF( BUILD_EXAMPLES )
Your library MSI-src/CMakeFiles.txt will be as before, and your example/MSI-project-1/CMakeLists.txt will be something like
## Make the InferData example project
project (MSI-project-1)
#include MSI library
include_directories ("${MSILibrary_SOURCE_DIR}/include")
#include the includes of this project
include_directories ("${MSI-project-1_SOURCE_DIR}/../include")
#build
add_executable(MSI-project-1 src/P1.cpp)
target_link_libraries (MSI-project-1 MSILibrary) #link
install (TARGETS MSI-project-1 DESTINATION bin)