[Trilinos-Users] Linking path to Trilinos?

Sensei senseiwa at gmail.com
Thu Jun 9 09:09:34 MDT 2011


Hi all! This might be a stupid question, but here it is: how do I tell CMake to add the Trilinos library path to the linking stage?

I am trying to modify the sample makefile, and until now I've succeeded in finding libraries and setting the linking option, except the library path. In fact, it adds the various -llibraryname, but alas, no -L/path/to/trilinos/libs. 

Thanks for helping!

Cheers!




# CMAKE File for "MyApp" application building against an installed Trilinos

CMAKE_MINIMUM_REQUIRED(VERSION 2.7)

# Get Trilinos as one entity
FIND_PACKAGE(Trilinos PATHS ${TRILINOSDIR}/include)

IF(NOT Trilinos_FOUND)
  MESSAGE(FATAL_ERROR "Could not find Trilinos!")
ENDIF()

# Echo trilinos build info just for fun
MESSAGE("\nFound Trilinos!  Here are the details: \n")
MESSAGE("   Trilinos_DIR = ${Trilinos_DIR}\n")
MESSAGE("   Trilinos_VERSION = ${Trilinos_VERSION}\n")
MESSAGE("   Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}\n")
MESSAGE("   Trilinos_LIBRARIES = ${Trilinos_LIBRARIES}\n")
MESSAGE("   Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}\n")
MESSAGE("   Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}\n")
MESSAGE("   Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}\n")
MESSAGE("   Trilinos_TPL_INCLUDE_DIRS = ${Trilinos_TPL_INCLUDE_DIRS}\n")
MESSAGE("   Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}\n")
MESSAGE("   Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}\n")
MESSAGE("   Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}\n")
MESSAGE("End of Trilinos details\n")

# Make sure to use same compilers and flags as Trilinos
SET(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} )
SET(CMAKE_C_COMPILER ${Trilinos_C_COMPILER} )
SET(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} )

SET(CMAKE_CXX_FLAGS "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS} -I ${Trilinos_INCLUDE_DIRS}")
SET(CMAKE_C_FLAGS  "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_Fortran_FLAGS  "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}")

#
# End of setup and error checking
#  NOTE: PROJECT command checks for compilers, so this statement
#        is moved AFTER setting CMAKE_CXX_COMPILER from Trilinos

PROJECT(TestTrilinos)

# MPI check 
LIST(FIND Trilinos_TPL_LIST MPI MPI_List_ID)
IF (MPI_List_ID GREATER -1)
  MESSAGE("-- Checking if MPI is enabled in Trilinos: MPI ENABLED")
  SET(MYAPP_MPI TRUE)
  ADD_DEFINITIONS(-DMYAPP_MPI)
ELSE()
  MESSAGE("-- Checking if MPI is enabled in Trilinos: MPI NOT ENABLED")
  SET(MYAPP_MPI FALSE)
ENDIF()

SET(CMAKE_VERBOSE_MAKEFILE TRUE)

# Compile source code
ADD_EXECUTABLE(ex1.exe src/ex1.cpp)

# Link libraries
TARGET_LINK_LIBRARIES(ex1.exe ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})

# ADD LIBRARY PATHS
LINK_DIRECTORIES("${Trilinos_LIBRARY_DIRS}")





More information about the Trilinos-Users mailing list