[CMake] [EXTERNAL]: To include external libraries using Cmake

Parag Chandra parag at ionicsecurity.com
Wed Jan 4 14:52:49 EST 2017


Hi there,

If I’m not mistaken, when a library cannot be found, the value of the variable “ARMADILLO” will be set to “ARMADILLO-NOTFOUND”. So I think you need to adjust your test to:

IF (${ARMADILLO} STREQUAL “ARMADILLO-NOTFOUND”)
  # do what you want
ENDIF ()

The following links in the doc may be helpful:

https://cmake.org/cmake/help/v3.7/command/find_library.html
https://cmake.org/cmake/help/v3.7/command/if.html

Parag Chandra
Technical Lead, Mobile Team
Mobile: +1.919.824.1410

Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309




From: CMake <cmake-bounces at cmake.org> on behalf of aishwarya selvaraj <aishwaryaselvaraj1708 at gmail.com>
Date: Wednesday, January 4, 2017 at 12:29 PM
To: cmake <cmake at cmake.org>
Subject: [EXTERNAL]: [CMake] To include external libraries using Cmake

Hi ,
I'm using Cmake to create binary files as it can give a way to build my  application that will successfully compile on different platforms .
I use :
Linux -14.04
Cmake - 2.8.12

My .cpp code is called TSM_CODE_V3.cpp.It<http://tsm_code_v3.cpp.it/> depends on two external library files .1) armadillo 2) sndfile .
I scripted a CmakeLists.txt as follows :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
PROJECT(TSM2)

FIND_LIBRARY(ARMADILLO armadillo)
MESSAGE(STATUS "Armadillo Library location: " ${ARMADILLO})

IF (NOT ARMADILLO_FOUND)
include(ExternalProject)
MESSAGE(STATUS "Armadillo not found in the system ,Trying to install armadillo...")
ExternalProject_Add(armadillo
  URL https://github.com/lsolanka/armadillo/archive/master.zip
  PREFIX ${CMAKE_CURRENT_BINARY_DIR}/armadillo-latest)
ENDIF()

FIND_LIBRARY(SNDFILE sndfile)
MESSAGE(STATUS "Sndfile Library location: " ${SNDFILE})

IF (NOT SNDFILE_FOUND)
include(ExternalProject)
MESSAGE(STATUS "Armadillo not found in the system ,Trying to install libsndfile...")
ExternalProject_Add(sndfile
  URL https://github.com/erikd/libsndfile/archive/master.zip
  PREFIX ${CMAKE_CURRENT_BINARY_DIR}/sndfile-latest)
ENDIF()

ADD_EXECUTABLE(tsm ${PROJECT_SOURCE_DIR}/src/TSM_CODE_V3.cpp)
TARGET_LINK_LIBRARIES(tsm ${ARMADILLO} ${SNDFILE})

I made use of ExternalProject_add to download the external libraries from the specified link address ,but when I try to compile the CmakeLists.txt , it throws an error of saying library not found .Basically , the external library is not downloaded from the specified link .

I'm not  sure where am I going wrong here .
Can anyone help me out ?
Hoping to hear from you..

--
Regards,
Aishwarya Selvaraj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170104/a8897244/attachment.html>


More information about the CMake mailing list