Put your own project and the VLCQt
project into external projects with ExternalProject_Add
and create a top-level CMakeLists.txt
file to build them one after another.
Your directory structure will look something like this:
ProjectRoot/
|-- CMakeLists.txt
|-- MyProject/
| |-- sources/
| `-- CMakeLists.txt
`-- modules/
|-- MyProject.cmake
`-- ExternalVLCQt.cmake
The ProjectRoot/modules/ExternalVLCQt.cmake
may look like:
set(VLCQT_ROOT ${EXT_INSTALL_PATH}/vlcqt CACHE INTERNAL "")
ExternalProject_Add(vlcqt
URL "http://url.of.source/release.0.1.tar.gz"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${VLCQT_ROOT}
INSTALL_COMMAND make install
)
list(APPEND GLOBAL_THIRDPARTY_LIB_ARGS "-DVLCQT_ROOT:PATH=${VLCQT_ROOT}")
The ProjectRoot/modules/MyProject.cmake
may look like:
ExternalProject_Add(my_project
DEPENDS vlcqt
SOURCE_DIR ${CMAKE_SOURCE_DIR}/MyProject
CMAKE_ARGS
${GLOBAL_THIRDPARTY_LIB_ARGS}
-DCMAKE_INSTALL_PREFIX=${EXT_INSTALL_PATH}/my_project
BUILD_COMMAND make
)
Then finally the ProjectRoot/CMakeLists.txt
should contain the following:
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(MyProject VERSION 0.1)
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/modules"
${CMAKE_MODULE_PATH}
)
include(ExternalProject)
set_directory_properties(PROPERTIES EP_BASE ${CMAKE_BINARY_DIR}/ExtProjects)
get_directory_property(EXT_BASE_PATH EP_BASE)
set(EXT_INSTALL_PATH ${EXT_BASE_PATH}/Install)
include(ExternalVLCQt)
include(MyProject)
install(DIRECTORY ${EXT_INSTALL_PATH}/my_project DESTINATION .)
You can read more about this pattern here. By this pattern the ProjectRoot/MyProject/CMakeLists.txt
will be configured at the build time of the top-level CMakeLists.txt
after the vlcqt
is built. Therefore the find_package
will find the VLCQt
package.
Note: In my example the VLCQT_ROOT
will be received by the CMakeLists.txt
of MyProject
where the find_package
command is used. This variable is a hint for the find_package
command and for different packages this may vary. Every CMake modules used by the find_package
has its own varaible requirements.