CMake: generate or extract header necessary for shared lib - c++

I'm currently working on a larger project which is not maintained.
Explanation
It tries to use CMake but not very intuitive. Instead of including shared libs and headers from every submodule, one can set a flag in the top level CMakeList which triggers an add_subdirectory, sneaking the top level CMAKE_BUILD_DIR and installs into it. These CMakeLists use exclusively glob RECUSE to find all sources and most operation are not target based but global. Therefor the main target compiles properly. Here is a little snippet of the main CMakeList
set(MY_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(MY_SOURCE_BASE_DIR "${MY_BASE_DIR}/myproject")
# includes
include(build/global.cmake)
#include(externalLibs/mz-cmaketools-master/global.cmake)
# configuration options
option(MOD1 "" ON)
option(MOD2 "" ON)
option(MOD3 "" OFF)
option(MOD4 "" OFF)
option(MOD5 "" ON)
option(MOD6 "" OFF)
option(MOD7 "" ON)
message("-- Building myproject unit-tests - ${ENABLE_MYPROJECT_TEST}")
set(CMAKE_ECLIPSE_MAKE_ARGUMENTS "-j4")
if(MOD1)
message(STATUS "Building viral_core + viral_recon")
add_subdirectory(${MY_BASE_DIR}/externalLibs/viral/trunk/linux)
include_directories(${MY_BASE_DIR}/externalLibs/viral/trunk/source/)
else(MOD1)
if(MOD3)
message(WARNING "Building viral_core + viral_recon")
add_subdirectory(${MY_BASE_DIR}/externalLibs/viral/trunk/linux)
include_directories(${MY_BASE_DIR}/externalLibs/viral/trunk/source/)
endif(MOD3)
endif(MOD1)
# external libraries
include(${MY_BASE_DIR}/externalLibs.cmake)
include_directories(
${MY_BASE_DIR}
${MY_SOURCE_BASE_DIR}
${MY_BASE_DIR}/externalLibs/viral/trunk/source/
)
# depending on the supported robots we have different dependencies
if( MOD1 )
set(OPT1 TRUE)
endif()
...
# collect binaries
set(LIBRARY_OUTPUT_PATH ${MY_BASE_DIR} CACHE PATH "Library output path")
set(EXECUTABLE_OUTPUT_PATH ${MY_BASE_DIR} CACHE PATH "Executable output path")
message("-- Setting executable output path: ${EXECUTABLE_OUTPUT_PATH}")
message("-- Setting library output path : ${LIBRARY_OUTPUT_PATH}")
# collect sources
file(GLOB MY
"${MY_SOURCE_BASE_DIR}/*.h"
"${MY_SOURCE_BASE_DIR}/*.cpp"
)
source_group(base FILES ${MY_BASE})#
file(GLOB MY_UTIL
"${MY_SOURCE_BASE_DIR}/util/*.h"
"${MY_SOURCE_BASE_DIR}/util/*.cpp"
)
source_group(util FILES ${MY_UTIL})
file(GLOB_RECURSE MY_KINEMATICS
"${MY_SOURCE_BASE_DIR}/kinematics/*.h"
"${MY_SOURCE_BASE_DIR}/kinematics/*.cpp"
)
source_group(kinematics FILES ${MY_KINEMATICS})
file(GLOB MY_COLLISION
"${MY_SOURCE_BASE_DIR}/collision/pqp/*.cpp"
"${MY_SOURCE_BASE_DIR}/collision/PQP*.cpp"
)
source_group(collision FILES ${MY_COLLISION})
...
add_library(MY SHARED
${MY_COLLISION}
${MY_UTIL}
${MY_KINEMATICS}
...}
)
....
In the end the project builds several libs, but does not publish required headers to use them. These libs are put into the top level of the build directory. (without an install step)
Question
Is there a possibility to make CMake to export the included header for a lib (target). To be more precisely, these headers should only lie within the source folder and below; headers from /usr/... should not be considered. Furthermore it is acceptable if the headers are merged into one single header. But from the ~1700 headers only ~40 are relevant, so a simple find RECURSE does not seem adequate to me.
I did have a look at GENERATE_EXPORT_HEADER but do not think that is what I look for. And I do not have the permission to change the project, so I want to make a patch to the SVN repository and do NOT want to make another copy of the repository, because there are around 10 different in use.
I would appreciate any hints towards a solution or strategy
This is my very first question on stackoverflow, so please be merciful :)

I hope I understood your question correctly.
I usually use the CMakePackageConfigHelpers to generate cmake configuration files for the lib, if done correctly the nice thing is that CMake sets up transitive dependencies and include directories automatically when you link against a library with a package config.
The install command can then be used to copy targets, directories, include files to the CMAKE_INSTALL_PREFIX dir, or into an archive via CPack.
After declaring my target I will usually have something along the lines of:
install(TARGETS MyLibrary
LIBRARY DESTINATION lib
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${GENERATED_DIR}/MyLibraryConfigVersion.cmake" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"cmake/Config.cmake.in"
"${GENERATED_DIR}/MyLibraryConfig.cmake"
INSTALL_DESTINATION "cmake"
)
install(FILES
inc/someHeader.h
inc/someHeaderB.h
DESTINATION include/MyLibrary
)
install(FILES
"${GENERATED_DIR}/MyLibraryConfig.cmake"
"${GENERATED_DIR}/MyLibraryConfigVersion.cmake"
DESTINATION "cmake"
)
Then you can set CMAKE_INSTALL_PREFIX to a directory of your choice and run make install, creating the following structure:
InstallationDir
├── cmake
│   ├── MyLibraryConfig.cmake
│   └── MyLibraryConfigVersion.cmake
├── include
│   └── MyLibrary
│   ├── someHeaderB.h
│   └── someHeader.h
└── lib
└── MyLibrary.so
Then you can use find_package in CONFIG mode to automatically set up include directories, compile options etc. when linking against MyLibrary.so.
Just a hint: The target_include_directories function is preferred to include_directories. I am not sure how well config file generation works if you do not use it. Also take a look at the following functions for more advanced control on your target: set_target_properties, target_link_libraries, target_compile_definitions

Related

How to write a CMakeLists.txt to use FreeImage precompiled library and header file

The folder structure:
Project/
├── main.cpp
└── deps/
└── FreeImage/
├── FreeImage.lib
├── FreeImage.dll
├── FreeImage.h
├── FreeImagePlus.lib
├── FreeImagePlus.dll
└── FreeImagePlus.h
The code:
#include <FreeImagePlus.h>
int main(void)
{
fipImage i;
return 0;
}
And now the question:
How to write a CMakeLists.txt file to be able to compile the above in windows?
My attempt as an answer below
You should use different steps here. A proper goal is to have everything you need to use FreeImage in a FindFreeImage.cmake file. Then you can set FreeImage.cmake like this:
FIND_PATH(FreeImage_INCLUDE_DIR FreeImage.h HINTS ${FreeImage_ROOT})
FIND_LIBRARY(FreeImage_LIBRARY NAMES FreeImage HINTS ${FreeImage_ROOT})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FreeImage DEFAULT_MSG FreeImage_INCLUDE_DIR FreeImage_LIBRARY)
Of course, you should add more so that when linking against FreeImage, you get the include path set, installation procedure... But that would be for another question.
One solution of a CMakeLists.txt with extra tips
cmake_minimum_required(VERSION 3.8)
set(NAME cmakecopytest)
project(${NAME})
# The place to put built libraries
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/windows-64/debug")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/windows-64/debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/windows-64/debug")
# Copying pre-compiled dll libraries next to the built libraries for them to be found in runtime without extra effort
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus.dll" "${CMAKE_BINARY_DIR}/bin/windows-64/debug/FreeImagePlus.dll" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage.dll" "${CMAKE_BINARY_DIR}/bin/windows-64/debug/FreeImage.dll" COPYONLY)
add_executable(${NAME}_exe main.cpp)
target_include_directories(${NAME}_exe PUBLIC ./ include/ deps/FreeImage)
target_link_libraries(${NAME}_exe PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage.lib" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus.lib")
# target_link_libraries(${NAME}_exe PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus") # ERROR LNK1104: cannot open file '..\deps\FreeImage\FreeImage.obj'
Extra tips:
CMAKE_BINARY_DIR contains the place where you built the solution (i.e., D:/Work/Project/build)
Setting the output directories and then copying the precompiled libraries to that same location is a easy way to have your code run without any added extra configurations in MSVS
math(EXPR platform_bits "${CMAKE_SIZEOF_VOID_P} * 8")
set(platform_dir bin/${CMAKE_SYSTEM_NAME}-${platform_bits})
foreach(config DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
foreach(var
CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config}
CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config}
CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
)
set(${var} "${CMAKE_BINARY_DIR}/${platform_dir}/${config}")
string(TOLOWER "${${var}}" ${var})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus.dll ${var}/FreeImagePlus.dll COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage.dll ${var}/FreeImage.dll COPYONLY)
endforeach()
endforeach()
And this for cycle does that for you for all the desired configurations
However, I do not like having to specify the '.lib' in target_link_libraries(...FreeImage.lib...)
Anyone else has a solution to be able to say target_link_libraries(${NAME}_exe PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImage" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/FreeImage/FreeImagePlus") while avoiding the linking error LNK1104: cannot open file '..\deps\FreeImage\FreeImage.obj' ?

How to build only one target for dependency?

I want to build an application under Windows using CMake + Visual Studio with a lot of dependencies, such as zlib. All of them are static libraries.
I've tried ADD_SUBDIRECTORY and this works pretty well but instead of building only depending target (zlibstatic) it builds all of them.
How to remove unused targets (with their solutions) or choose only one?
Mainly I'm searching for feature to define only needed targets.
Part of my CMakeLists.txt:
ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib")
TARGET_INCLUDE_DIRECTORIES(MyProject PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib")
TARGET_LINK_LIBRARIES(MyProject zlibstatic)
I finally figured out how to do it.
MyProject
├───build <- here I call cmake
├───deps
│ └───zlib
│ └───CMakeLists.txt
├───inc
├───src
└───CMakeLists.txt
# Include project but remove all tartgets
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib EXCLUDE_FROM_ALL)
# Use only specific one target
ADD_DEPENDENCIES(MyProject zlibstatic)
# Include dirs from zlib source directory and from output directory becuse it generates some headers
TARGET_INCLUDE_DIRECTORIES(MyProject PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib
${CMAKE_CURRENT_BINARY_DIR}/deps/zlib
)
# Just to create beautiful structure in project tree
SET_PROPERTY(TARGET zlibstatic PROPERTY FOLDER Deps)
# Link after all
TARGET_LINK_LIBRARIES(MyProject zlibstatic)
I suggest you use vcpkg or conan instead to resolve your dependent library issue this is much cleaner and works well except for header only libraries.
You can of cause do that manually but than you loose the nice cmake setup.

Why am I not able to include header file from cmake exported/imported library

I am trying to write a header only library to be imported by others, using CMake. I tried to follow the instructions by Daniel Pfeifer - "Effective CMake". However I am not able to include the header files into another project. For illustration purpose I created a similar toy project having the tree structure:
├── testinclude
│ ├── CMakeLists.txt
│ └── testinclude.cpp
└── testlib
├── CMakeLists.txt
├── include
│ └── testLib.h
└── testLibConfig.cmake
while the library is supposed to be testLib.h containing
void sayHello(){
std::cout<<"Hello"<<'\n';
}
and the source code for the executable testinclude.cpp looks like:
#include"testLib.h"
int main(){
sayHello();
return 0;
}
Trying to follow Daniel Pfeifers guidelines my CMakeLists.txt in the directory testlib looks like:
cmake_minimum_required(VERSION 3.5)
project(testLib VERSION 0.1)
add_library(testLib INTERFACE )
target_include_directories(testLib INTERFACE
$<INSTALL_INTERFACE:include>
)
install(TARGETS testLib EXPORT testLibTargets
INCLUDES DESTINATION include
)
install(EXPORT testLibTargets
FILE testLibTargets.cmake
NAMESPACE testLib::
DESTINATION lib/cmake/testLib
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("testLibConfigVersion.cmake"
VERSION ${testLib_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES "testLibConfig.cmake" "testLibConfigVersion.cmake"
DESTINATION lib/cmake/testLib
)
and testLibConfig.cmake:
include("${CMAKE_CURRENT_LIST_DIR}/testLibTargets.cmake")
end finally the CMakeLists.txt in the directory testinclude:
cmake_minimum_required(VERSION 3.5)
project(testInclude)
add_executable(testInclude testinclude.cpp)
find_package(testLib)
target_link_libraries(testInclude PRIVATE testLib::testLib)
After running in the directory testlib:
cmake .
sudo make install
and running in the testinclude directory:
cmake .
make
I get the error that testLib.h was not found, even though I had no complains or error before.
The comment by Tsyvarev was absolutely correct. Additionally installing the public header file "testLib.h" (into some location independent of the project) was the missing thing to do.
Adding the line
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/testLib.h" DESTINATION
include/testLib )
to the "testLib/CMakeLists.txt"
fixed the problem.
I think your install doesn't include the header files.
use set_target_properties(tgt PROPERTIEs PUBLIC_HEADER "${HEADER_FILES}")
and PUBLIC_HEADER in install to install them (warning no subdirectory allowed)
also "include DESTINATION" in install should not be use, try to use target_include_directories() instead ("includes" which is a reminiscence of pre Modern CMake). It is just need when you want to add install include directories...
Otherwise seems fine to me...
e.g. https://github.com/Mizux/cmake-cpp/blob/master/Foo/CMakeLists.txt
src: https://cmake.org/cmake/help/latest/prop_tgt/PUBLIC_HEADER.html

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)