I want to analyze a C++ code in eclipse with GPROF.
I added the code that I want to analyze with "new -> Makefile Project with Existing Code" because I got it as open source from the Internet and now I want to profile it. I'm working with gprof and with eclipse for the first time.
My problem is, that when I go to "project -> properties -> C/C++ build -> settings" I don't see anything more than "Binary Parsers" and "Error Parsers". I can't add flags (e.g. -pg) for the Compiler and Linker. It might have something to do with the Makefile Project?!
(Unfortunately I can't add my screenshot because of to less reputation).
How can I use gprof now? Can I add flags to Compiler and Linker somewhere else?
Thank you!
aciams
EDIT:
The Makefile has been created with cmake. So I added -pg to every file that does not begin with "# CMAKE generated file: DO NOT EDIT!".
When I build the project again I find -pg in
# compile CXX with /usr/bin/c++
CXX_FLAGS = -O3 -DNDEBUG -Wall -g -pg
but when I run the program and search for a file named "gmon.out" nothing can be found. Do I have to set -pg to the Linker explicitly?
This is the important part of CMakeLists.txt:
project()
#set ( CMAKE_BUILD_TYPE Debug )
set ( CMAKE_BUILD_TYPE Release )
#set ( CMAKE_CXX_COMPILER "icpc" )
#set ( CMAKE_CXX_COMPILER "g++-4.2" )
add_definitions ( -Wall -g -pg)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_CXX_COMPILER} MATCHES "icpc")
set ( OPENMP_FLAG "-openmp" )
set ( OPENMP_LINK "-openmp" )
else()
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "-lgomp" )
endif(${CMAKE_CXX_COMPILER} MATCHES "icpc")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(${CMAKE_GENERATOR} MATCHES "Makefile")
find_package ( OpenMP REQUIRED )
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "-lgomp" )
#set ( APP_TYPE MACOSX_BUNDLE )
else()
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "" )
endif(${CMAKE_GENERATOR} MATCHES "Makefile")
else()
set ( OPENMP_FLAG "" )
set ( OPENMP_LINK "" )
endif()
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set ( CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
/sw
/opt
/opt/local
/Users/$ENV{USER}/Development
./include
./lib
)
include ( ${QT_USE_FILE} )
include_directories (
${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
set ( EXECUTABLE_OUTPUT_PATH build/release )
set_source_files_properties ( test.cpp test2.cpp
PROPERTIES COMPILE_FLAGS ${OPENMP_FLAG}
)
add_executable ( )
target_link_libraries ()
install ( )
Thanks!
Related
I have the following cmake file to download, build and install zlib:
cmake_minimum_required ( VERSION 2.8.7 )
include (ExternalProject)
if(UNIX)
# An external project for zlib
SET (GIT_URL https://github.com/madler/zlib.git)
SET (ZLIB_INSTALL ${CMAKE_CURRENT_BINARY_DIR})
SET (ZLIB_INCLUDE ${CMAKE_BINARY_DIR}/include/zlib)
SET (ZLIB_STATIC ${CMAKE_BINARY_DIR}/lib/libz.a )
ExternalProject_Add(zlib
PREFIX zlib
GIT_REPOSITORY ${GIT_URL}
INSTALL_DIR ${ZLIB_INSTALL}
PATCH_COMMAND ${CMAKE_COMMAND} -E remove <SOURCE_DIR>/zconf.h
BUILD_IN_SOURCE 1
PATCH_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --includedir=${ZLIB_INCLUDE}
)
SET (ZLIB_INCLUDE_DIR ${ZLIB_INSTALL}/include/zlib)
SET (ZLIB_LIBRARY "${ZLIB_INSTALL}")
ADD_LIBRARY (ZLIB_LIB STATIC IMPORTED DEPENDS zlib)
SET_TARGET_PROPERTIES (ZLIB_LIB PROPERTIES IMPORTED_LOCATION "${ZLIB_STATIC}")
endif(UNIX)
But this cmake file only install zlib. I want also install minizip. Minizip is "part of zlib". In the zlib repository has a directory that has minizip.
How can I also install minizip in the same cmake file? Is it possible?
The minizip is inside zlib repository:
- zlib
- contrib
- minizip
- ....
- ...
- ...
I have cmake file to install minizip:
cmake_minimum_required(VERSION 2.8)
project(minizip)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(BUILD_SHARED_LIBS OFF)
find_package (ZLIB REQUIRED)
if (ZLIB_FOUND)
set(ZLIB_LIBRARY ${CMAKE_BINARY_DIR}/ZLIB/src/ZLIB/contrib)
SET (minizip ${CMAKE_BINARY_DIR}/lib/minizip)
if(CMAKE_HOST_APPLE)
set(PLATFORM __APPLE__)
elseif(CMAKE_HOST_UNIX)
set(PLATFORM unix)
elseif(CMAKE_HOST_WIN32)
set(PLATFORM _WIN32)
else(CMAKE_HOST_APPLE)
message(FATAL_ERROR "Not supported Platform")
endif(CMAKE_HOST_APPLE)
add_definitions(-D${PLATFORM})
set(SOURCE
${ZLIB_LIBRARY}/minizip/ioapi.c
${ZLIB_LIBRARY}/minizip/miniunz.c
${ZLIB_LIBRARY}/minizip/minizip.c
${ZLIB_LIBRARY}/minizip/unzip.c
${ZLIB_LIBRARY}/minizip/zip.c
)
if(WIN32)
set(SOURCE ${SOURCE} ${ZLIB_LIBRARY}/minizip/iowin32.c)
endif(WIN32)
set(HEADERS
${ZLIB_LIBRARY}/minizip/crypt.h
${ZLIB_LIBRARY}/minizip/ioapi.h
${ZLIB_LIBRARY}/minizip/miniunz.h
${ZLIB_LIBRARY}/minizip/unzip.h
)
if(WIN32)
set(HEADERS ${HEADERS} ${ZLIB_LIBRARY}/minizip/iowin32.h)
endif(WIN32)
add_library(minizip ${SOURCE} ${HEADERS})
target_link_libraries(minizip PUBLIC "-static" ZLIB_STATIC)
add_dependencies ( minizip zlib)
install(
TARGETS minizip EXPORT minizip-exports
INCLUDES DESTINATION "include"
RUNTIME DESTINATION "bin"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
)
install(
FILES ${HEADERS}
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/include/minizip"
)
ADD_LIBRARY (MINIZIP_LIB STATIC IMPORTED DEPENDS minizip)
SET_TARGET_PROPERTIES (MINIZIP_LIB PROPERTIES IMPORTED_LOCATION ${minizip})
endif()
I want before install minizip, install zlib.
But when I run
cmake ..
I have the following error:
Make Error at modules/minizip.cmake:50 (add_library):
Cannot find source file:
/home/lais/Imagens/agent/build/ZLIB/src/ZLIB/contrib/minizip/ioapi.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:59 (include)
CMake Error: Cannot determine link language for target "minizip".
CMake Error: CMake can not determine linker language for target: minizip
And I have a top level cmake, that call for this two modules:
cmake_minimum_required( VERSION 2.8.7 )
project( project )
# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
# src : main + jsoncpp library
file ( GLOB SOURCES src/project/*.cpp )
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/project/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/project/linux/*.cpp )
endif ()
# src : curl requests
# options for cpr
# avoid experimental use of openssl
option( CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" OFF )
# avoid building tests
option( BUILD_CPR_TESTS "Set to ON to build cpr tests." OFF )
# options for curl
# avoid building tests
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF )
# avoid running tests - set ON again in download version or if errors occur
option( RUN_CURL_TESTS "Set to ON to run cURL tests." OFF )
add_subdirectory ( lib/cpr )
include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
endif ()
# headers
include_directories ( "include" )
include_directories ( "${CMAKE_BINARY_DIR}/include" )
# scr = libboost
include ( "modules/boost.cmake" )
# src = zlib
include ( "modules/zlib.cmake" )
# src = minizip
include ( "modules/minizip.cmake" )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB} ${ZLIB_STATIC} ${minizip})
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} zlib)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} minizip)
if ( WIN32 )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
# libudev
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()
Looks your source package is not complete.
minizip is just simple a single file minizip.c. Why do you need cmake? Just compile it and link with zlib and everything will be fine.
My question: in this moment I'm linking the libre2 dinamically, but I want to do this statically. I installed the library in my pc (sudo apt-get install libre2-dev), got the "binary" and linked this binary "libre2.so" in my executable. But I want to git clone the repository or to do this by git submodule, then build this repository and link it in my project statically.
I'm new here and sorry for my bad English rss'
1) my project structure
- bin
- build
- external
- re2
- main.cpp
- CMakeLists.txt
- README.md
2) CMakeLists.txt
cmake_minimum_required( VERSION 2.6 )
project( simmc-agent )
# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# src : main
file ( GLOB SOURCES *.cpp )
# linking res library dinamically
set(RE2_LIBRARIES -L${RE2_LIBRARY_DIR} -l libre2.so)
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp )
endif ()
# headers
include_directories ( "include" )
# test
option( PRINT_JSON "Set to ON to print json objects before sending" OFF )
message(STATUS "${PRINT_JSON}: ${${PRINT_JSON}}")
if ( PRINT_JSON )
add_definitions ( -DPRINT_JSON )
endif ()
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${RE2_LIBRARY} )
3) main.cpp
#include <iostream>
#include <re2/re2.h>
using namespace std;
using namespace re2;
int main (int argc, char **argv) {
cout << "hello world" << endl;
int matchResult;
matchResult = RE2::FullMatch("hello", "h.*o");
cout << "matchResult = " << matchResult << endl;
return 0;
}
EDIT - (26.01.17) : Hello, guys. I'm here to talk how I resolve it.
Following some tips gave here, I create a file called re2.cmake:
cmake_minimum_required ( VERSION 2.8.7 )
if (NOT RE2_NAME)
include (ExternalProject)
SET (RE2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/re2/src/re2/)
SET (RE2_EXTRA_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/re2/src/re2/)
SET (RE2_URL https://github.com/google/re2.git)
SET (RE2_BUILD ${CMAKE_BINARY_DIR}/re2/src/re2)
SET (RE2_LIBRARIES ${RE2_BUILD}/obj/so/libre2.so)
get_filename_component(RE2_STATIC_LIBRARIES ${RE2_BUILD}/libre2.a ABSOLUTE)
SET (RE2_INCLUDES ${RE2_BUILD})
if ( WIN32 )
SET (RE2_STATIC_LIBRARIES ${RE2_BUILD}/${CMAKE_BUILD_TYPE}/re2.lib)
else ()
SET (RE2_STATIC_LIBRARIES ${RE2_BUILD}/libre2.a)
endif ()
ExternalProject_Add(RE2
PREFIX RE2
GIT_REPOSITORY ${RE2_URL}
# GIT_TAG ${RE2_TAG}
DOWNLOAD_DIR "${DOWNLOAD_LOCATION}"
BUILD_IN_SOURCE 1
INSTALL_COMMAND sudo make install
CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
)
## put re2 includes in the directory where they are expected
add_custom_target(re2_create_destination_dir COMMAND ${CMAKE_COMMAND} -E make_directory ${RE2_INCLUDE_DIR}/re2 DEPENDS re2)
add_custom_target(re2_copy_headers_to_destination DEPENDS re2_create_destination_dir)
foreach(header_file ${RE2_HEADERS})
add_custom_command(TARGET re2_copy_headers_to_destination PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${header_file} ${RE2_INCLUDE_DIR}/re2)
endforeach ()
ADD_LIBRARY(RE2_LIB STATIC IMPORTED DEPENDS RE2)
SET_TARGET_PROPERTIES(RE2_LIB PROPERTIES IMPORTED_LOCATION ${RE2_STATIC_LIBRARIES})
endif (NOT RE2_NAME)
This file download the repository, building and install the library libre2 in my computer. This library has a dependency for Thread library* (I thinks all linux operation system come with this library).
But, has a problem: I only do this, if I'm a root user. Because the library used the "make install" command and to do it, you need to be a root user.
my project structure:
- bin
- build
- src
- include
- modules
- re2.cmake
- CMakeLists.txt
FOllowing my CMakeLists.txt:
cmake_minimum_required ( VERSION 2.8.7 )
project ( project C CXX)
# version number
SET ( VERSION_MAJOR 0 )
SET ( VERSION_MINOR 0 )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# src : main
file ( GLOB SOURCES src/main.cpp )
# headers
include_directories ( "include" )
# src : libre2 - Download, build and install the library
find_package (Threads)
include ( "modules/re2.cmake" )
set(RE2_STATIC_LIBRARIES -L${RE2_LIBRARY_DIR} -l libre2.a )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES})
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${RE2_STATIC_LIBRARIES})
add_dependencies(project-v${VERSION_MAJOR}.${VERSION_MINOR} RE2)
target_link_libraries (project-v${VERSION_MAJOR}.${VERSION_MINOR} ${CMAKE_THREAD_LIBS_INIT})
My new CmakeLists.txt
cmake_minimum_required( VERSION 2.8.7 )
project( simmc-agent )
# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# src : main
file ( GLOB SOURCES *.cpp )
# libre2
if (NOT RE2_NAME)
include (ExternalProject)
set(ABBREV "RE2")
set(EXT_PREFIX "external/re2" )
set(${ABBREV}_NAME ${ABBREV})
set(${ABBREV}_INCLUDE_DIRS ${EXT_PREFIX}/src/re2/)
set(APP_DEPENDENCIES ${APP_DEPENDENCIES} ${ABBREV})
message("Installing ${RE2_NAME} into ext build area: ${EXT_PREFIX} ...")
ExternalProject_Add(RE2
PREFIX ${EXT_PREFIX}
URL https://re2.googlecode.com/files/re2-20130115.tgz
URL_MD5 "ef66646926e6cb8f11f277b286eac579"
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND make
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
set(CXXFLAGS CMAKE_CXX_FLAGS)
set(${ABBREV}_LIBRARIES ${EXT_PREFIX}/src/RE2/obj/so/libre2.so)
set(${ABBREV}_STATIC_LIBRARIES ${EXT_PREFIX}/src/RE2/obj/libre2.a)
set_target_properties(${RE2_NAME} PROPERTIES EXCLUDE_FROM_ALL ON)
endif (NOT RE2_NAME)
if(RE2_INCLUDE_DIRS AND RE2_LIBRARIES)
set(RE2_FOUND TRUE)
endif(RE2_INCLUDE_DIRS AND RE2_LIBRARIES)
if(RE2_FOUND)
message(STATUS "Found RE2: ${RE2_LIBRARIES}")
else(RE2_FOUND)
message(FATAL_ERROR "Could not find RE2 library.")
endif(RE2_FOUND)
set(INCLUDES ${INCLUDES} ${RE2_INCLUDE_DIRS} )
# set(LIBS ${LIBS} ${RE2_STATIC_LIBRARIES} )
# headers
include_directories ( "include" )
# test
option( PRINT_JSON "Set to ON to print json objects before sending" OFF )
message(STATUS "${PRINT_JSON}: ${${PRINT_JSON}}")
if ( PRINT_JSON )
add_definitions ( -DPRINT_JSON )
endif ()
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${RE2_LIBRARIES})
I'm trying to build a project using CMake 3.4.0-rc3 on 64-bit Windows 8.
When I click "generate", I get an error saying:
Thing is, when I go to C:\MinGW\bin I do have a dll called libmpc-3.dll. By looking at a similar answer I tried running mingw-get install mpc which ran successfully but didn't fix the problem. Any advice? :)
EDIT: CMakeLists.txt
#
# Root vxl
#
# vxl-maintainers#lists.sf.net
CMAKE_MINIMUM_REQUIRED(VERSION 2.5)
# Support for CMake 2.6
IF( COMMAND CMAKE_POLICY )
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF( COMMAND CMAKE_POLICY )
# CMake 2.8 stuff
SET( CMAKE_LEGACY_CYGWIN_WIN32 0 ) # Remove when CMake >= 2.8.4 is required
# Use #rpath on OS X
IF( POLICY CMP0042 )
CMAKE_POLICY(SET CMP0042 NEW)
ENDIF()
PROJECT(vxl)
SET( LIBRARY_OUTPUT_PATH ${vxl_BINARY_DIR}/lib CACHE PATH
"Output directory for the vxl libraries" )
IF( NOT EXECUTABLE_OUTPUT_PATH )
SET( EXECUTABLE_OUTPUT_PATH "." )
ENDIF( NOT EXECUTABLE_OUTPUT_PATH )
# CMake support directory.
SET(VXL_CMAKE_DIR ${vxl_SOURCE_DIR}/config/cmake/Modules)
INCLUDE( ${VXL_CMAKE_DIR}/VXLStandardOptions.cmake )
INCLUDE( ${vxl_SOURCE_DIR}/config/cmake/config/vxl_utils.cmake )
# INCLUDE( ${vxl_SOURCE_DIR}/UseSTLPort.cmake )
INCLUDE(${vxl_SOURCE_DIR}/config/cmake/doxygen/doxygen.cmake)
# Copy the UseVXL.cmake file to the binary directory so that client
# projects don't need to find the source directory first. They can run
# the UseVXL.cmake from the vxl binary directory, and determine the
# vxl source directory by loading the cache.
CONFIGURE_FILE( ${VXL_CMAKE_DIR}/UseVXL.cmake
${vxl_BINARY_DIR}/UseVXL.cmake COPYONLY )
# Copy CTestCustom.cmake to top of build tree
CONFIGURE_FILE( ${VXL_CMAKE_DIR}/CTestCustom.cmake
${vxl_BINARY_DIR}/CTestCustom.cmake COPYONLY )
# Location of VXL's FindXXX.cmake CMake modules.
# This is identical to VXL_CMAKE_DIR. Perhaps we should eliminate MODULE_PATH?
SET( MODULE_PATH ${vxl_SOURCE_DIR}/config/cmake/Modules CACHE STATIC "VXL module path" )
# For use in client projects that call UseVXL.cmake
SET (VXL_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH} CACHE STATIC "Where all the vxl libraries are, for clients to use." )
# Options to add extra compiler and linker flags
#
# These options allow you to specify additional flags without
# affecting the default flags for a particular platform or build type.
# This is especially useful for adding extra warning flags.
SET( VXL_EXTRA_CMAKE_C_FLAGS CACHE STRING "Extra flags appended to CMAKE_C_FLAGS" )
SET( VXL_EXTRA_CMAKE_CXX_FLAGS CACHE STRING "Extra flags appended to CMAKE_CXX_FLAGS" )
SET( VXL_EXTRA_CMAKE_EXE_LINKER_FLAGS CACHE STRING "Extra flags appended to CMAKE_EXE_LINKER_FLAGS" )
SET( VXL_EXTRA_CMAKE_MODULE_LINKER_FLAGS CACHE STRING "Extra flags appended to CMAKE_MODULE_LINKER_FLAGS" )
SET( VXL_EXTRA_CMAKE_SHARED_LINKER_FLAGS CACHE STRING "Extra flags appended to CMAKE_SHARED_LINKER_FLAGS" )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VXL_EXTRA_CMAKE_C_FLAGS}" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VXL_EXTRA_CMAKE_CXX_FLAGS}" )
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${VXL_EXTRA_CMAKE_EXE_LINKER_FLAGS}" )
SET( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${VXL_EXTRA_CMAKE_MODULE_LINKER_FLAGS}" )
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${VXL_EXTRA_CMAKE_SHARED_LINKER_FLAGS}" )
# Option to specify whether this is a build for the dashboard. Each
# dashboard build should set BUILD_FOR_VXL_DASHBOARD to YES in the
# initial cache (set in the CTest script).
OPTION( BUILD_FOR_VXL_DASHBOARD "Is this a build for the dashboard?" NO )
# A variable to default some OPTIONs to YES for the dashboard, but to
# NO for other builds.
IF( BUILD_FOR_VXL_DASHBOARD )
SET( YES_FOR_DASHBOARD "YES" )
ELSE( BUILD_FOR_VXL_DASHBOARD )
SET( YES_FOR_DASHBOARD "NO" )
ENDIF( BUILD_FOR_VXL_DASHBOARD )
# Use this variable in vxl_config.h to tell if it is a shared build
set(VXL_BUILD_SHARED FALSE)
if(BUILD_SHARED_LIBS)
set(VXL_BUILD_SHARED TRUE)
endif()
# Do platform-specific configuration.
IF(NOT VXL_NO_CMAKE_CONFIGURE)
SUBDIRS(config/cmake/config)
ENDIF(NOT VXL_NO_CMAKE_CONFIGURE)
# Options to reduce build to just some core libraries
OPTION( BUILD_CORE_NUMERICS "Build VXL's numerics libraries" YES )
OPTION( BUILD_CORE_SERIALISATION "Build VXL's serialisation libraries" YES )
OPTION( BUILD_CORE_UTILITIES "Build VXL's utility libraries" YES )
OPTION( BUILD_CORE_GEOMETRY "Build VXL's geometry libraries" YES )
OPTION( BUILD_CORE_IMAGING "Build VXL's imaging libraries" YES )
OPTION( BUILD_NONDEPRECATED_ONLY "Build only nondeprecated libraries (Experimental)" NO )
IF(BUILD_CORE_NUMERICS)
IF( BUILD_FOR_VXL_DASHBOARD )
OPTION( BUILD_CORE_PROBABILITY "Build VXL's probability libraries (Experimental)" YES )
ELSE( BUILD_FOR_VXL_DASHBOARD )
OPTION( BUILD_CORE_PROBABILITY "Build VXL's probability libraries (Experimental)" NO )
ENDIF( BUILD_FOR_VXL_DASHBOARD )
ENDIF(BUILD_CORE_NUMERICS)
SET (BUILD_CORE_ALL OFF CACHE INTERNAL "All Core libraries are being built")
IF (BUILD_CORE_GEOMETRY AND BUILD_CORE_NUMERICS)
IF (BUILD_CORE_UTILITIES AND BUILD_CORE_SERIALISATION)
IF (BUILD_CORE_IMAGING)
SET (BUILD_CORE_ALL ON CACHE INTERNAL "All Core libraries are being built")
ENDIF (BUILD_CORE_IMAGING)
ENDIF (BUILD_CORE_UTILITIES AND BUILD_CORE_SERIALISATION)
ENDIF (BUILD_CORE_GEOMETRY AND BUILD_CORE_NUMERICS)
# Optionally use old error reporting methods, rather than exceptions.
# The main use is in vil which often uses/used null images to imply an error.
OPTION (VXL_LEGACY_ERROR_REPORTING "Use old error reporting methods rather than exceptions?" YES)
IF (VXL_LEGACY_ERROR_REPORTING)
ADD_DEFINITIONS( -DVXL_LEGACY_ERROR_REPORTING )
ENDIF (VXL_LEGACY_ERROR_REPORTING)
# Options to build no longer maintained libraries.
# It is still useful to have the dashboard check that they are correct,
# but no-one is likely to work on improving test coverage or fixing memory leaks.
OPTION( BUILD_UNMAINTAINED_LIBRARIES "Build libraries that are no longer actively maintained?" ${YES_FOR_DASHBOARD} )
# Option to build Windows Unicode support, the string
# type of which is wchar_t, each character is a 16-bit unsigned integer.
IF(WIN32)
IF(VXL_HAS_WIN_WCHAR_T)
OPTION( VXL_USE_WIN_WCHAR_T "Build overloading functions that accept Windows wide char strings?" YES )
IF(VXL_USE_WIN_WCHAR_T) # Force it to be 0/1
SET(VXL_USE_WIN_WCHAR_T 1)
ELSE(VXL_USE_WIN_WCHAR_T)
SET(VXL_USE_WIN_WCHAR_T 0)
ENDIF(VXL_USE_WIN_WCHAR_T)
ELSE(VXL_HAS_WIN_WCHAR_T)
SET(VXL_USE_WIN_WCHAR_T 0)
ENDIF(VXL_HAS_WIN_WCHAR_T)
ELSE(WIN32)
# avoid empty macro definition
SET(VXL_USE_WIN_WCHAR_T 0)
ENDIF(WIN32)
# In order to be able to link vxl libraries into shared libraries on 64 bit linux, the -fPIC
# compiler flag must be added. Only do this if we are on a x86_64 *nix platform, we're building
# static libraries, and the user has not explicitly requested position dependent code.
IF(UNIX)
IF(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
OPTION(BUILD_POSITION_DEPENDENT_CODE "Generate position dependent code (i.e. code cannot be used in shared library)" OFF)
MARK_AS_ADVANCED(BUILD_POSITION_DEPENDENT_CODE)
IF (NOT BUILD_POSITION_DEPENDENT_CODE)
message(STATUS "Adding -fPIC compiler flag to generate position independent code.")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-fPIC")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-fPIC")
ENDIF(NOT BUILD_POSITION_DEPENDENT_CODE)
ENDIF(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
ENDIF(UNIX)
# Build the core vxl + support libraries
SUBDIRS(vcl v3p core)
# Optionally build the contributed libraries
IF( EXISTS ${vxl_SOURCE_DIR}/contrib/CMakeLists.txt )
OPTION( BUILD_CONTRIB "Build the contributed libraries?" YES )
ENDIF( EXISTS ${vxl_SOURCE_DIR}/contrib/CMakeLists.txt )
IF( BUILD_CONTRIB AND BUILD_CORE_ALL)
SUBDIRS( contrib )
ENDIF( BUILD_CONTRIB AND BUILD_CORE_ALL)
# Use the old configure script if the cache tells us to do so.
IF(VXL_NO_CMAKE_CONFIGURE)
IF(RUN_CONFIGURE)
EXEC_PROGRAM( ${vxl_SOURCE_DIR}/configure
${vxl_BINARY_DIR} )
ENDIF(RUN_CONFIGURE)
ENDIF(VXL_NO_CMAKE_CONFIGURE)
# Some types of path names can cause havoc with regular expressions,
# so avoid those.
IF( ${vxl_BINARY_DIR} MATCHES \\+ )
MESSAGE(SEND_ERROR "You cannot have a + in your binary path")
ENDIF( ${vxl_BINARY_DIR} MATCHES \\+ )
IF( ${vxl_SOURCE_DIR} MATCHES \\+ )
MESSAGE(SEND_ERROR "You cannot have a + in your source path")
ENDIF( ${vxl_SOURCE_DIR} MATCHES \\+ )
# include CMakeListsLocal.txt from source directory if it exists
# also include it from the binary dir if different from source dir
IF( ${vxl_BINARY_DIR} MATCHES ${vxl_SOURCE_DIR} )
INCLUDE( ${vxl_SOURCE_DIR}/CMakeListsLocal.txt OPTIONAL )
ELSE( ${vxl_BINARY_DIR} MATCHES ${vxl_SOURCE_DIR} )
INCLUDE( ${vxl_SOURCE_DIR}/CMakeListsLocal.txt OPTIONAL )
INCLUDE( ${vxl_BINARY_DIR}/CMakeListsLocal.txt OPTIONAL )
ENDIF( ${vxl_BINARY_DIR} MATCHES ${vxl_SOURCE_DIR} )
# Standard include directories.
SET(VXLCORE_INCLUDE_DIR ${vxl_BINARY_DIR}/core ${vxl_SOURCE_DIR}/core)
SET(VXLCORE_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/vxl/core)
SET(VCL_INCLUDE_DIR ${vxl_BINARY_DIR}/vcl ${vxl_SOURCE_DIR}/vcl)
SET(VCL_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/vxl/vcl)
# Autoconf does not work on windows. Use hardcoded results if not using
# cmake to configure.
IF(VXL_NO_CMAKE_CONFIGURE)
IF(WIN32)
IF(NOT CYGWIN)
SET(VCL_INCLUDE_DIR ${vxl_SOURCE_DIR}/vcl/config.win32 ${VCL_INCLUDE_DIR})
SET(VCL_INSTALL_INCLUDE_DIR
${CMAKE_INSTALL_PREFIX}/include/vcl/config.win32
${VCL_INSTALL_INCLUDE_DIR}
)
ENDIF(NOT CYGWIN)
ENDIF(WIN32)
ENDIF(VXL_NO_CMAKE_CONFIGURE)
INCLUDE_DIRECTORIES(${VCL_INCLUDE_DIR} ${VXLCORE_INCLUDE_DIR})
# This SUBDIRS command must be the last SUBDIRS command in this file
SUBDIRS( config/cmake/export )
Now I am using CMake to create a VC 10 project. One issue I have found is that the path of the output library or execute program is connected with the project configuration (debug or release). In order to illustrate it, I give the following examples:
cmake_minimum_required( VERSION 2.6 )
project (test)
add_definitions (-DEXP_STL )
add_library(lib1 SHARED lib1.cxx)
set_target_properties(lib1 PROPERTIES LINK_INTERFACE_LIBRARIES "")
set(LIBRARY_OUTPUT_PATH ${test_SOURCE_DIR})
The last command in the script denote that I would like to put the output library (lib1) in the directory of ${test_SOURCE_DIR}. However, the output library is located in ${test_SOURCE_DIR}/Debug instead. I was wondering how I could make sure that the output library is exactly in the path I have set. Thanks!
BWT: The reason why I raise this question is because in the Linux development environmental the output library or execute program path is exactly the path you set with set(LIBRARY_OUTPUT_PATH ...) function. I want to have a consistent result.
This question is regarded as duplicated, and one possible solution is as follows:
if (WIN32)
set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/win/32)
elseif (CMAKE_COMPILER_IS_GNUCC)
set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/linux/32)
elseif(APPLE)
set(myoutputdirectory ${your_source_file_SOURCE_DIR}/output/mac/32)
endif (WIN32)
# set output parth
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${myoutputdirectory} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${myoutputdirectory} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${myoutputdirectory} )
# for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${myoutputdirectory} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
I have downloaded and installed libtar.
I have added the header file correctly ( #include <libtar.h> ).
I use KDevelop, which automatically recognizes the functions tar_append_tree and tar_open when I start typing them.
I use cmake with KDevelop (as an option when creating a new project), and so far everything that needed linking (pthreads,shared memory and math) all I had to do was add the appropriate flag in CMAKE_EXE_LINKER_FLAGS. I know that libtar needs -ltar in order to work, but I still get: undefined reference to tar_open , undefined reference to tar_append_tree.
Can anyone please help ? I am not aware of any other tar library, and I really need to organize thousands of xml files in a tarball prior to compressing.
edit: I have now found libarchive which is supposed to be much better than libtar. However I am missing something here. How do I explicitly tell KDevelop/Cmake how to link with those libraries ? There is no link flag for libarchive (at least not one I could find on google) and again when I try to compile I get undefined references to the imported functions.
Thank you!
I'm sure there is more than one solution, but here is mine. I created two files
FindLIBTAR.cmake in my project's folder under cmake/Modules/
libtar.pc in /usr/lib/pkgconfig
FindLIBTAR.cmake
# - Try to find LIBTAR
# Find LIBTAR headers, libraries and the answer to all questions.
#
# LIBTAR_FOUND True if libuuid got found
# LIBTAR_INCLUDE_DIRS Location of libuuid headers
# LIBTAR_LIBRARIES List of libraries to use libuuid
#
INCLUDE( FindPkgConfig )
IF ( LIBTAR_FIND_REQUIRED )
SET( _pkgconfig_REQUIRED "REQUIRED" )
ELSE ( LIBTAR_FIND_REQUIRED )
SET( _pkgconfig_REQUIRED "" )
ENDIF ( LIBTAR_FIND_REQUIRED )
IF ( LIBTAR_MIN_VERSION )
PKG_SEARCH_MODULE( LIBTAR ${_pkgconfig_REQUIRED} libtar>=${LIBTAR_MIN_VERSION} )
ELSE ( LIBTAR_MIN_VERSION )
PKG_SEARCH_MODULE( LIBTAR ${_pkgconfig_REQUIRED} libtar )
ENDIF ( LIBTAR_MIN_VERSION )
IF( NOT LIBTAR_FOUND AND NOT PKG_CONFIG_FOUND )
FIND_PATH( LIBTAR_INCLUDE_DIRS libtar.h )
FIND_LIBRARY( LIBTAR_LIBRARIES libtar)
# Report results
IF ( LIBTAR_LIBRARIES AND LIBTAR_INCLUDE_DIRS )
SET( LIBTAR_FOUND 1 )
IF ( NOT LIBTAR_FIND_QUIETLY )
MESSAGE( STATUS "Found libtar: ${LIBTAR_LIBRARIES}" )
ENDIF ( NOT LIBTAR_FIND_QUIETLY )
ELSE ( LIBTAR_LIBRARIES AND LIBTAR_INCLUDE_DIRS )
IF ( LIBTAR_FIND_REQUIRED )
MESSAGE( SEND_ERROR "Could NOT find libtar" )
ELSE ( LIBTAR_FIND_REQUIRED )
IF ( NOT LIBTAR_FIND_QUIETLY )
MESSAGE( STATUS "Could NOT find libtar" )
ENDIF ( NOT LIBTAR_FIND_QUIETLY )
ENDIF ( LIBTAR_FIND_REQUIRED )
ENDIF ( LIBTAR_LIBRARIES AND LIBTAR_INCLUDE_DIRS )
ENDIF( NOT LIBTAR_FOUND AND NOT PKG_CONFIG_FOUND )
MARK_AS_ADVANCED( LIBTAR_LIBRARIES LIBTAR_INCLUDE_DIRS )
libtar.pc
###########################################################################
# libtar installation details
###########################################################################
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: libtar
URL: http://www.feep.net/libtar/
Description: Library for Tar files
Version: 1.2.11-8
Libs: -L${libdir} -ltar -Wl,-Bsymbolic-functions -Wl,-z,relro
Libs.private:
Cflags: -I${includedir}
The FindLIBTAR.cmake uses pkgconfig to find the libtar library and libtar.pc is used by pkgconfig to find the library. You can place the cmake file in the same place where CMake places all find files (/usr/share/cmake/Modules/) if you don't want to put it in your project's directory. If you do keep it in your project's folder, you will need to add that to CMAKE_MODULE_PATH via:
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")