I have the following code in one of my CMakeLists.txt:
FIND_PACKAGE(sphinxbase)
if (${SPHINXBASE_FOUND})
INCLUDE_DIRECTORIES(${SPHINXBASE_INCLUDE_DIR}/sphinxbase/)
else ()
ExternalProject_Add(
sphinxbase
GIT_REPOSITORY "https://github.com/cmusphinx/sphinxbase.git"
GIT_TAG "e34b1c632392276101ed16e8a05862e43f038a7c"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/sphinxbase
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/sphinxbase/autogen.sh
BUILD_COMMAND ${MAKE}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
BUILD_IN_SOURCE ON
LOG_DOWNLOAD ON
LOG_UPDATE ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_TEST ON
LOG_INSTALL ON
)
ExternalProject_Get_Property(sphinxbase SOURCE_DIR)
ExternalProject_Get_Property(sphinxbase BINARY_DIR)
SET(SPHINXBASE_SOURCE_DIR ${SOURCE_DIR})
SET(SPHINXBASE_BINARY_DIR ${BINARY_DIR})
SET(SPHINXBASE_LIBRARIES ${SPHINXBASE_BINARY_DIR}/src/libsphinxbase/.libs/libsphinxbase.a)
INCLUDE_DIRECTORIES(${SPHINXBASE_SOURCE_DIR}/include)
endif ()
SET(DEPENDENCIES ${DEPENDENCIES} sphinxbase)
SET(LIBS ${LIBS} ${SPHINXBASE_LIBRARIES})
In addition to the TARGET that I'm trying to install, how would I go about installing this ExternalProject? Right now I'm trying to do it like this:
install(TARGETS ${LIBS}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
OPTIONAL
)
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
)
But I'm getting the following error thrown at me:
CMake Error at CMakeLists.txt:197 (install):
install TARGETS given target
"/Users/syb0rg/Dropbox/Development/Khronos/Khronos/lib/sphinxbase/src/libsphinxbase/.libs/libsphinxbase.a"
which does not exist in this directory.
Any suggestions?
Command flow install(TARGETS) installs targets, which are created with add_executable or add_library commands. For install concrete files, you need to use command flow install(FILES).
Instead of installing selected files from subproject's build directory, you may install subproject as is. For that you can use
make DESTDIR=<...> install
command as INSTALL option of ExeternalProject_Add. This command will install whole subproject into directory given as DESTDIR parameter for make (more information about this parameter can be found here).
Then you may use install(DIRECTORY) command for install all subproject's files at once:
# It is better to use binary directory for download or build 3d-party project
set(sphinxbase_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib/sphinxbase)
# This will be used as DESTDIR on subproject's `make install`.
set(sphinxbase_DESTDIR ${CMAKE_CURRENT_BINARY_DIR}/lib/sphinxbase_install)
ExternalProject_Add(
sphinxbase
GIT_REPOSITORY "https://github.com/cmusphinx/sphinxbase.git"
GIT_TAG "e34b1c632392276101ed16e8a05862e43f038a7c"
SOURCE_DIR ${sphinxbase_SOURCE_DIR}
# Specify installation prefix for configure.sh (autogen.sh).
CONFIGURE_COMMAND ./autogen.sh --prefix=${CMAKE_INSTALL_PREFIX}
BUILD_COMMAND ${MAKE}
UPDATE_COMMAND ""
# Fake installation: copy installed files into DESTDIR.
INSTALL_COMMAND make DESTDIR=${sphinxbase_DESTDIR} install
...
)
# Actually install subproject.
install(
DIRECTORY ${sphinxbase_DESTDIR}/
DESTINATION "/"
USE_SOURCE_PERMISSIONS # Remain permissions (rwx) for installed files
)
Note, that root directory is used as DESTINATION. This is because files under sphinxbase_DESTDIR directory already located in accordance to CMAKE_INSTALL_PREFIX, which is passed as --prefix option to configure.sh (autogen.sh in the given case).
If you know, that subprojects installs its files only under installation prefix (given by --prefix), you can make main project installation more packaging-friendly:
install(
DIRECTORY ${sphinxbase_DESTDIR}/${CMAKE_INSTALL_PREFIX}/
DESTINATION "."
USE_SOURCE_PERMISSIONS
)
Because now relative path is used for DESTINATION option, the project will correctly support packaging. For example, make DESTDIR=<...> install will work for main project too.
Note, that even if ExternalProject_Add is used for build CMake subproject, targets created in this subroject are not seen by the main project.
Related
I am trying to install boost by ExternalProject_Add but I get error.
Question What does the error mean and how can I resolve it?
This is the error message I have:
Performing update step for 'boost-external'
No patch step for 'boost-external'
Performing configure step for 'boost-external'
'cp' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Msbuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(241,5): e
rror MSB8066: Custom build for 'C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde471
9f69085ebded4413f3304\boost-external-mkdir.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\7a303cde4719f69085ebded4413f3304\boost-external-download.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02
_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-update.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super
_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-patch.rule;C:\IBOIS57\_Code\Software
\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-configure.rule;C:\IB
OIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-
build.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304
\boost-external-install.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\1a2a6d9ea64ba5
92f97cd191c1d5acb1\boost-external-complete.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\a70b522e33d20f4a0fb02fd1b3fdb173\boost-external.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\CM
akeLists.txt' exited with code 9009. [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\boost-external.v
cxproj]
This is the screenshot:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/HyrKM.jpg
This is my full CMakeLists.txt
###############################################################################
#cmake + project name
###############################################################################
cmake_minimum_required(VERSION 3.10)
project(boostdemo)
###############################################################################
#create executable
###############################################################################
add_executable(boostdemo ${PROJECT_SOURCE_DIR}/main.cpp)
###############################################################################
#boost
###############################################################################
#https://github.com/BBO-repo/cpp-boost-cmake-superbuild
set( Boost_Bootstrap_Command ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/bootstrap.sh && cp ${CMAKE_BINARY_DIR}/boost-download/src/boost-external-build/b2 ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/)
set( Boost_b2_Command cd ${CMAKE_BINARY_DIR}/boost-download/src/boost-external && ./b2 )
include(ExternalProject)
ExternalProject_Add(
boost-external #library name that will be used for linking in the executable
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.79.0
PREFIX boost-download
CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
BUILD_COMMAND ${Boost_b2_Command} install
--without-python
--without-mpi
--disable-icu
--prefix=${CMAKE_SOURCE_DIR}/thirdparty/boost/
--threading=single,multi
--link=shared
--variant=release
-j12
INSTALL_COMMAND ""
)
set(Boost_LIBS ${CMAKE_SOURCE_DIR}/thirdparty/boost/lib/${CMAKE_STATIC_LIBRARY_PREFIX}boost_chrono${CMAKE_SHARED_LIBRARY_SUFFIX})
set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/boost/include/)
###############################################################################
#link boost
###############################################################################
add_dependencies(boostdemo boost-external)
include_directories(boostdemo ${Boost_INCLUDE_DIR})
target_link_libraries(boostdemo ${Boost_LIBS})
In case it helps someone, below is the cmake fragment I used to have for obtaining boost with ExternalProject_Add. I was focussed at the time on the header only parts so it may not be complete.
I was never entirely happy with this and in the end switched to obtaining all of our third party dependencies with vcpkg. I have been much happier ever since, especially with regard to boost. In fact I just deleted this file from our repo. So I strongly recommend looking at vcpkg (or conan or ...) instead of ExternalProject_Add.
if(WIN32)
set( Boost_Bootstrap_Command bootstrap.bat )
set( Boost_b2_Command b2.exe )
set( Boost_version_dir /boost-1_77 )
else()
set( Boost_Bootstrap_Command ./bootstrap.sh )
set( Boost_b2_Command ./b2 )
set( Boost_version_dir "")
endif()
ExternalProject_Add(git_boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
BUILD_COMMAND ""
INSTALL_COMMAND ${Boost_b2_Command} --with-headers --with-math install --prefix=${CMAKE_CURRENT_BINARY_DIR}/boost
TEST_COMMAND ""
)
add_library(ours_boost INTERFACE)
add_library(ours::boost ALIAS ours_boost)
target_include_directories(ours_boost INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
message(${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
add_dependencies(ours_boost git_boost)
I want to integrate CasADi into a CMake-based C++ codebase as an ExternalProject. For this purpose, I would like to use pre-compiled libraries because building from source is not recommended. So far, I have only managed to write the following:
ExternalProject_Add(
casadi-3.5.5
URL https://github.com/casadi/casadi/releases/download/3.5.5/casadi-linux-py39-v3.5.5-64bit.tar.gz
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
PREFIX ${CMAKE_BINARY_DIR}/external/casadi)
and I noticed that all the binaries are correctly downloaded in the specified folder. However, I do not know how to link my targets to CasADi, nor how to find the package.
There is a natural problem with ExternalProject_Add:
ExternalProject_Add executes commands only on build.
Hence, download will not happen at the configure stage of your project which makes it difficult to use find_package, because the files cannot be found during your first configure run.
Take this CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
add_executable(untitled main.cpp)
include(ExternalProject)
ExternalProject_Add(
casadi-3.5.5
URL https://github.com/casadi/casadi/releases/download/3.5.5/casadi-linux-py39-v3.5.5-64bit.tar.gz
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
PREFIX ${CMAKE_BINARY_DIR}/external/casadi)
find_package(casadi HINTS ${CMAKE_BINARY_DIR}/external/casadi/src/casadi-3.5.5/casadi)
target_link_libraries(untitled casadi)
In order to use it you have to do the following:
Configure your project
mkdir build
cd build
cmake ..
Build (download) casadi-3.5.5
cmake --build . --target casadi-3.5.5
Reconfigure your project, because now find_package will find the needed files
cmake ..
Build your targets
cmake --build .
If you want a one step build, there are ways to get around this problem
Use FetchContent
Create a sub-cmake-project in a subfolder with all the ExternalProject_Add commands and execute the approriate build (download) steps manually in your own CMakeLists.txt via execute_process calls: https://stackoverflow.com/a/37554269/8088550
Here is an example for the second option, which might be better since FetchContent doesn't have the full functionality of ExternalProject.
main.cpp
#include <casadi/casadi.hpp>
int main()
{
casadi_printf("This works!");
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
# some default target
add_executable(untitled main.cpp)
# Configure and build external project
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/external)
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/external
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/external
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/external
)
# find and link externals
find_package(casadi REQUIRED HINTS ${CMAKE_BINARY_DIR}/external/external/casadi/src/casadi-3.5.5/casadi)
target_link_libraries(untitled casadi)
external/CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(external)
include(ExternalProject)
ExternalProject_Add(
casadi-3.5.5
URL https://github.com/casadi/casadi/releases/download/3.5.5/casadi-linux-py39-v3.5.5-64bit.tar.gz
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
PREFIX ${CMAKE_BINARY_DIR}/external/casadi)
The point is to have another cmake project under external/CMakeLists.txt, which gets configured and build via execute_process calls from the main cmake project. Do note, that you can now have find_package(casadi REQUIRED ...) at configure stage, because the download will happen just before.
Coming from other package managers I expect to be able to do the following on a project:
configure the required libraries (in a config file, e.g. CMakelists.txt or nuget's packages.config)
install/upgrade all the required libraries
This seems to not be possible with vcpkg and CMake:
I managed to set up vcpkg and CMakefile (linux):
# in ternimal
vcpkg install <package>
# CMakeLists.txt
find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries(<app> <package>)
This however requires to manually install all the required libraries (vcpkg install <package>).
How can I list the required packages and have vcpkg or CMake managed them as required (e.g. automatically install them if they are missing)?
I've recently spent some time working with CMake and vcpkg. I dislike the typical approach of managing vcpkg and its installed packages separately from my CMake projects, so I wrote some CMake scripts to handle vcpkg during the CMake build process.
The CMake script to install vcpkg is primarily a call to ExternalProject_Add.
# ./vcpkg_utilities.cmake (part 1)
include(ExternalProject)
function(get_vcpkg)
ExternalProject_Add(vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
BUILD_COMMAND "<SOURCE_DIR>/bootstrap-vcpkg.sh"
)
ExternalProject_Get_Property(vcpkg SOURCE_DIR)
set(VCPKG_DIR ${SOURCE_DIR} PARENT_SCOPE)
set(VCPKG_DEPENDENCIES "vcpkg" PARENT_SCOPE)
endfunction()
The script to have vcpkg install a package requires a custom command and target.
# ./vcpkg_utilities.cmake (part 2)
function(vcpkg_install PACKAGE_NAME)
add_custom_command(
OUTPUT ${VCPKG_DIR}/packages/${PACKAGE_NAME}_x64-linux/BUILD_INFO
COMMAND ${VCPKG_DIR}/vcpkg install ${PACKAGE_NAME}:x64-linux
WORKING_DIRECTORY ${VCPKG_DIR}
DEPENDS vcpkg
)
add_custom_target(get${PACKAGE_NAME}
ALL
DEPENDS ${VCPKG_DIR}/packages/${PACKAGE_NAME}_x64-linux/BUILD_INFO
)
list(APPEND VCPKG_DEPENDENCIES "get${PACKAGE_NAME}")
set(VCPKG_DEPENDENCIES ${VCPKG_DEPENDENCIES} PARENT_SCOPE)
endfunction()
Getting the main project linked to vcpkg appropriately (via toolchain file) requires vcpkg to be available when the main project is configured, so the main project is configured as an ExternalProject.
# /CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
project(top LANGUAGES CXX)
include(vcpkg_utilities)
get_vcpkg()
vcpkg_install(nlohmann_json)
include(ExternalProject)
set_property(DIRECTORY PROPERTY EP_BASE main_projectname)
ExternalProject_Add(main_projectname
DEPENDS ${VCPKG_DEPENDENCIES}
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src
INSTALL_COMMAND ""
CMAKE_ARGS --no-warn-unused-cli;
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake
)
Using this structure, CMake will manage the installation of both vcpkg and packages maintained by it.
Note that this is a point solution. I have a more generalized template for this in my Github that covers Windows and Linux, and allows the use of a separately-maintained vcpkg instance.
I've done something similar in my projects using ExternalProject_Add.
Code will be similar to the below pattern (I've replaced my dependency with your)
find_package(nlohmann_json CONFIG) # make package not REQUIRED to avoid error...
if(NOT NLOHMANN_JSON_FOUND) # or whatever variable indicating _FOUND
...
# here ExternalProject_Add from https://github.com/nlohmann/json.git
# using specific tag...
...
ExternalProject_Get_Property(... INSTALL_DIR)
# create imported target here similar to nlohmann_json, as if we found it
...
else()
# We've found lib already installed... will use it...
...
endif()
Another option can be using FetchContent, but I haven't tried it yet.
I'd like to use the following third party library:
https://github.com/Corvusoft/restbed
I'd like to create a folder structure similar to this:
- root
- CMakeLists.txt
- src
- third_party
- restbed
- src
- CMakeLists.txt
- CMakeLists.txt
I've found out that I should use the ExternalProject CMake module to achieve this but it does not seem that I can do it correctly. For some reason the external lib's (restbed's) source does not appear in my XCode project when I generate it out with the use of the root CMakeLists.txt. This root CMakeLists.txt includes in the third_party folder's CMakeLists.txt. The third_party folder's CMakeLists.txt looks like this:
include(ExternalProject)
# CMAKE_CURRENT_LIST_DIR -> third_party folder
set(RESTBED_DIR ${CMAKE_CURRENT_LIST_DIR}/restbed)
ExternalProject_Add(restbed
PREFIX ${RESTBED_DIR}
SOURCE_DIR ${RESTBED_DIR}
CMAKE_ARGS -DBUILD_SSL=NO
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
BUILD_COMMAND cmake ..
BINARY_DIR ${RESTBED_DIR}/build
INSTALL_DIR ${RESTBED_DIR}/distribution
INSTALL_COMMAND make install
)
set(RESTBED_INCLUDE_DIR ${RESTBED_DIR}/distribution/include)
set(RESTBED_LIB_DIR ${RESTBED_DIR}/distribution/lib)
add_library(librestbed IMPORTED STATIC)
add_dependencies(librestbed restbed)
After this I'd like to use target_include_dir and target_link_libraries to add librestbed as a dependency to my root project. After this when I build my XCode project nothing happens, the external lib won't get built. What am I doing wrong? I would not like to use the built-in CMake git functionality because I'd like to store my external dependencies as git submodules in the third_party lib. I'd rather not let CMake figure out if it needs to re-download a given dependency. Thanks in advance!
I think you mixed up the BUILD_COMMAND option with the CONFIGURE_COMMAND option. The cmake .. should be placed after the option CONFIGURE_COMMAND.
ExternalProject_Add(restbed
PREFIX ${RESTBED_DIR}
SOURCE_DIR ${RESTBED_DIR}
CMAKE_ARGS -DBUILD_SSL=NO
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CONFIGURE_COMMAND cmake ..
BINARY_DIR ${RESTBED_DIR}/build
INSTALL_DIR ${RESTBED_DIR}/distribution
INSTALL_COMMAND make install
)
Per the documentation, there are defaults to each of these commands, so you likely don't have to specify the CONFIGURE_COMMAND at all. For example, for BUILD_COMMAND:
If this option is not given, the default build command will be chosen to integrate with the main build in the most appropriate way (e.g. using recursive make for Makefile generators or cmake --build if the project uses a CMake build).
Also, if you do specify the CONFIGURE_COMMAND, you likely expand the arguments you pass it to something like this:
...
CONFIGURE_COMMAND cd restbed && mkdir build && cd build && cmake ..
...
I want to build Google glog with CMake as part of bigger project (solution, in words of Visual Studio). What I want to have as a result:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
-DCMAKE_INSTALL_PREFIX:PATH=xxx {MAIN CMakeLists.txt location}
cmake --build . --target install --config Debug
will build solution in Debug configuration and install files to xxx folder.
Ok, glog is sub project of main solution:
add_subdirectory(third_party/glog_0.3.4)
On Windows everything is ok (see CMakeLists.txt): everything works as expected.
To build glog on Linux, I need to configure .h.in files too (among other work). CMake configure_file does not works: I have .h files but they contain #undef's only. But glog's ./configure works fine, so I found that ExternalProject_Add() may help:
if(UNIX)
include(ExternalProject)
ExternalProject_Add(glog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure
CMAKE_GENERATOR 'Unix Makefiles'
BUILD_COMMAND ${MAKE})
endif()
And cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=xxx . works fine, but cmake --build . --target install --config Debug will give me:
make: *** No rule to make target 'install'. Stop.
If I invoke cmake --build . --config Debug, then it will build and install glog to /usr/local/lib. Next try:
if(UNIX)
include(ExternalProject)
get_filename_component(glog_absolute_install_dir ${CMAKE_INSTALL_PREFIX} ABSOLUTE)
ExternalProject_Add(glog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure --prefix=${glog_absolute_install_dir}
CMAKE_GENERATOR 'Unix Makefiles'
BUILD_COMMAND ${MAKE}
INSTALL_DIR ${glog_absolute_install_dir}
INSTALL_COMMAND "${MAKE}")
endif()
will not install files to xxx and just build it to glog-prefix/src/glog-build/.
Ok, I have no idea how to make it work.. And how to
specify install dir
lib build type (static/shared)
configure type (Debug/Release) - not sure that now it works
On Windows, according to glog's documentation, for 2nd case I do next:
add_library(${lib_name} ${lib_type} ${src_files})
if(build_shared_lib)
add_definitions(-DLIBGLOG_EXPORTS)
else()
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif()
Thanks for any help
I will show you by example, the below is my project structure:
The file FindGLog.cmake in the directory cmake is used to find glog, it contents :
# - Try to find Glog
#
# The following variables are optionally searched for defaults
# GLOG_ROOT_DIR: Base directory where all GLOG components are found
#
# The following are set after configuration is done:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
include(FindPackageHandleStandardArgs)
if (NOT DEFINED GLOG_ROOT)
message("set GLOG_ROOT========================")
set (GLOG_ROOT /usr /usr/local /usr/include/)
endif (NOT DEFINED GLOG_ROOT)
#set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS
${GLOG_ROOT_DIR}
PATH_SUFFIXES
src)
find_library(GLOG_LIBRARY glog libglog
PATHS
${GLOG_ROOT_DIR}
PATH_SUFFIXES
.libs
lib
lib64)
find_package_handle_standard_args(GLOG DEFAULT_MSG
GLOG_INCLUDE_DIR GLOG_LIBRARY)
if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
message("GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS}===========")
message("GLOG_LIBRARY ${GLOG_LIBRARY}===========")
endif()
The main CMakeLists.txt use the above FindGLog.cmake to find glog:
cmake_minimum_required(VERSION 3.5)
project(my_caffe)
set(CMAKE_CXX_STANDARD 11)
# find glog
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GLog REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(my_caffe_test ${SOURCE_FILES})
# link glog
target_link_libraries(my_caffe_test
${GLOG_LIBRARIES}
)
cited from:https://davidstutz.de/running-google-glog-on-travis-ci/
Nowadays (presumably this will be in glog release 0.3.5), there is a CMakeLists.txt included with glog, so no longer any need for ExternalProject.