cmake compile undefined reference - cmake

Let me first start with my CMakeLists.txt source:
cmake_minimum_required(VERSION 2.8.7)
project(audiowaveform)
#set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: default is Release")
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
message(STATUS "CMAKE_VERSION=${CMAKE_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_MODULE_PATH "${audiowaveform_SOURCE_DIR}/cmake/modules")
message(STATUS "CMAKE_MODULE_PATH='${CMAKE_MODULE_PATH}'")
include(SystemInfo)
#-------------------------------------------------------------------------------
#
# Version number
#
#-------------------------------------------------------------------------------
# Read version number from VERSION file and split into its component parts.
file(STRINGS "VERSION" VERSION)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" VERSION_PARTS ${VERSION})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH ${CMAKE_MATCH_3})
message(STATUS "Building version ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
#-------------------------------------------------------------------------------
#
# Dependencies
#
#-------------------------------------------------------------------------------
find_package(LibGD REQUIRED)
if(LIBGD_FOUND)
message(STATUS "LIBGD_INCLUDE_DIR='${LIBGD_INCLUDE_DIR}'")
message(STATUS "LIBGD_LIBRARY=${LIBGD_LIBRARY}")
include_directories(${LIBGD_INCLUDE_DIR})
endif(LIBGD_FOUND)
find_package(LibSndFile REQUIRED)
if(LIBSNDFILE_FOUND)
message(STATUS "LIBSNDFILE_INCLUDE_DIR='${LIBSNDFILE_INCLUDE_DIR}'")
message(STATUS "LIBSNDFILE_LIBRARY=${LIBSNDFILE_LIBRARY}")
include_directories(${LIBSNDFILE_INCLUDE_DIR})
endif(LIBSNDFILE_FOUND)
find_package(LibMad REQUIRED)
if(LIBMAD_FOUND)
message(STATUS "LIBMAD_INCLUDE_DIR='${LIBMAD_INCLUDE_DIR}'")
message(STATUS "LIBMAD_LIBRARY=${LIBMAD_LIBRARY}")
include_directories(${LIBMAD_INCLUDE_DIR})
endif(LIBMAD_FOUND)
find_package(LibId3Tag REQUIRED)
if(LIBID3TAG_FOUND)
message(STATUS "LIBID3TAG_INCLUDE_DIR='${LIBID3TAG_INCLUDE_DIR}'")
message(STATUS "LIBID3TAG_LIBRARY=${LIBID3TAG_LIBRARY}")
include_directories(${LIBID3TAG_INCLUDE_DIR})
endif(LIBID3TAG_FOUND)
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIRS CACHE)
find_package(Boost 1.46.0 COMPONENTS program_options filesystem regex system REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS='${Boost_INCLUDE_DIRS}'")
message(STATUS "Boost_LIBRARIES='${Boost_LIBRARIES}'")
include_directories(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
#-------------------------------------------------------------------------------
#
# Packaging
#
#-------------------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "audiowaveform")
set(CPACK_PACKAGE_VENDOR "Chris Needham")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT "Chris Needham <chris#chrisneedham.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Audio waveform data and image generator")
set(CPACK_PACKAGE_DESCRIPTION "Generates audio waveform data that can be used to render waveform images, similar to Audacity")
set(CPACK_RESOURCE_FILE_LICENSE "${audiowaveform_SOURCE_DIR}/COPYING")
set(CPACK_RESOURCE_FILE_README "${audiowaveform_SOURCE_DIR}/README.md")
set(PACKAGE_RELEASE_NUMBER 1)
if(UNIX AND NOT APPLE AND NOT CYGWIN)
if(OF_DISTRO_IS_UBUNTU)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_SECTION "sound")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${OF_SYSTEM_ARCH}")
set(PACKAGE_BOOST_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmad0 (>=0.15.1), libsndfile1 (>= 1.0.25), libgd2-xpm (>= 2.0.35), libboost-program-options${PACKAGE_BOOST_VERSION}, libboost-filesystem${PACKAGE_BOOST_VERSION}, libboost-regex${PACKAGE_BOOST_VERSION}")
# http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-pkgname
# The Debian binary package file names conform to the following convention:
# <foo>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_NUMBER}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if(OF_DISTRO_IS_CENTOS OR OF_DISTRO_IS_FEDORA)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Multimedia")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${OF_SYSTEM_ARCH}")
set(CPACK_RPM_PACKAGE_REQUIRES "libmad >= 0.15.1, libsndfile >= 1.0.25, gd >= 2.0.35, boost >= ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_NUMBER}.${OF_SYSTEM_ARCH}")
endif()
endif()
include(CPack)
#-------------------------------------------------------------------------------
#
# Compiler flags
#
#-------------------------------------------------------------------------------
if(CMAKE_VERSION VERSION_LESS "2.8.10")
exec_program(
${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE COMPILER_VERSION_STRING
)
string(REGEX REPLACE ".*([0-9]\\.[0-9]\\.[0-9]).*" "\\1" CMAKE_CXX_COMPILER_VERSION ${COMPILER_VERSION_STRING})
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.6.3")
message(FATAL_ERROR "g++ 4.6.3 or later required")
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7")
set(CMAKE_CXX_FLAGS "-std=c++11")
else()
# Set GTEST_LANG_CXX11=0 to disable C++11 features when compiling googlemock.
# Without this compilation fails with g++ 4.6.3 on gmock-matchers.h.
set(CMAKE_CXX_FLAGS "-std=c++0x -DGTEST_LANG_CXX11=0")
endif()
set(COMMON_FLAGS "-Wall -Wextra -Wconversion -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -DBOOST_FILESYSTEM_NO_DEPRECATED")
set(CMAKE_C_FLAGS ${COMMON_FLAGS})
if(APPLE)
set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()
message(STATUS "CMAKE_CXX_COMPILER_VERSION='${CMAKE_CXX_COMPILER_VERSION}'")
message(STATUS "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}'")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}'")
message(STATUS "CMAKE_CXX_COMPILE_OBJECT='${CMAKE_CXX_COMPILE_OBJECT}'")
#-------------------------------------------------------------------------------
#
# Source files
#
#-------------------------------------------------------------------------------
include_directories(src)
# Configure a header file to pass some of the CMake settings to the source code.
configure_file(
"${PROJECT_SOURCE_DIR}/src/Config.h.in"
"${PROJECT_BINARY_DIR}/Config.h"
)
# Add the binary directory to the search path for include files so that we find
# Config.h.
include_directories("${PROJECT_BINARY_DIR}")
set(MODULES
src/AudioFileReader.cpp
src/AudioProcessor.cpp
src/BStdFile.cpp
src/Error.cpp
src/GdImageRenderer.cpp
src/MathUtil.cpp
src/Mp3AudioFileReader.cpp
src/Options.cpp
src/OptionHandler.cpp
src/Rgba.cpp
src/SndFileAudioFileReader.cpp
src/TimeUtil.cpp
src/WaveformBuffer.cpp
src/WaveformColors.cpp
src/WaveformGenerator.cpp
src/WaveformRescaler.cpp
src/WavFileWriter.cpp
src/madlld-1.1p1/bstdfile.c
)
set(SRCS
src/Main.cpp
${MODULES}
)
add_executable(audiowaveform ${SRCS})
#-------------------------------------------------------------------------------
#
# Linker
#
#-------------------------------------------------------------------------------
# Specify libraries to link against.
set(LIBS ${LIBSNDFILE_LIBRARY} ${LIBMAD_LIBRARY} ${LIBID3TAG_LIBRARY} ${Boost_LIBRARIES} ) #${ZLIB_LIBRARIES}
target_link_libraries(audiowaveform ${LIBS} )
target_link_libraries(audiowaveform ${LIBGD_LIBRARY} )
#-------------------------------------------------------------------------------
#
# Tests
#
#-------------------------------------------------------------------------------
if (NOT DEFINED ENABLE_TESTS)
set(ENABLE_TESTS 0)
endif()
if(ENABLE_TESTS)
enable_testing()
# Use EXCLUDE_FROM_ALL to prevent installing googletest headers as part of
# 'make install'.
add_subdirectory(googlemock EXCLUDE_FROM_ALL)
set(TESTS
test/AudioFileReaderTest.cpp
test/GdImageRendererTest.cpp
test/MathUtilTest.cpp
test/Mp3AudioFileReaderTest.cpp
test/OptionsTest.cpp
test/OptionHandlerTest.cpp
test/RgbaTest.cpp
test/SndFileAudioFileReaderTest.cpp
test/TimeUtilTest.cpp
test/WavFileWriterTest.cpp
test/WaveformBufferTest.cpp
test/WaveformGeneratorTest.cpp
test/WaveformRescalerTest.cpp
test/util/FileDeleter.cpp
test/util/FileUtil.cpp
test/util/Streams.cpp
)
include_directories(${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)
set(TEST_LIBS gmock_main)
add_executable(audiowaveform_tests ${MODULES} ${TESTS})
target_link_libraries(audiowaveform_tests ${LIBS} ${TEST_LIBS})
add_test(audiowaveform_tests audiowaveform_tests)
else()
message(STATUS "Unit tests disabled")
endif()
#-------------------------------------------------------------------------------
#
# Documentation
#
#-------------------------------------------------------------------------------
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
COMMAND gzip -c -9 ${PROJECT_SOURCE_DIR}/doc/audiowaveform.1 > ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
DEPENDS ${PROJECT_SOURCE_DIR}/doc/audiowaveform.1
)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
COMMAND gzip -c -9 ${PROJECT_SOURCE_DIR}/doc/audiowaveform.5 > ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
DEPENDS ${PROJECT_SOURCE_DIR}/doc/audiowaveform.5
)
add_custom_target(doc
DEPENDS ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
)
add_dependencies(audiowaveform doc)
#-------------------------------------------------------------------------------
#
# Installation
#
#-------------------------------------------------------------------------------
message(STATUS "CMAKE_INSTALL_PREFIX='${CMAKE_INSTALL_PREFIX}'")
# Install executable
install(TARGETS audiowaveform DESTINATION bin)
# Install man pages
install(
FILES ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
DESTINATION share/man/man1
)
install(
FILES ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
DESTINATION share/man/man5
)
#-------------------------------------------------------------------------------
Now here is the message when I run cmake:
The C compiler identification is GNU 5.4.1
The CXX compiler identification is GNU 5.4.1
Check for working C compiler: /usr/bin/cc
Check for working C compiler: /usr/bin/cc -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /usr/bin/c++
Check for working CXX compiler: /usr/bin/c++ -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Build type not specified: default is Release
CMAKE_VERSION=3.5.2
Build type: Release
CMAKE_MODULE_PATH='/home/medo/build2/audiowaveform-master/cmake/modules'
Building version 1.1.0
Found LibGD: /usr/local/lib/libgd.a
LIBGD_INCLUDE_DIR='/usr/local/include'
LIBGD_LIBRARY=/usr/local/lib/libgd.a
Found LibSndFile: /usr/local/lib/libsndfile.a
LIBSNDFILE_INCLUDE_DIR='/usr/local/include'
LIBSNDFILE_LIBRARY=/usr/local/lib/libsndfile.a
Found LibMad: /usr/local/lib/libmad.a
LIBMAD_INCLUDE_DIR='/usr/local/include'
LIBMAD_LIBRARY=/usr/local/lib/libmad.a
Found LibId3Tag: /usr/local/lib/libid3tag.a
LIBID3TAG_INCLUDE_DIR='/usr/local/include'
LIBID3TAG_LIBRARY=/usr/local/lib/libid3tag.a
Boost version: 1.58.0
Found the following Boost libraries:
program_options
filesystem
regex
system
Boost_INCLUDE_DIRS='/usr/include'
Boost_LIBRARIES='/usr/lib/x86_64-linux-gnu/libboost_program_options.a;/usr/lib/x86_64-linux-gnu/libboost_filesystem.a;/usr/lib/x86_64-linux-gnu/libboost_regex.a;/usr/lib/x86_64-linux-gnu/libboost_system.a'
CMAKE_CXX_COMPILER_VERSION='5.4.1'
CMAKE_CXX_FLAGS='-std=c++11 -Wall -Wextra -Wconversion -pedantic -DBOOST_FILESYSTEM_NO_DEPRECATED'
CMAKE_CXX_FLAGS_DEBUG='-g'
CMAKE_CXX_FLAGS_RELEASE='-O3 -DNDEBUG'
CMAKE_CXX_COMPILE_OBJECT='<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>'
Unit tests disabled
CMAKE_INSTALL_PREFIX='/usr/local'
Configuring done
Generating done
now i enter to build folder and ran make command
and when the progress 100% its give me an error
[100%] Linking CXX executable audiowaveform
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `sf_flac_error_callback':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:520: undefined reference to `FLAC__StreamDecoderErrorStatusString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_seek':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1391: undefined reference to `FLAC__stream_decoder_seek_absolute'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_close':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:736: undefined reference to `FLAC__metadata_object_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:739: undefined reference to `FLAC__stream_encoder_finish'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:740: undefined reference to `FLAC__stream_encoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:745: undefined reference to `FLAC__stream_decoder_finish'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:746: undefined reference to `FLAC__stream_decoder_delete'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_strings':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:627: undefined reference to `FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:628: undefined reference to `FLAC__metadata_object_vorbiscomment_append_comment'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:631: undefined reference to `FLAC__stream_encoder_set_metadata'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_header':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:646: undefined reference to `FLAC__stream_encoder_init_stream'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:647: undefined reference to `FLAC__StreamEncoderInitStatusString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_strings':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:582: undefined reference to `FLAC__metadata_object_new'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `sf_flac_meta_get_vorbiscomments':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:414: undefined reference to `FLAC__metadata_object_vorbiscomment_find_entry_from'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_enc_init':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:792: undefined reference to `FLAC__stream_encoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:793: undefined reference to `FLAC__stream_encoder_new'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:796: undefined reference to `FLAC__stream_encoder_set_channels'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:801: undefined reference to `FLAC__stream_encoder_set_sample_rate'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:806: undefined reference to `FLAC__stream_encoder_set_bits_per_sample'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:811: undefined reference to `FLAC__stream_encoder_set_compression_level'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_d2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1272: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_f2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1141: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_i2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1099: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_s2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1057: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_read_loop':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:919: undefined reference to `FLAC__stream_decoder_get_state'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:932: undefined reference to `FLAC__stream_decoder_process_single'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:934: undefined reference to `FLAC__stream_decoder_get_state'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:936: undefined reference to `FLAC__StreamDecoderStateString'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:921: undefined reference to `FLAC__StreamDecoderStateString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_read_header':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:825: undefined reference to `FLAC__stream_decoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:826: undefined reference to `FLAC__stream_decoder_new'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:829: undefined reference to `FLAC__stream_decoder_set_metadata_respond_all'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:831: undefined reference to `FLAC__stream_decoder_init_stream'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:834: undefined reference to `FLAC__stream_decoder_process_until_end_of_metadata'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:841: undefined reference to `FLAC__stream_decoder_get_decode_position'
/usr/local/lib/libsndfile.a(ogg.o): In function `ogg_close':
/home/medo/build2/lib/libsndfile-1.0.28/src/ogg.c:103: undefined reference to `ogg_sync_clear'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:328: undefined reference to `png_get_valid'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:336: undefined reference to `png_get_tRNS'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:311: undefined reference to `png_get_pHYs'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:292: undefined reference to `png_set_strip_16'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:396: undefined reference to `png_get_tRNS'
/usr/local/lib/libgd.a(gd_png.o): In function `gdPngReadData':
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:89: undefined reference to `png_error'
collect2: error: ld returned 1 exit status
CMakeFiles/audiowaveform.dir/build.make:570: recipe for target 'audiowaveform' failed
make[2]: *** [audiowaveform] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/audiowaveform.dir/all' failed
make[1]: *** [CMakeFiles/audiowaveform.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
I don't know what happened. All the libraries were linked and at the end it gave me this error. Does anyone have any ideas?

Related

CMAKE_EXE_LINKER_FLAGS vs target_link_libraries

trying to play around with odas library, using following CMakeLists.txt file to crosscompile for Raspberry PI platform:
make_minimum_required(VERSION 3.10)
# Set some basic project attributes
project (Audio_Sweep_Cross_CMake_04
VERSION 0.1
DESCRIPTION "Audio Sweep Project")
# Referencing ODAS here
include (CMakeListsOdas.cmake)
#Add base directory for includes (global)
include_directories(include)
set (SRC src)
# This project will output an executable file
add_executable(${PROJECT_NAME} ${SRC}/main.cpp )
# Include the configuration header in the build
SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
set(ENV{PKG_CONFIG_PATH} "/sysroot/usr/lib/aarch64-linux-gnu/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_ALSA REQUIRED alsa)
pkg_check_modules(PC_FFTW3 REQUIRED fftw3f)
pkg_check_modules(PC_LIBCONFIG REQUIRED libconfig)
pkg_check_modules(PC_PULSEAUDIO REQUIRED libpulse-simple)
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
# m
# pthread
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
This one compiles no problem.
However, if I comment out
# SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
and un-comment m and pthread in
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
m
pthread
)
then, when i try to build the project, i am getting a bunch of errors:
**** Incremental Build of configuration Debug for project RPI_audio_sweep_04 ****
/usr/bin/ninja -j 8 all
[1/1] Linking CXX executable Audio_Sweep_Cross_CMake_04
FAILED: Audio_Sweep_Cross_CMake_04
: && /opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-g++ --sysroot=/sysroot -g --sysroot=/sysroot CMakeFiles/Audio_Sweep_Cross_CMake_04.dir/src/main.cpp.o -o Audio_Sweep_Cross_CMake_04 -Wl,-rpath,/RPI_audio_sweep_04/_build/Debug libodas.so -lfftw3f -lasound -lconfig -lpulse-simple -lpulse -lm -lpthread && :
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(pthread_create.o): in function `allocate_stack':
./nptl/allocatestack.c:525: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/allocatestack.c:647: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_initialize_minimal_internal':
./nptl/nptl-init.c:335: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:344: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:360: undefined reference to `_dl_init_static_tls'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:362: undefined reference to `_dl_wait_lookup_done'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_get_minstack':
./nptl/nptl-init.c:393: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(unwind.o): in function `_jmpbuf_sp':
./nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
"/usr/bin/ninja -j 8 all" terminated with exit code 1. Build might be incomplete.
Not sure what is going on here.

Include tensorflow lite libraries in CMakeLists.txt of C++ project giving errors "undefined reference to `ruy::ScopedSuppressDenormals"

I'm trying to include TensorFlow lite libraries in CMakeLists.txt of C++ project. I followed the instructure in https://www.tensorflow.org/lite/guide/build_cmake
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build && cd tflite_build
cmake ../tensorflow_src/tensorflow/lite -DTFLITE_ENABLE_XNNPACK=OFF
-DTFLITE_ENABLE_EXTERNAL_DELEGATE=OFF TFLITE_ENABLE_RUY=ON/OFF (tried both option)
cmake --build . --config release -j24
and added all the libs to the CmakeLists.txt file as follow
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
${TFLITE_DIR}/eigen
${TFLITE_DIR}/neon2sse
${TFLITE_DIR}/abseil-cpp
${TFLITE_DIR}/farmhash/src
${TFLITE_DIR}/flatbuffers/include
${TFLITE_DIR}/gemmlowp/public
${TFLITE_DIR}/gemmlowp
${TFLITE_DIR}/ruy
${TFLITE_DIR}/cpuinfo/include
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_DIR}/_deps/farmhash-build/libfarmhash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_functions.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_handle.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_info.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_city.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_low_level_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/profiling/libabsl_exponential_biased.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_base.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/status/libabsl_status.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a
${TFLITE_DIR}/_deps/flatbuffers-build/libflatbuffers.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_cpuinfo.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_frontend.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_blocking_counter.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_apply_multiplier.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_block_map.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_trmul.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_denormal.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepacked_cache.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_system_aligned_alloc.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context_get_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_allocator.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_wait.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_thread_pool.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_tune.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx512.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg2d.a
${TFLITE_DIR}/_deps/clog-build/libclog.a
${TFLITE_DIR}/_deps/cpuinfo-build/libcpuinfo.a
${TFLITE_DIR}/libtensorflow-lite.a
dl
)
It worked on a windows machine but on Linux I'm getting error about
undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
[ 33%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke()':
interpreter.cc:(.text+0x3ff): undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
/usr/bin/ld: interpreter.cc:(.text+0x523): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke() [clone .cold]':
interpreter.cc:(.text.unlikely+0x5c): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o: in function `SSD_MOBILENET::loadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
ssd_mobilenet_tflite.cpp:(.text+0x2b2): undefined reference to `tflite::ops::builtin::BuiltinOpResolver::BuiltinOpResolver()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:231: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I don't want to add the libs as "add_subdirectory" as it was given in the guide because it will compile every time I create a new project
So how can I solve the undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
UPDATE:
if I change the CMakeLists.txt to :
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
find_package(TFLITE)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_LIBS}
)
I take this error
from test_cpp/src/main.cpp:1:
test_cpp/tensorflow_src/tensorflow/lite/interpreter_builder.h:26:10: fatal error: flatbuffers/flatbuffers.h: No such file or directory
26 | #include "flatbuffers/flatbuffers.h" // from #flatbuffers
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/main.dir/build.make:63: CMakeFiles/main.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I found this repo that contains all needed libs for the project https://github.com/muhammedakyuzlu/tflite-cpp-package
I believe that the problem you have is the ordering of the libs.
Try putting the libtensorflow-lite.a before the ruy-*.a in your setup.
There is another trick that could help you getting started.
Just add this to your CMake File:
include(FetchContent)
FetchContent_Declare(
tensorflow
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
GIT_TAG v2.10.0
SOURCE_SUBDIR tensorflow/lite
)
FetchContent_MakeAvailable(tensorflow)
and link to the library:
target_link_libraries(${PROJECT_NAME} PRIVATE
tensorflow-lite
)
This is downloading all dependencies automatically and should make you ready to go.

What is a correct way to solve undefined reference to undefined reference to `LLVMInitializeAArch64TargetInfo'

In Clion when i build llvm project I got following message:
CMakeFiles/codegen_llvm.dir/main.cpp.o: In function `llvm::InitializeAllTargetInfos()':
/usr/lib/llvm-9/include/llvm/Config/Targets.def:26: undefined reference to `LLVMInitializeAArch64TargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:27: undefined reference to `LLVMInitializeAMDGPUTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:28: undefined reference to `LLVMInitializeARMTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:29: undefined reference to `LLVMInitializeBPFTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:30: undefined reference to `LLVMInitializeHexagonTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:31: undefined reference to `LLVMInitializeLanaiTargetInfo'
And My CmakeLists is here:
cmake_minimum_required(VERSION 3.15)
project(codegen_llvm)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_CXX_STANDARD 14)
add_executable(codegen_llvm main.cpp)
llvm_map_components_to_libnames(llvm_libs support core irreader executionEngine)
target_link_libraries(codegen_llvm ${llvm_libs})
...
What should I do?
cmake solution
cmake_minimum_required(VERSION 3.10)
project(project_name )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
link_libraries()
execute_process(COMMAND llvm-config --libs OUTPUT_VARIABLE LIBS)
execute_process(COMMAND llvm-config --system-libs OUTPUT_VARIABLE SYS_LIBS)
execute_process(COMMAND llvm-config --ldflags OUTPUT_VARIABLE LDF)
#message(STATUS "Found LLVM" ${LIBS})
string(STRIP ${LIBS} LIBS)
string(STRIP ${SYS_LIBS} SYS_LIBS)
string(STRIP ${LDF} LDF)
link_libraries(${LIBS} ${SYS_LIBS} ${LDF})
execute_process(COMMAND llvm-config --cxxflags OUTPUT_VARIABLE CMAKE_CXX_FLAGS)
string(STRIP ${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
add_executable(project_name toy.cpp)
one liner
clang++ -g toy.cpp $(llvm-config --cxxflags --ldflags --system-libs --libs) -O3 -o toy
If you still do not have a solution for this error, try to add ${LLVM_TARGETS_TO_BUILD} to your link libraries.
I am using CLion too, and I solved this by changing:
llvm_map_components_to_libnames(llvm_libs support core irreader codegen mc mcparser option)
to:
llvm_map_components_to_libnames(llvm_libs ${LLVM_TARGETS_TO_BUILD} support core irreader codegen mc mcparser option)
In your last but one line config is not an llvm component, so you'd want to remove it. To see the list of official components, use the llvm-config --components command.

How to link Qt 5.9 in ROS?

The following CMakeList produces errors which have been listed below:
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
project(draw_on_images)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
find_package(OpenCV 2.4.8 REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Quick REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
catkin_package(
CATKIN_DEPENDS roscpp rospy std_msgs
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp src/provide_qpixmap_to_qml.cpp )
qt5_use_modules(${PROJECT_NAME} Core Qml Quick)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Qml Qt5::Quick ${OpenCV_LIBS})
The way I run it:
catkin_make -DCMAKE_PREFIX_PATH="/opt/Qt5.9.1/5.9.1/gcc_64/lib/" -DWITH_QT:BOOL=ON
Yes I have sourced it.
Errors:
Base path: /home/.../ros_workspace_test
Source space: /home/.../ros_workspace_test/src
Build space: /home/.../ros_workspace_test/build
Devel space: /home/.../ros_workspace_test/devel
Install space: /home/.../ros_workspace_test/install
####
#### Running command: "cmake /home/.../ros_workspace_test/src -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/gcc_64/lib/ -DWITH_QT:BOOL=ON -DCATKIN_DEVEL_PREFIX=/home/.../ros_workspace_test/devel -DCMAKE_INSTALL_PREFIX=/home/.../ros_workspace_test/install -G Unix Makefiles" in "/home/.../ros_workspace_test/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/.../ros_workspace_test/devel
-- Using CMAKE_PREFIX_PATH: /opt/Qt5.9.1/5.9.1/gcc_64/lib/
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/.../ros_workspace_test/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - draw_on_images
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'draw_on_images'
-- ==> add_subdirectory(draw_on_images)
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_QT
-- Build files have been written to: /home/.../ros_workspace_test/build
####
#### Running command: "make -j4 -l4" in "/home/.../ros_workspace_test/build"
####
[ 14%] Automoc for target draw_on_images
[ 14%] Built target draw_on_images_automoc
Linking CXX executable /home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `int qmlRegisterType<Draw_on_qimage>(char const*, int, int, char const*)':
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x38): undefined reference to `Draw_on_qimage::staticMetaObject'
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x1b6): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Draw_on_qimage::~Draw_on_qimage()':
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x13): undefined reference to `vtable for Draw_on_qimage'
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x25): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QMetaTypeIdQObject<Draw_on_qimage*, true>::qt_metatype_id()':
main.cpp:(.text._ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv[_ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv]+0x2c): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QtPrivate::MetaObjectForType<Draw_on_qimage*, true>::value()':
main.cpp:(.text._ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv[_ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv]+0x7): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `Draw_on_qimage::metaObject() const'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x18): undefined reference to `Draw_on_qimage::qt_metacast(char const*)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x20): undefined reference to `Draw_on_qimage::qt_metacall(QMetaObject::Call, int, void**)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `typeinfo for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Provide_QPixmap_to_QML::~Provide_QPixmap_to_QML()':
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x13): undefined reference to `vtable for Provide_QPixmap_to_QML'
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x25): undefined reference to `vtable for Provide_QPixmap_to_QML'
CMakeFiles/draw_on_images.dir/src/draw_on_qimage.cpp.o: In function `Draw_on_qimage::Draw_on_qimage(QQuickPaintedItem*)':
draw_on_qimage.cpp:(.text+0x4b): undefined reference to `vtable for Draw_on_qimage'
draw_on_qimage.cpp:(.text+0x5d): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/provide_qpixmap_to_qml.cpp.o: In function `Provide_QPixmap_to_QML::Provide_QPixmap_to_QML()':
provide_qpixmap_to_qml.cpp:(.text+0x52): undefined reference to `vtable for Provide_QPixmap_to_QML'
provide_qpixmap_to_qml.cpp:(.text+0x64): undefined reference to `vtable for Provide_QPixmap_to_QML'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images] Error 1
make[1]: *** [draw_on_images/CMakeFiles/draw_on_images.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
How to link Qt 5.9 in ROS?
I am using Ubuntu 14.
Solution was to add the header files to add_executable in CMakelists.txt:
add_executable(${PROJECT_NAME} ${RESOURCES}
src/main.cpp
include/draw_on_images/draw_on_qimage.h src/draw_on_qimage.cpp
include/draw_on_images/provide_qpixmap_to_qml.h src/provide_qpixmap_to_qml.cpp)
My guess is that CMake's AUTOMOC fails in this case. See the documentation here https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html
It asserts, that the header file of your class Draw_on_qimage is similarly named as the source file and is locatable by CMake.
You can avoid AUTOMOC by manually running moc on your header for your QObject-derived class like this
QT5_WRAP_CPP(MOC_SOURCES <path of header file of your class Draw_on_qimage>)
add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp ${MOC_SOURCES} src/provide_qpixmap_to_qml.cpp

Detect Sun Studio compiler and add platform libraries in CMakeList.txt?

Sun Studio 12.5 on Solaris 11.3. Solve one problem and move to the next... Building our project with CMake results the link error below.
I believe its a simple matter of detecting SunCC and adding -lnsl -lsocket to LDLIBS. However, the method to detect the SunCC compiler escapes me. I found an old post from 2006 that states (from Error detecting sun studio compiler under linux):
I am trying to use the sun studio compiler under linux and I am having a
terrible time getting past the cmake compiler tests.
AFAIK no one has tried CMake with this compiler before.... CMake is invoking the compiler assuming that it accepts the flags other Linux compilers (such as GNU and Intel) accept... You'll have to setup a platform file to configure this compiler.
I tried to use SunPro from CMake Compiler IDs, but it results in the same error shown below.
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
My question is, how do I detect the Sun Studio compiler in CMakeList.txt? Or how do I detect Solaris?
/opt/developerstudio12.5/bin/CC -DNDEBUG -g2 -O2 -D__SSE2__ -D__SSE3__ -D__SSSE3__
-D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ -D__RDRND__ -D__RDSEED__ -D__AVX__
-D__AVX2__ -D__BMI__ -D__BMI2__ -D__ADX__ -xarch=avx2_i
CMakeFiles/cryptest.dir/bench1.cpp.o CMakeFiles/cryptest.dir/bench2.cpp.o
CMakeFiles/cryptest.dir/test.cpp.o CMakeFiles/cryptest.dir/validat1.cpp.o
CMakeFiles/cryptest.dir/validat2.cpp.o CMakeFiles/cryptest.dir/validat3.cpp.o
CMakeFiles/cryptest.dir/datatest.cpp.o CMakeFiles/cryptest.dir/regtest.cpp.o
CMakeFiles/cryptest.dir/fipsalgt.cpp.o CMakeFiles/cryptest.dir/dlltest.cpp.o
CMakeFiles/cryptest.dir/fipstest.cpp.o -o cryptest.exe libcryptopp.a
Undefined first referenced
symbol in file
bind libcryptopp.a(socketft.cpp.o)
recv libcryptopp.a(socketft.cpp.o)
send libcryptopp.a(socketft.cpp.o)
getservbyname libcryptopp.a(socketft.cpp.o)
getsockname libcryptopp.a(socketft.cpp.o)
accept libcryptopp.a(socketft.cpp.o)
listen libcryptopp.a(socketft.cpp.o)
gethostbyname libcryptopp.a(socketft.cpp.o)
socket libcryptopp.a(socketft.cpp.o)
setsockopt CMakeFiles/cryptest.dir/test.cpp.o
connect libcryptopp.a(socketft.cpp.o)
getpeername libcryptopp.a(socketft.cpp.o)
inet_addr libcryptopp.a(socketft.cpp.o)
shutdown libcryptopp.a(socketft.cpp.o)
ld: fatal: symbol referencing errors
gmake[2]: *** [cryptest.exe] Error 2
gmake[2]: Leaving directory `/export/home/cryptopp-build'
gmake[1]: *** [CMakeFiles/cryptest.dir/all] Error 2
gmake[1]: Leaving directory `/export/home/cryptopp-build'
gmake: *** [all] Error 2
Here's the CMakeList.tx file. It has not been checked in yet, so I have to dump it here:
$ cat CMakeLists.txt
# Please ensure your changes or patch meets minimum requirements.
# The minimum requirements are below, and they are 2.8.5. Please
# do not check in something for 2.8.12. To test your changes,
# please set up a Ubuntu 12.04 LTS system. Then, manually install
# CMake 2.8.5 from http://cmake.org/Wiki/CMake_Released_Versions.
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
project(cryptopp)
set(cryptopp_VERSION_MAJOR 5)
set(cryptopp_VERSION_MINOR 6)
set(cryptopp_VERSION_PATCH 5)
include(GNUInstallDirs)
include(TestBigEndian)
#============================================================================
# Settable options
#============================================================================
option(BUILD_STATIC "Build static library" ON)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_TESTING "Build library tests" ON)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory")
#============================================================================
# Internal compiler options
#============================================================================
# Don't use RPATH's. The resulting binary could fail a security audit.
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
set(CMAKE_MACOSX_RPATH 0)
endif()
set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH})
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180)
endif()
# Endianess
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
add_definitions(-DIS_BIG_ENDIAN)
endif()
if(DISABLE_ASM)
add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif()
if(DISABLE_SSSE3)
add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
endif()
if(DISABLE_AESNI)
add_definitions(-DCRYPTOPP_DISABLE_AESNI)
endif()
if(NOT CRYPTOPP_DATA_DIR STREQUAL "")
add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}")
endif()
if(WINDOWS_STORE OR WINDOWS_PHONE)
if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" )
endif()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" )
endif()
#============================================================================
# Sources & headers
#============================================================================
# Library headers
file(GLOB cryptopp_HEADERS *.h)
# Test sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES_TEST bench1.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp)
# Library sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES *.cpp)
list(REMOVE_ITEM cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/simple.cpp
${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib_bds.cpp
${cryptopp_SOURCES_TEST}
)
set(cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${cryptopp_SOURCES}
)
if(MINGW OR WIN32)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp)
endif()
if(MSVC AND NOT DISABLE_ASM)
if(${CMAKE_GENERATOR} MATCHES ".*ARM")
message(STATUS "Disabling ASM because ARM is specified as target platform.")
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
else()
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
endif()
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm)
enable_language(ASM_MASM)
endif()
endif()
#============================================================================
# Compile targets
#============================================================================
# Set global includes BEFORE adding any targets for legacy CMake versions
if(CMAKE_VERSION VERSION_LESS 2.8.12)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-object OBJECT ${cryptopp_SOURCES})
endif()
if (BUILD_STATIC)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-static STATIC $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-static STATIC ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
if (BUILD_SHARED)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-shared SHARED $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-shared SHARED ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-shared PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
# Set PIC
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# Enables -fPIC on all 64-bit platforms
if(NOT CMAKE_VERSION VERSION_LESS 2.8.9) # POSITION_INDEPENDENT_CODE support
set_target_properties(cryptopp-object PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
elseif(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # Object library support
get_target_property(flags_old cryptopp-object COMPILE_FLAGS)
set_target_properties(cryptopp-object PROPERTIES COMPILE_FLAGS "${flags_old} -fPIC")
else()
if (BUILD_STATIC)
get_target_property(flags_old_static cryptopp-static COMPILE_FLAGS)
if(NOT flags_old_static)
set(flags_old_static "")
endif()
set_target_properties(cryptopp-static PROPERTIES COMPILE_FLAGS "${flags_old_static} -fPIC")
endif()
if (BUILD_SHARED)
get_target_property(flags_old_shared cryptopp-shared COMPILE_FLAGS)
if(NOT flags_old_shared)
set(flags_old_shared "")
endif()
set_target_properties(cryptopp-shared PROPERTIES COMPILE_FLAGS "${flags_old_shared} -fPIC")
endif()
endif()
endif()
# Set filenames for targets to be "cryptopp"
if(NOT MSVC)
set(COMPAT_VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR})
if (BUILD_STATIC)
set_target_properties(cryptopp-static
PROPERTIES
OUTPUT_NAME cryptopp)
endif()
if (BUILD_SHARED)
set_target_properties(cryptopp-shared
PROPERTIES
SOVERSION ${COMPAT_VERSION}
OUTPUT_NAME cryptopp)
endif()
endif()
# Targets, compatible with Crypto++ GNUMakefile
if (BUILD_STATIC)
add_custom_target(static)
add_dependencies(static cryptopp-static)
endif()
if (BUILD_SHARED)
add_custom_target(dynamic)
add_dependencies(dynamic cryptopp-shared)
endif()
#============================================================================
# Third-party libraries
#============================================================================
if(WIN32)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ws2_32)
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ws2_32)
endif()
endif()
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
find_package(Threads)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ${CMAKE_THREAD_LIBS_INIT})
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ${CMAKE_THREAD_LIBS_INIT})
endif()
#============================================================================
# Tests
#============================================================================
enable_testing()
if(BUILD_TESTING)
add_executable(cryptest ${cryptopp_SOURCES_TEST})
target_link_libraries(cryptest cryptopp-static)
# Setting "cryptest" binary name to "cryptest.exe"
if(NOT WIN32)
set_target_properties(cryptest PROPERTIES OUTPUT_NAME cryptest.exe)
endif()
if(NOT TARGET cryptest.exe)
add_custom_target(cryptest.exe)
add_dependencies(cryptest.exe cryptest)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${PROJECT_BINARY_DIR})
add_test(NAME build_cryptest COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target cryptest)
add_test(NAME cryptest COMMAND $<TARGET_FILE:cryptest> v)
set_tests_properties(cryptest PROPERTIES DEPENDS build_cryptest)
endif()
#============================================================================
# Doxygen documentation
#============================================================================
if(BUILD_DOCUMENTATION)
find_package(Doxygen REQUIRED)
set(in_source_DOCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/html-docs")
set(out_source_DOCS_DIR "${PROJECT_BINARY_DIR}/html-docs")
add_custom_target(docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
)
if(NOT ${in_source_DOCS_DIR} STREQUAL ${out_source_DOCS_DIR})
add_custom_command(
TARGET docs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${in_source_DOCS_DIR}" "${out_source_DOCS_DIR}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${in_source_DOCS_DIR}"
)
endif()
endif()
#============================================================================
# Install
#============================================================================
set(export_name "cryptopp-targets")
# Runtime package
if (BUILD_SHARED)
install(
TARGETS cryptopp-shared
EXPORT ${export_name}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
# Development package
if (BUILD_STATIC)
install(TARGETS cryptopp-static EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${cryptopp_HEADERS} DESTINATION include/cryptopp)
# CMake Package
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # CMakePackageConfigHelpers is supported from 2.8.8
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake" VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}.${cryptopp_VERSION_PATCH} COMPATIBILITY SameMajorVersion)
install(FILES cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp")
install(EXPORT ${export_name} DESTINATION "lib/cmake/cryptopp")
endif()
# Tests
if(BUILD_TESTING)
install(TARGETS cryptest DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
endif()
# Documentation
if(BUILD_DOCUMENTATION)
install(DIRECTORY "${out_source_DOCS_DIR}" DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()