Include these variables into cmake
cmake
Solution
The cleanest solution would be to create a `FindPAPI.cmake`. So, add to your project this file inside of a `cmake/`folder:
FindPAPI.cmake
# Try to find PAPI headers and libraries.
#
# Usage of this module as follows:
#
# find_package(PAPI)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# PAPI_PREFIX Set this variable to the root installation of
# libpapi if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# PAPI_FOUND System has PAPI libraries and headers
# PAPI_LIBRARIES The PAPI library
# PAPI_INCLUDE_DIRS The location of PAPI headers
find_path(PAPI_PREFIX
NAMES include/papi.h
)
find_library(PAPI_LIBRARIES
# Pick the static library first for easier run-time linking.
NAMES libpapi.a papi
HINTS ${PAPI_PREFIX}/lib ${HILTIDEPS}/lib
)
find_path(PAPI_INCLUDE_DIRS
NAMES papi.h
HINTS ${PAPI_PREFIX}/include ${HILTIDEPS}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PAPI DEFAULT_MSG
PAPI_LIBRARIES
PAPI_INCLUDE_DIRS
)
mark_as_advanced(
PAPI_PREFIX_DIRS
PAPI_LIBRARIES
PAPI_INCLUDE_DIRS
)
Then, modify your CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
set(PROJECT_NAME myproject)
project(${PROJECT_NAME})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(PAPI REQUIRED)
...
# Include directories
include_directories(${DOLFIN_INCLUDE_DIRS})
include_directories(SYSTEM ${DOLFIN_3RD_PARTY_INCLUDE_DIRS})
include_directories(${PAPI_INCLUDE_DIRS})
# Executable
add_executable(${PROJECT_NAME} main.cpp)
# Target libraries
target_link_libraries(${PROJECT_NAME} ${PAPI_LIBRARIES} ${DOLFIN_LIBRARIES})
I hope it resolves it! ;)
Problem
This scientific application I am using uses cmake to build its program. Attached is the CMakeLists.txt: ``` cmake_minimum_required(VERSION 2.8) set(PROJECT_NAME myproject) project(${PROJECT_NAME}) # Set verbose output while testing CMake #set(CMAKE_VERBOSE_MAKEFILE 1) # Set CMake behavior cmake_policy(SET CMP0004 OLD) # Get DOLFIN configuration data (DOLFINConfig.cmake must be in # DOLFIN_CMAKE_CONFIG_PATH) find_package(DOLFIN) # Need to get VTK config because VTK uses advanced VTK features which # mean it's not enough to just link to the DOLFIN target. See # http://www.vtk.org/pipermail/vtk-developers/2013-October/014402.html find_package(VTK HINTS ${VTK_DIR} $ENV{VTK_DIR} NO_MODULE QUIET) # Default build type (can be overridden by user) if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug MinSizeRel Release RelWithDebInfo." FORCE) endif() # Compiler definitions add_definitions(${DOLFIN_CXX_DEFINITIONS}) # Compiler flags set(CMAKE_CXX_FLAGS "${DOLFIN_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") # Include directories include_directories(${DOLFIN_INCLUDE_DIRS}) include_directories(SYSTEM ${DOLFIN_3RD_PARTY_INCLUDE_DIRS}) # Executable add_executable(${PROJECT_NAME} main.cpp) # Target libraries target_link_libraries(${PROJECT_NAME} ${DOLFIN_LIBRARIES}) ``` However, I need to include some additional compiler flags and libraries not included within DOLFIN. I need to incorporate this package called PAPI. On my system, the paths/environments are: ``` PAPI_LIBDIR=/project/cacds/apps/papi/5.4.0/lib PAPI_INCLUDE=/project/cacds/apps/papi/5.4.0/include PAPI_FLAG=-lpapi ``` Normally I would do something like this: ``` gcc -O3 -o -I myproject $(PAPI_LIBDIR) main.c -L $(PAPI_INCLUDE) $(PAPI_FLAG) ``` But again I need the additional DOLFIN libraries and third party packages. Pardon me if this is a silly or simple question, but how would I modify the above CMakeLists.txt? I am kind of new to cmake, so any help appreciated, thanks