I am moving from including my dependencies using VCPKG to using FetchContent to make building my docker images slightly easer. I now get my dependencies in a file called get_dependencies.cmake
like:
include(FetchContent)
message(STATUS "Getting iGraph")
FetchContent_Declare(
igraph
URL https://github.com/igraph/igraph/releases/download/0.10.4/igraph-0.10.4.tar.gz
URL_HASH MD5=10a3f325425970c75a7ba8359376e208
FIND_PACKAGE_ARGS NAMES igraph
SYSTEM
)
FetchContent_MakeAvailable(igraph)
message(STATUS "Getting GEOS")
FetchContent_Declare(
GEOS
URL https://download.osgeo.org/geos/geos-3.11.1.tar.bz2
URL_HASH MD5=5732ec96b391ecddc35bda9795b654ea
FIND_PACKAGE_ARGS NAMES GEOS
SYSTEM
)
FetchContent_MakeAvaiable(GEOS)
FetchContent_Declare(
grpc
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v1.52.1
GIT_SHALLOW ON
SYSTEM
)
FetchContent_MakeAvailable(grpc)
etc..
However my code is now running really slowly. I cant tell if this is because it is some network issue (as my office is currently experiencing them) or if my dependencies (grpc) have been built without optimizations.
My library is being built like:
file(GLOB_RECURSE INCLUDE_FILES CONFIGURE_DEPENDS LIST_DIRECTORIES false ${CMAKE_CURRENT_SOURCE_DIR} *.h)
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS LIST_DIRECTORIES false ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
set(DEPENDENCIES
igraph
geos
GribManagerClient
Eigen3::Eigen
Boost::functional
)
add_library(
RoutingLib
${INCLUDE_FILES}
${SRC_FILES}
)
add_dependencies(RoutingLib ${DEPENDENCIES})
target_link_libraries(RoutingLib PUBLIC ${DEPENDENCIES})
target_compile_options(RoutingLib PRIVATE ${RoutingLib_FLAGS_LIST})
And the value for RoutingLib_FLAGS_LIST is in a CMakePresets.json file as:
"RoutingLib_FLAGS": "-std=c++17 -pthread -O3 -fPIC -Wall -Wextra -pedantic"
Does FetchContent
automatically build my external libraries with the optimisation flags, or do I need to add the line:
add_compile_options(-O3)
to the top of my cmake file that gets my external dependencies?