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

2017-01-04 Thread Matthew Woehlke
(Arf, re-send with an account that's allowed to post to the list...)

On 2017-01-04 14:52, Parag Chandra wrote:
> If I’m not mistaken, when a library cannot be found, the value of
> the variable “ARMADILLO” will be set to “ARMADILLO-NOTFOUND”.

Correct. But...

> So I think you need to adjust your test to:
> 
> IF (${ARMADILLO} STREQUAL “ARMADILLO-NOTFOUND”)
>   # do what you want
> ENDIF ()

CMake treats several strings as having the Boolean value 'false',
including "FALSE" (duh), "0", "OFF", and anything that ends with
"-NOTFOUND". So, it's clearer to just write `if(NOT ARMADILLO)`.

(That said, note that it is convention to name variables that receive
the location of a library like ARMADILLO_LIBRARY. Also, uppercase
commands are sooo last decade ;-).)

BTW, avoid writing unquoted variable expansions in `if()`, as they are
subject to multiple expansion that way. (And it's only recently that
quoted values are not subject to expansion!) Instead, just write the
variable name without the `${` and `}`; it will be expanded for you.

-- 
Matthew
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

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

2017-01-04 Thread Parag Chandra
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  on behalf of aishwarya selvaraj 

Date: Wednesday, January 4, 2017 at 12:29 PM
To: cmake 
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 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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake