I'm trying to create a superbuild to compile the dependencies (zlib, nifticlib and boost) and then compile my project, depending on all these libraries.
Here is my CMakeLists:
cmake_minimum_required(VERSION 3.6)
project(CMakeTest)
#-----------------------------------------------------------------------------
# Build options
#-----------------------------------------------------------------------------
option(BUILD_MYPROJECT "Build MYPROJECT." ON)
#-----------------------------------------------------------------------------
# Git protocole option
#-----------------------------------------------------------------------------
option(USE_GIT_PROTOCOL "If behind a firewall turn this off to use http instead." OFF)
set(git_protocol "git")
if(NOT USE_GIT_PROTOCOL)
set(git_protocol "https")
endif()
#-----------------------------------------------------------------------------
# Enable and setup External project global properties
#-----------------------------------------------------------------------------
include(ExternalProject)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
#-----------------------------------------------------------------------------
# Zlib
#-----------------------------------------------------------------------------
message(STATUS "Installing Zlib library.")
ExternalProject_Add(Zlib
SOURCE_DIR "${PROJECT_BINARY_DIR}/deps/zlib"
BINARY_DIR "${PROJECT_BINARY_DIR}/deps/zlib-build"
INSTALL_DIR "${PROJECT_BINARY_DIR}/deps/zlib-install"
GIT_REPOSITORY "${git_protocol}://github.com/madler/zlib.git"
GIT_TAG "50893291621658f355bc5b4d450a8d06a563053d"
CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BIN_DIR:PATH=<INSTALL_DIR>/bin
-DINSTALL_INC_DIR:PATH=<INSTALL_DIR>/include
-DINSTALL_LIB_DIR:PATH=<INSTALL_DIR>/lib
-DINSTALL_MAN_DIR:PATH=<INSTALL_DIR>/share/man
-DINSTALL_PKGCONFIG_DIR:PATH=<INSTALL_DIR>/share/pkgconfig)
if(WIN32)
set(ZLIB_LIB_BASE_NAME "zlibstatic")
set(ZLIB_LIB_NAME_RELEASE "${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ZLIB_LIB_NAME_DEBUG "${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_LIB_BASE_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}")
elseif(UNIX)
set(ZLIB_LIB_BASE_NAME "z")
set(ZLIB_LIB_NAME_RELEASE "${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ZLIB_LIB_NAME_DEBUG "${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
# MacOSX
endif()
ExternalProject_Get_Property(Zlib install_dir)
set(ZLIB_LIBRARY_DIR ${install_dir}/lib)
set(ZLIB_INCLUDE_DIR ${install_dir}/include)
set(ZLIB_BINARY_DIR ${install_dir}/bin)
add_library(zlib STATIC IMPORTED)
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION_DEBUG "${ZLIB_LIBRARY_DIR}/${ZLIB_LIB_NAME_DEBUG}")
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION_RELEASE "${ZLIB_LIBRARY_DIR}/${ZLIB_LIB_NAME_RELEASE}")
#-----------------------------------------------------------------------------
# Niftilib
#-----------------------------------------------------------------------------
message(STATUS "Installing Nifti library.")
ExternalProject_Add(Nifticlib
SOURCE_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib"
BINARY_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib-build"
INSTALL_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib-install"
GIT_REPOSITORY "${git_protocol}://gitlab.com/slckr/nifticlib.git"
GIT_TAG "e26a94e947c210104223f9f49737392c742c1c5b"
CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR}
-DZLIB_LIBRARY_DEBUG:PATH=${ZLIB_LIBRARY_DIR}/${ZLIB_LIB_NAME_DEBUG}
-DZLIB_LIBRARY_RELEASE:PATH=${ZLIB_LIBRARY_DIR}/${ZLIB_LIB_NAME_RELEASE}
DEPENDS Zlib)
set(NIFTIIO_LIB_BASE_NAME "niftiio")
set(NIFTIIO_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${NIFTIIO_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(NIFTICDF_LIB_BASE_NAME "nifticdf")
set(NIFTICDF_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${NIFTICDF_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ZNZ_LIB_BASE_NAME "znz")
set(ZNZ_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${ZNZ_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
ExternalProject_Get_Property(Nifticlib install_dir)
set(NIFTI_LIBRARY_DIR ${install_dir}/lib)
set(NIFTI_INCLUDE_DIR ${install_dir}/include/nifti)
set(NIFTI_BINARY_DIR ${install_dir}/bin)
add_library(niftiio STATIC IMPORTED)
set_target_properties(niftiio PROPERTIES IMPORTED_LOCATION "${NIFTI_LIBRARY_DIR}/${NIFTIIO_LIB_NAME}")
add_library(nifticdf STATIC IMPORTED)
set_target_properties(nifticdf PROPERTIES IMPORTED_LOCATION "${NIFTI_LIBRARY_DIR}/${NIFTICDF_LIB_NAME}")
add_library(znz STATIC IMPORTED)
set_target_properties(znz PROPERTIES IMPORTED_LOCATION "${NIFTI_LIBRARY_DIR}/${ZNZ_LIB_NAME}")
#-----------------------------------------------------------------------------
# Boost
#-----------------------------------------------------------------------------
message(STATUS "Installing Boost library.")
set(BOOST_BOOTSTRAP_COMMAND)
if(WIN32)
set(BOOST_BOOTSTRAP_COMMAND bootstrap.bat)
set(BOOST_B2_COMMAND b2.exe)
elseif(UNIX )
set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh)
set(BOOST_B2_COMMAND ./b2)
else()
# MacOSX
set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh)
set(BOOST_B2_COMMAND ./b2)
endif()
set(BOOST_BUILD_TYPE variant=release)
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
set(BOOST_BUILD_TYPE variant=debug)
endif(${CMAKE_BUILD_TYPE} MATCHES Debug)
set(BOOST_INSTALL_DIR ${PROJECT_BINARY_DIR}/deps/boost-install)
ExternalProject_Add(boost
SOURCE_DIR "${PROJECT_BINARY_DIR}/deps/boost"
BUILD_IN_SOURCE 1
GIT_REPOSITORY "${git_protocol}://github.com/boostorg/boost"
GIT_TAG "5ec478a570bdc71c5d4854e7165a8b3f4fa82ad9"
CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_COMMAND}
BUILD_COMMAND ${BOOST_B2_COMMAND} headers COMMAND ${BOOST_B2_COMMAND} install
link=static
${BOOST_BUILD_TYPE}
--prefix=${BOOST_INSTALL_DIR}
--with-filesystem
--with-program_options
--with-system
--with-thread
-j8
INSTALL_COMMAND ""
)
if(WIN32)
set(BOOST_LIBRARY_DIR ${BOOST_INSTALL_DIR}/lib/boost)
set(BOOST_INCLUDE_DIR ${BOOST_INSTALL_DIR}/include/boost-1_65)
else()
set(BOOST_LIBRARY_DIR ${BOOST_INSTALL_DIR}/lib/boost)
set(BOOST_INCLUDE_DIR ${BOOST_INSTALL_DIR}/include)
endif()
set(BOOST_SUBMODULES system;filesystem;program_options;thread)
#-----------------------------------------------------------------------------
# MyProject
#-----------------------------------------------------------------------------
message(STATUS "Installing MyProject library.")
if(BUILD_MYPROJECT)
set(MYPROJECT_LIBS zlib;znz;nifticdf;niftiio)
ExternalProject_Add(MYPROJECT
SOURCE_DIR "${PROJECT_BINARY_DIR}/MyProject"
BINARY_DIR "${PROJECT_BINARY_DIR}/MyProject-build"
INSTALL_DIR "${PROJECT_BINARY_DIR}/MyProject-install"
GIT_REPOSITORY "${git_protocol}://gitlab.com/slckr/MyProject.git"
GIT_TAG "origin/multithread2"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DZLIB_INC_DIR:PATH=${ZLIB_INCLUDE_DIR}
-DZLIB_LIB_DIR:PATH=${ZLIB_LIBRARY_DIR}
-DNIFTI_INC_DIR:PATH=${NIFTI_INCLUDE_DIR}
-DNIFTI_LIB_DIR:PATH=${NIFTI_LIBRARY_DIR}
-DBOOST_INC_DIR:PATH=${BOOST_INCLUDE_DIR}
-DBOOST_LIB_DIR:PATH=${BOOST_LIBRARY_DIR}
-DBOOST_SUBMODULES:STRING=${BOOST_SUBMODULES}
-DMYPROJECT_LIBS:STRING=${MYPROJECT_LIBS}
DEPENDS Nifticlib boost)
endif()
The problem is when I try to link MyProject to nifticlib or boost, because the library name is different based on the platform (which I handled when importing libraries) the linking fails.
I pass the library directory and in MyProject CMakeLists, I do:
include_directories(${ZLIB_INC_DIR} ${NIFTI_INC_DIR} ${BOOST_INC_DIR})
link_directories(${ZLIB_LIB_DIR} ${NIFTI_LIB_DIR} ${BOOST_LIB_DIR})
target_link_libraries(MyProject zlib znz niftiio nifticdf)
but target_link_libraries fails, because zlib is not found (but I imported it in my superbuild). How can I tell MyProject to use the imported library of my superbuild?
Thank you.
I think this https://crascit.com/2015/07/25/cmake-gtest/ could help you.
The main point of the method in the link is to build the external project during configuration time. This integrates the external project completly in your build and gives access to the targets.
Unfortunaly the example uses gtest to demonstrate the use but it is possible to use it for other dependencies.
Related
How do I connect the libxlsxwriter library to my personal project using CMake.
I cloned the official library files from https://github.com/jmcnamara/libxlsxwriter.
Then I extracted it in my personal project and added a few lines of CMake:
cmake_minimum_required(VERSION 3.11.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
[enter image description here][1]
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main # release-1.10.0
)
include(FetchContent)
FetchContent_Declare(
Bcrypt
GIT_REPOSITORY https://github.com/veltro123/Bcrypt.cpp
GIT_TAG master
)
FetchContent_MakeAvailable(Bcrypt)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Now simply link against gtest or gtest_main as needed. Eg
#ADDED
include_directories("libxlsxwriter/include")
set(XLSXWRITER_LIBRARY "libxlsxwriter/build/libxlsxwriter.a")
add_library(xlsxwriter STATIC IMPORTED)
set_target_properties(xlsxwriter PROPERTIES IMPORTED_LOCATION ${XLSXWRITER_LIBRARY})
target_link_libraries(${PROJECT_NAME} xlsxwriter)
#END
project(MONEYTRACKER)
enable_testing()
add_executable(${PROJECT_NAME} main.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)
add_executable(${PROJECT_NAME}-ut Testing/DateTests.cpp Testing/UserTests.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)
target_link_libraries(${PROJECT_NAME}-ut gtest_main)
target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt)
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}-ut)
This is the error I get:
I am trying to install a package called DICe available here: https://github.com/dicengine/dice on my Ubuntu 20.04 LTS using source code. This package requires another package called Trilinos : https://trilinos.github.io/ . I have successfully build the Trilinos in the following path: ~/Documents/Trilinos/. Now the problem is, when I try to build the DCIe in ~/Documents/DCIe/ it shows error:
CMake Error at CMakeLists.txt:22 (find_package):
By not providing "FindTrilinos.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Trilinos",
but CMake did not find one.
Could not find a package configuration file provided by "Trilinos" with any
of the following names:
TrilinosConfig.cmake
trilinos-config.cmake
Add the installation prefix of "Trilinos" to CMAKE_PREFIX_PATH or set
"Trilinos_DIR" to a directory containing one of the above files. If
"Trilinos" provides a separate development package or SDK, be sure it has
been installed.
I have extracted DCIe source code in ~/Downloads/dice2.0. Can someone guide me how I am supposed to configure the CmakeLists.txt? Here is my changed version:
MESSAGE("\nConfiguring DICe...\n")
# check if the pre-compiled set of libraries and header for windows is being used:
IF(DEFINED DICE_DEVPACK_DIR)
MESSAGE(STATUS "***Using DevPack from: ${DICE_DEVPACK_DIR}")
MESSAGE(STATUS "Note: if any of the following variables have been defined, they will be reset\n DICE_TRILINOS_DIR\n OpenCV_DIR\n CLAPACK_DIR\n NetCDF_DIR\n HDF5_DIR")
SET(DICE_TRILINOS_DIR "${DICE_DEVPACK_DIR}/trilinos")
SET(OpenCV_DIR "${DICE_DEVPACK_DIR}/opencv")
SET(NetCDF_DIR "${DICE_DEVPACK_DIR}/netcdf/lib")
SET(HDF5_DIR "${DICE_DEVPACK_DIR}/netcdf/lib")
SET(CLAPACK_DIR "${DICE_DEVPACK_DIR}/lapack")
link_directories(${CLAPACK_DIR}/F2CLIBS)
ENDIF()
# Try to find Trilinos, if path was not given
IF (NOT DEFINED DICE_TRILINOS_DIR)
# Losely based on:
# https://github.com/trilinos/Trilinos_tutorial/wiki/CMakeFindPackageTrilinosExample
# /usr/share/doc/opencv-doc/examples/face/CMakeLists.txt
# * Find Trilinos
find_package(Trilinos REQUIRED)
IF(Trilinos_FOUND)
MESSAGE("\nFound Trilinos")
SET(DICE_TRILINOS_DIR ${Trilinos_DIR})
MESSAGE("Trilinos_DIR = ${DICE_TRILINOS_DIR}")
ELSE()
MESSAGE(FATAL_ERROR "Could not find Trilinos")
ENDIF()
ENDIF()
MESSAGE(STATUS "Using Trilinos installed in: ${DICE_TRILINOS_DIR}")
# If this is a windows build CLAPACK is required. Find package for
# clapack is automatically enabled by setting the CLAPACK_DIR variable
IF(WIN32 AND NOT DEFINED DICE_DEVPACK_DIR)
# must defined clapack_dir
IF (NOT DEFINED CLAPACK_DIR)
MESSAGE(FATAL_ERROR "\nDICe Error: this is a windows build, so cmake must define CLAPACK_DIR:
(-D CLAPACK_DIR:FILEPATH=<clapack_install_prefix>)!")
ENDIF()
FIND_PACKAGE(clapack PATHS ${CLAPACK_DIR})
IF(clapack_FOUND)
MESSAGE("\nFound CLAPACK in ${CLAPACK_DIR}")
link_directories(${CLAPACK_DIR}/F2CLIBS/libf2c)
ELSE()
MESSAGE("\nERROR: could not find CLAPACK in the following directory: ${CLAPACK_DIR}")
ENDIF()
ENDIF()
IF(WIN32)
IF(NOT BUILD_SHARED_LIBS)
MESSAGE("\nWarning: This is a windows build, but BUILD_SHARED_LIBS is OFF. Setting BUILD_SHARED_LIBS on automatically.")
SET(BUILD_SHARED_LIBS ON)
ENDIF(NOT BUILD_SHARED_LIBS)
ENDIF(WIN32)
IF(BUILD_SHARED_LIBS)
MESSAGE(STATUS "BUILD_SHARED_LIBS is set to ON")
ELSE(BUILD_SHARED_LIBS)
MESSAGE(STATUS "BUILD_SHARED_LIBS is set to OFF")
ENDIF(BUILD_SHARED_LIBS)
# Get Trilinos as one entity
# SET(Trilinos_DIR CACHE PATH "~/Documents/Trilinos")
SET(CMAKE_PREFIX_PATH ${DICE_TRILINOS_DIR} ${CMAKE_PREFIX_PATH})
FIND_PACKAGE(Trilinos PATHS ~/Documents/Trilinos)
IF(NOT Trilinos_FOUND)
MESSAGE(FATAL_ERROR "Could not find Trilinos!")
ENDIF()
MESSAGE("\nFound Trilinos! Here are the details: ")
MESSAGE(" Trilinos_DIR = ${Trilinos_DIR}")
MESSAGE(" Trilinos_VERSION = ${Trilinos_VERSION}")
MESSAGE(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}")
MESSAGE(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES}")
MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}")
MESSAGE(" Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}")
MESSAGE(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}")
MESSAGE(" Trilinos_TPL_INCLUDE_DIRS = ${Trilinos_TPL_INCLUDE_DIRS}")
MESSAGE(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}")
MESSAGE(" Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}")
MESSAGE(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}")
MESSAGE("End of Trilinos details\n")
IF(NOT DEFINED DICE_DEVPACK_DIR)
SET(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} )
SET(CMAKE_C_COMPILER ${Trilinos_C_COMPILER} )
ENDIF()
SET(CMAKE_VERBOSE_MAKEFILE OFF)
IF(NOT DEFINED DICE_MPI_EXEC)
SET(DICE_MPI_EXEC mpiexec)
ENDIF()
# End of setup and error checking
# NOTE: PROJECT command checks for compilers, so this statement
# is moved AFTER setting CMAKE_CXX_COMPILER opton
PROJECT(DICe)
MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
SET(DICE_OUTPUT_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
MESSAGE(STATUS "The output directory for DICe libraries will be: ${DICE_OUTPUT_PREFIX}/lib")
MESSAGE(STATUS "If 'make install' is exectued, the libraries will also be copied to: ${CMAKE_INSTALL_PREFIX}/lib")
# See if tracklib is available
IF(DEFINED TRACKLIB_DIR)
MESSAGE(STATUS "TRACKLIB is ON")
MESSAGE(STATUS "TRACKLIB_DIR is set to: ${TRACKLIB_DIR}")
ADD_DEFINITIONS(-DDICE_ENABLE_TRACKLIB=1)
ELSE()
MESSAGE(STATUS "TRACKLIB is OFF")
ENDIF()
# Try to find OpenCV, if path was not given
IF (NOT DEFINED OpenCV_DIR)
# Losely based on:
# https://github.com/trilinos/Trilinos_tutorial/wiki/CMakeFindPackageTrilinosExample
# /usr/share/doc/opencv-doc/examples/face/CMakeLists.txt
# * Find OpenCV
message(STATUS "OpenCV_DIR not specified, looking in default paths")
find_package(OpenCV REQUIRED)
ELSE()
message(STATUS "Looking for OpenCV in dir: ${OpenCV_DIR}")
find_package( OpenCV NO_DEFAULT_PATH PATHS ${OpenCV_DIR} )
ENDIF()
IF(OpenCV_FOUND)
set(DICE_ENABLE_OPENCV ON)
IF(WIN32)
FILE(GLOB OPENCV_DLLS ${OpenCV_DIR}/x64/vc12/bin/*.dll)
FILE(COPY ${OPENCV_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)
FILE(GLOB OPENCV_DLLS ${OpenCV_DIR}/x64/vc15/bin/*.dll)
FILE(COPY ${OPENCV_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)
ENDIF()
ELSE()
message(FATAL_ERROR "OpenCV not found. OpenCV is now a required package in DICe")
ENDIF()
# FIND NETCDF
set(DICE_ENABLE_NETCDF OFF)
if(DEFINED NetCDF_DIR)
set(DICE_ENABLE_NETCDF ON)
MESSAGE(STATUS "Looking for NetCDF in: ${NetCDF_DIR}")
find_library(NetCDF_lib NAMES libnetcdf.a netcdf PATHS ${NetCDF_DIR})
MESSAGE(STATUS "Looking for HDF5 in: ${HDF5_DIR}")
find_library(HDF5_lib NAMES libhdf5.a hdf5 PATHS ${HDF5_DIR} NO_DEFAULT_PATH)
find_library(HDF5_lib NAMES libhdf5.a hdf5 PATHS ${HDF5_DIR})
find_library(HDF5_hl_lib NAMES libhdf5_hl.a hdf5_hl PATHS ${HDF5_DIR} NO_DEFAULT_PATH)
find_library(HDF5_hl_lib NAMES libhdf5_hl.a hdf5_hl PATHS ${HDF5_DIR})
MESSAGE(STATUS "Using NetCDF lib: ${NetCDF_lib}")
MESSAGE(STATUS "Using HDF5 libs: ${HDF5_lib} ${HDF5_hl_lib}")
IF(NOT NetCDF_lib_NOTFOUND)
SET(DICE_LIBRARIES ${DICE_LIBRARIES} ${NetCDF_lib})
SET(DICE_LIBRARIES ${DICE_LIBRARIES} ${HDF5_lib})
SET(DICE_LIBRARIES ${DICE_LIBRARIES} ${HDF5_hl_lib})
ADD_DEFINITIONS(-DDICE_ENABLE_NETCDF=1)
include_directories(${NetCDF_DIR}/../include)
link_directories(${NetCDF_DIR}/../lib)
IF(WIN32)
FILE(GLOB NetCDF_DLLS ${NetCDF_DIR}/../bin/*.dll)
FILE(COPY ${NetCDF_DLLS} DESTINATION ${DICE_OUTPUT_PREFIX}/bin)
ENDIF()
ELSE()
message(FATAL_ERROR "Error, NetCDF enabled but not found")
ENDIF()
else()
MESSAGE(STATUS "NetCDF will NOT be enabled")
endif()
#
# Hypercine library for reading cine files
#
include(ExternalProject)
MESSAGE(STATUS "Configuring hypercine")
SET(HYPERCINE_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DHYPERCINE_DEBUG_MSG:BOOL=${DICE_DEBUG_MSG} -DOpenCV_DIR:PATH=${OpenCV_DIR})
# base data type:
if(DICE_USE_INT_STORAGE)
SET(HYPERCINE_CMAKE_ARGS ${HYPERCINE_CMAKE_ARGS} -DHYPERCINE_USE_INT_STORAGE:BOOL=ON)
ADD_DEFINITIONS(-DUSE_INT_STORAGE=1)
elseif(DICE_USE_DOUBLE)
SET(HYPERCINE_CMAKE_ARGS ${HYPERCINE_CMAKE_ARGS} -DHYPERCINE_USE_DOUBLE_STORAGE:BOOL=ON)
ADD_DEFINITIONS(-DUSE_DOUBLE_STORAGE=1)
else()
SET(HYPERCINE_CMAKE_ARGS ${HYPERCINE_CMAKE_ARGS} -DHYPERCINE_USE_FLOAT_STORAGE:BOOL=ON)
ADD_DEFINITIONS(-DUSE_FLOAT_STORAGE=1)
endif()
ExternalProject_Add(hypercine
GIT_REPOSITORY git://github.com/dicengine/hypercine.git
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/hypercine
CMAKE_ARGS ${HYPERCINE_CMAKE_ARGS}
)
# base data type:
if(DICE_USE_DOUBLE)
ADD_DEFINITIONS(-DDICE_USE_DOUBLE=1)
MESSAGE(STATUS "Scalar type will be: DOUBLE")
else()
MESSAGE(STATUS "Scalar type will be: FLOAT (default)")
endif()
if(DICE_USE_INT_STORAGE)
ADD_DEFINITIONS(-DDICE_USE_INT_STORAGE=1)
MESSAGE(STATUS "Image intensity storage type will be: INT")
else()
IF(DICE_USE_DOUBLE)
MESSAGE(STATUS "Image intensity storage type will be: DOUBLE")
ELSE()
MESSAGE(STATUS "Image intensity storage type will be: FLOAT (default)")
ENDIF()
endif()
# MPI check -- defaults to TRUE
LIST(FIND Trilinos_TPL_LIST MPI MPI_List_ID)
IF (MPI_List_ID GREATER -1)
MESSAGE(STATUS "Checking if MPI is enabled in Trilinos: MPI ENABLED")
SET(DICE_MPI TRUE)
ADD_DEFINITIONS(-DDICE_MPI=1)
MESSAGE(STATUS "Using DICE_MPI_EXEC: ${DICE_MPI_EXEC}")
ELSE()
MESSAGE(STATUS "Checking if MPI is enabled in Trilinos: MPI NOT ENABLED")
SET(DICE_MPI FALSE)
ENDIF()
SET(DICE_TRILINOS_HEADERS
${Trilinos_INCLUDE_DIRS}
${Trilinos_TPL_INCLUDE_DIRS}
)
SET(DICE_TRILINOS_LIB_DIRS
${Trilinos_LIBRARY_DIRS}
${Trilinos_TPL_LIBRARY_DIRS}
)
link_directories(${DICE_TRILINOS_LIB_DIRS})
ExternalProject_Get_Property(hypercine source_dir)
include_directories(${source_dir}/src)
set(libprefix "lib")
set(libsuffix ".a")
if(WIN32)
set(libprefix "")
set(libsuffix ".lib")
endif()
set(DICE_LIBRARIES ${DICE_LIBRARIES} "${libprefix}hypercine${libsuffix}")
set(DICE_UTILS_LIBRARIES ${DICE_UTILS_LIBRARIES} "${libprefix}hypercine${libsuffix}")
link_directories(${CMAKE_INSTALL_PREFIX}/lib)
if(WIN32)
link_directories(${CMAKE_INSTALL_PREFIX}/bin)
endif()
SET(DICE_HEADER_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/src/api
${CMAKE_CURRENT_SOURCE_DIR}/src/base
${CMAKE_CURRENT_SOURCE_DIR}/src/core
${CMAKE_CURRENT_SOURCE_DIR}/src/netcdf
${CMAKE_CURRENT_SOURCE_DIR}/src/fft
${CMAKE_CURRENT_SOURCE_DIR}/src/ioutils
${CMAKE_CURRENT_SOURCE_DIR}/src/rawi
${CMAKE_CURRENT_SOURCE_DIR}/src/kdtree
${CMAKE_CURRENT_SOURCE_DIR}/src/mesh
)
IF(DEFINED TRACKLIB_DIR)
SET(DICE_HEADER_DIRS
${DICE_HEADER_DIRS}
${TRACKLIB_DIR}/src/
)
ENDIF()
MESSAGE(STATUS "DICE_ENABLE_GLOBAL: ${DICE_ENABLE_GLOBAL}")
IF(DICE_ENABLE_GLOBAL)
IF(NOT DICE_USE_DOUBLE)
MESSAGE(FATAL_ERROR "DICE_ENABLE_GLOBAL can only be used with DICE_USE_DOUBLE=ON")
ENDIF(NOT DICE_USE_DOUBLE)
SET(DICE_HEADER_DIRS
${DICE_HEADER_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/src/global
${CMAKE_CURRENT_SOURCE_DIR}/src/mesh/io
${CMAKE_CURRENT_SOURCE_DIR}/src/global/triangle)
add_definitions(-DTRILIBRARY -DANSI_DECLARATORS -DDICE_ENABLE_GLOBAL=1)
ENDIF()
IF(DICE_ENABLE_OPENCV)
SET(DICE_HEADER_DIRS
${DICE_HEADER_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/src/opencv
)
add_definitions(-DDICE_ENABLE_OPENCV=1)
ENDIF()
SET(DICE_LIBRARIES
${DICE_LIBRARIES}
teuchoscore
teuchosnumerics
teuchoscomm
teuchosparameterlist
)
IF(DICE_ENABLE_GLOBAL)
MESSAGE(STATUS "*** Enabling Global DIC (requires the Tpetra (or Epetra), Seacas libraries, and Belos in Trilinos) ***")
IF(DICE_USE_TPETRA)
SET(DICE_LIBRARIES
${DICE_LIBRARIES}
tpetra
exodus
belos
belostpetra
)
ADD_DEFINITIONS(-DDICE_TPETRA=1)
ELSE()
SET(DICE_LIBRARIES
${DICE_LIBRARIES}
epetra
exodus
belos
ifpack
belosepetra
)
ENDIF()
ELSE()
MESSAGE(STATUS "Global DIC will not be enabled (to enable, set -D DICE_ENABLE_GLOBAL:BOOL=ON in the CMake script)")
SET(DICE_LIBRARIES
${DICE_LIBRARIES}
epetra
)
ENDIF()
# WINDOWS CMake has a bug for find_package() for clapack
# f2clibs have to be added manually here
IF(WIN32)
SET(DICE_LIBRARIES ${DICE_LIBRARIES} libf2c)
ENDIF()
# if debug messages are turned on:
IF(DICE_DEBUG_MSG)
MESSAGE(STATUS "Debugging messages are ON")
ADD_DEFINITIONS(-DDICE_DEBUG_MSG=1)
ELSE(DICE_DEBUG_MSG)
MESSAGE(STATUS "Debugging messages are OFF")
ENDIF(DICE_DEBUG_MSG)
# Windows: use Trilinos compiler flags
# Linux: don't use compiler flags from Trilinos, instead set them manually
# but pick up openmp if Trilinos was compiled with it:
if(WIN32)
SET(CMAKE_CXX_FLAGS ${Trilinos_CXX_COMPILER_FLAGS})
SET(CMAKE_C_FLAGS ${Trilinos_C_COMPILER_FLAGS})
Else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
STRING(FIND ${Trilinos_CXX_COMPILER_FLAGS} "openmp" OpenMPFound)
IF( ${OpenMPFound} GREATER -1 )
MESSAGE(STATUS "OpenMP was enabled in Trilinos so enabling it here. (Found flag at position ${OpenMPFound})")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
ENDIF()
STRING(FIND ${Trilinos_CXX_COMPILER_FLAGS} "c++11" CXX11Found)
IF( ${CXX11Found} GREATER -1 )
MESSAGE(STATUS "c++11 was enabled in Trilinos so enabling it here. (Found flag at position ${CXX11Found})")
ELSE()
MESSAGE(WARNING "could not find c++11 flag for Trilinos (c++11 is required)")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
MESSAGE(STATUS "Trilinos CMAKE_CXX_FLAGS: ${Trilinos_CXX_COMPILER_FLAGS}")
MESSAGE(STATUS "Trilinos CMAKE_C_FLAGS: ${Trilinos_C_COMPILER_FLAGS}")
MESSAGE(STATUS "DICe CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE(STATUS "DICe CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
# Get the git information to put in the header message (to identify the commit corresponding
# to the executable that was run
execute_process(
COMMAND git describe --abbrev=6 --dirty --always --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE(STATUS "Git sha1: ${GIT_SHA1}")
ADD_DEFINITIONS(-DGITSHA1=\"${GIT_SHA1}\")
add_subdirectory(src)
add_subdirectory(tools)
add_subdirectory(tests) ```
Thank you in advance.
Edit: I am using Ububtu in VirtualBox.
As #Tsyvarev rightly pointed out, I just added following lines to the CmakeLists.txt of DICe :
LIST(APPEND CMAKE_PREFIX_PATH "PATH TO TRILINOS INSTALLATION")
Hope it helps others like me. Peace.
Adding Eigen via
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.3.9
)
FetchContent_GetProperties(eigen)
if(NOT eigen_POPULATED)
FetchContent_Populate(eigen)
add_subdirectory(${eigen_SOURCE_DIR} ${eigen_BINARY_DIR})
endif()
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
gives me the error
CMake Error at o/b/x64-Debug/_deps/eigen-build/Eigen3Config.cmake:20 (include):
The file
D:/XXX/o/b/x64-Debug/_deps/eigen-build/Eigen3Targets.cmake
was generated by the export() command. It may not be used as the argument
to the include() command. Use ALIAS targets instead to refer to targets by
alternative names. D:\XXX\o/b/x64-Debug/_deps/eigen-build/Eigen3Config.cmake 20
But downloading Eigen manually and adding it works fine
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/eigen")
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
Any ideas ?
In any order:
Eigen only provide ALIAS target on master
ref: https://gitlab.com/libeigen/eigen/-/commit/cf0b5b0344a3bfcf410e95bf22289015a2daf34b#9a2aa4db38d3115ed60da621e012c0efc0172aae_671_599
FetchContent usage could be
include(FetchContent)
FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
set(EIGEN_BUILD_DOC OFF)
# note: To disable eigen tests,
# you should put this code in a add_subdirectory to avoid to change
# BUILD_TESTING for your own project too since variables are directory
# scoped
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
set( OFF)
FetchContent_MakeAvailable(Eigen)
...
target_link_libraries(YourTarget PRIVATE Eigen3::Eigen)
For find_package() and FetchContent()/add_subdirectory() please see
https://gitlab.kitware.com/cmake/cmake/-/issues/17735
Alright i gave up on FetchContent, i also tried this Local install Eigen in CMAKE not finding target but this didn't work for me either.
I use ExternalProject now (https://github.com/qulacs/qulacs/blob/master/CMakeLists.txt) for fetching and linking eigen
include(ExternalProject)
set(EIGEN_BUILD_DIR ${CMAKE_BINARY_DIR}/eigen)
set(EIGEN_INSTALL_DIR ${CMAKE_SOURCE_DIR}/include/eigen3)
set(EIGEN_INCLUDE_DIR ${EIGEN_INSTALL_DIR})
ExternalProject_Add(
eigen
URL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
PREFIX ${EIGEN_BUILD_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND
${CMAKE_COMMAND} -E copy_directory ${EIGEN_BUILD_DIR}/src/eigen/Eigen ${EIGEN_INCLUDE_DIR}/Eigen
&& ${CMAKE_COMMAND} -E copy_directory ${EIGEN_BUILD_DIR}/src/eigen/unsupported ${EIGEN_INCLUDE_DIR}/unsupported
TEST_COMMAND ""
)
include_directories(SYSTEM ${EIGEN_INCLUDE_DIR})
Additionally add_dependencies has to be used
add_executable(test1 "test1.cpp")
add_dependencies(test1 eigen)
Fetchcontent is great, but it has the unwanted side-effect that your workspace becomes cluttered by all targets of your dependency. If you don't like this then ExternalProject_Add seems to be a reasonable solution. In your case the following should work:
include(ExternalProject)
set(EIGEN_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/eigen-install/")
ExternalProject_Add(
eigen
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/eigen-src"
BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/eigen-build"
INSTALL_DIR "${EIGEN_INSTALL_DIR}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=Release
)
file(MAKE_DIRECTORY ${EIGEN_INSTALL_DIR}/include) # avoid race condition
add_library(eigenlib INTERFACE IMPORTED GLOBAL)
add_dependencies(eigenlib eigen)
target_compile_features(eigenlib INTERFACE cxx_std_14)
set_target_properties(eigenlib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${EIGEN_INSTALL_DIR}/include/eigen3
)
Note that the dependecy is linked to an interface library eigenlib that you can subsequenly link to your own targets as follows:
add_library(linalg INTERFACE)
target_include_directories(linalg
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(linalg INTERFACE eigenlib)
I would like to expand on #Mizux's answer.
In their comment, there is a set( OFF) statement that does nothing. Also, to remove a CMake warning, you might need to do:
include(FetchContent)
FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(EIGEN_BUILD_DOC OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
FetchContent_MakeAvailable(Eigen)
This removes the warning for this policy change.
I'm trying to download externally the mongo-cxx-driver on Windows from the given github repositories, but unfortunately my knowledge of cmake is less to none. I found the next given script in one of the stackoverflow questions: Building mongo-cxx-driver using CMake ExternalProject_Add, but even when it seems to work, it doesn't work. It does make the given project but without the libraries. May someone help with creating those libraries through cmake, externally or internally after downloading the mongo-c-driver and the mongo-cxx-driver from the github repositories.
If someone could go through the needed steps I'd be delighted.
Also if boost could be removed from this equation, it would be good.
The CMakeLists.txt file:
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 11)
project(Test)
option(${PROJECT_NAME}_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
if(${PROJECT_NAME}_SUPERBUILD)
include(ExternalProject)
set(common_cmake_cache_args
-DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER}
)
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES)
list(APPEND common_cmake_cache_args
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
)
endif()
ExternalProject_Add(libmongoc
GIT_REPOSITORY "https://github.com/mongodb/mongo-c-driver.git"
GIT_TAG "1.16.2"
GIT_PROGRESS 1
GIT_SHALLOW 1
SOURCE_DIR "${CMAKE_BINARY_DIR}/libmongoc"
BINARY_DIR "${CMAKE_BINARY_DIR}/libmongoc-build"
INSTALL_DIR "${CMAKE_BINARY_DIR}/libmongoc-install"
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/libmongoc-install
-DENABLE_TESTS:BOOL=OFF
-DENABLE_STATIC:BOOL=OFF
-DENABLE_EXAMPLES:BOOL=OFF
-DENABLE_EXTRA_ALIGNMENT:BOOL=OFF
#INSTALL_COMMAND ""
)
set(libmongoc-1.0_DIR "${CMAKE_BINARY_DIR}/libmongoc-install/lib/cmake/libmongoc-1.0/")
set(libbson-1.0_DIR "${CMAKE_BINARY_DIR}/libmongoc-install/lib/cmake/libbson-1.0/")
ExternalProject_Add(libmongocxx
GIT_REPOSITORY "https://github.com/mongodb/mongo-cxx-driver.git"
GIT_TAG "r3.4.2"
GIT_PROGRESS 1
GIT_SHALLOW 1
SOURCE_DIR "${CMAKE_BINARY_DIR}/libmongocxx"
BINARY_DIR "${CMAKE_BINARY_DIR}/libmongocxx-build"
INSTALL_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install"
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/libmongocxx-install
-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_TESTS:BOOL=OFF
-DENABLE_EXAMPLES:BOOL=OFF
-DBSONCXX_POLY_USE_BOOST:BOOL=OFF
-DBSONCXX_POLY_USE_MNMLSTC:BOOL=ON
-DBSONCXX_POLY_USE_STD:BOOL=OFF
-Dlibmongoc-1.0_DIR:PATH=${libmongoc-1.0_DIR}
-Dlibbson-1.0_DIR:PATH=${libbson-1.0_DIR}
DEPENDS
libmongoc
)
set(libmongocxx_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install/lib/cmake/libmongocxx-3.4.2/")
set(libbsoncxx_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install//lib/cmake/libbsoncxx-3.4.2/")
function(ExternalProject_AlwaysConfigure proj)
# This custom external project step forces the configure and later
# steps to run.
_ep_get_step_stampfile(${proj} "configure" stampfile)
ExternalProject_Add_Step(${proj} forceconfigure
COMMAND ${CMAKE_COMMAND} -E remove ${stampfile}
COMMENT "Forcing configure step for '${proj}'"
DEPENDEES build
ALWAYS 1
)
endfunction()
ExternalProject_Add(${PROJECT_NAME}
SOURCE_DIR "${CMAKE_SOURCE_DIR}"
BINARY_DIR "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build"
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-D${PROJECT_NAME}_SUPERBUILD:BOOL=OFF
-Dlibbsoncxx_DIR:PATH=${libbsoncxx_DIR}
-Dlibmongocxx_DIR:PATH=${libmongocxx_DIR}
INSTALL_COMMAND ""
DEPENDS
libmongocxx
)
ExternalProject_AlwaysConfigure(${PROJECT_NAME})
return()
endif()
message(STATUS "Configuring inner-build")
find_package(libmongocxx REQUIRED)
add_executable(test_mongocxx test.cpp)
target_link_libraries(test_mongocxx PUBLIC ${LIBMONGOCXX_LIBRARIES})
target_include_directories(test_mongocxx PUBLIC ${LIBMONGOCXX_INCLUDE_DIRS})
target_compile_definitions(test_mongocxx PUBLIC ${LIBMONGOCXX_DEFINITIONS})
I want to build the following project: https://github.com/reo7sp/tgbot-cpp
I get these errors: https://imgur.com/S9kgWyv
Makefile part 1: https://imgur.com/O222bJR
Makefile part 2: https://imgur.com/i68QLdC
Now, I think that I need zlib, openssl and boost. Curl seems to be optional.
What is "threads"?
And what is the difference between ...LIBRARY_DEBUG and ...LIBRARY_RELEASE?
What doe LIB and SSL mean in the gui? These "libraries" are not mentioned in the makefile?
I am desperate for days now. Please, help me.
Error:
CMake Error at D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
version "1.1.0j")
Call Stack (most recent call first):
D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
D:/Programme/CMake/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
CMakeLists.txt:47 (find_package)
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(TgBot)
if (${CONAN_EXPORTED})
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# options
option(ENABLE_TESTS "Set to ON to enable building of tests" OFF)
option(BUILD_SHARED_LIBS "Build tgbot-cpp shared/static library." OFF)
# sources
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Do not activate all warnings in VS (too much output for Appveyor)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
endif()
include_directories(include)
set(SRC_LIST
src/Api.cpp
src/EventHandler.cpp
src/TgException.cpp
src/TgTypeParser.cpp
src/net/BoostHttpOnlySslClient.cpp
src/net/CurlHttpClient.cpp
src/net/HttpParser.cpp
src/net/TgLongPoll.cpp
src/net/Url.cpp
src/tools/FileTools.cpp
src/tools/StringTools.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
)
# libs
## threads
find_package(Threads REQUIRED)
# zlib
find_package(ZLIB REQUIRED)
## openssl
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
## curl
find_package(CURL)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
add_definitions(-DHAVE_CURL)
endif()
## boost
set(Boost_USE_MULTITHREADED ON)
if (ENABLE_TESTS)
find_package(Boost 1.59.0 COMPONENTS system unit_test_framework REQUIRED)
else()
find_package(Boost 1.59.0 COMPONENTS system REQUIRED)
endif()
include_directories(${Boost_INCLUDE_DIR})
set(LIB_LIST
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${Boost_LIBRARIES}
${CURL_LIBRARIES}
)
# building project
add_library(${PROJECT_NAME} ${SRC_LIST})
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} ${LIB_LIST})
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
# tests
if (ENABLE_TESTS)
message(STATUS "Building of tests is enabled")
enable_testing()
add_subdirectory(test)
endif()
It turned out that I needed to set some system variables for OpenSSL, ZLib, Boost, curl. For Zlib just do the same procedure. drescherjm was a huge help. So thanks!
Tutorial for this:
OpenSSL: https://www.youtube.com/watch?v=3I7eL2Mm6Ps&index=34&t=0s&list=PLcmZ3Jkh7taY1ensPUAJ4VfMEicDcihhg
and
curl: How do I install and use curl on Windows?
Setting up curl library path in cmake