| 1 |
# CMAKE File for "MyApp" application building against an installed Trilinos |
| 2 |
|
| 3 |
#This file was created by modifiying the files in |
| 4 |
#Trilinos/demos/buildAgaintsTrilinos. The primary change was to make it a single |
| 5 |
#file cmake system in a flat directory. If you would like to run a cmake |
| 6 |
#configure using this file you should grab this file and src_file.cpp, |
| 7 |
#src_file.hpp, main_file.cpp from buildAgainstTrilinos and place them in a new |
| 8 |
#directory. From there you can run: |
| 9 |
#"cmake -DMYAPP_TRILINOS_DIR=<path to trilinos>." to configure. Another |
| 10 |
#important change is the buildAgainstTrilinos does some checking to see which |
| 11 |
#packages and tpls are enabled and behaves accordingly. However, this file does |
| 12 |
#only a serial configure(no mpi) and assumes that the install of Trilinos it is |
| 13 |
#pointed to has Epetra enabled. |
| 14 |
|
| 15 |
cmake_minimum_required(VERSION 2.8) |
| 16 |
|
| 17 |
# Error check up front |
| 18 |
IF (NOT DEFINED MYAPP_TRILINOS_DIR) |
| 19 |
MESSAGE(FATAL_ERROR "\nMyApp Error: cmake must define MYAPP_TRILINOS_DIR: |
| 20 |
(-D MYAPP_TRILINOS_DIR:FILEPATH=<trilinos_install_prefix>)!") |
| 21 |
ENDIF() |
| 22 |
|
| 23 |
# Get Trilinos as one entity |
| 24 |
FIND_PACKAGE(Trilinos PATHS ${MYAPP_TRILINOS_DIR}/include) |
| 25 |
|
| 26 |
IF(NOT Trilinos_FOUND) |
| 27 |
MESSAGE(FATAL_ERROR "Could not find Trilinos!") |
| 28 |
ENDIF() |
| 29 |
|
| 30 |
# Echo trilinos build info just for fun |
| 31 |
MESSAGE("\nFound Trilinos! Here are the details: ") |
| 32 |
MESSAGE(" Trilinos_DIR = ${Trilinos_DIR}") |
| 33 |
MESSAGE(" Trilinos_VERSION = ${Trilinos_VERSION}") |
| 34 |
MESSAGE(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}") |
| 35 |
MESSAGE(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES}") |
| 36 |
MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}") |
| 37 |
MESSAGE(" Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}") |
| 38 |
MESSAGE(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}") |
| 39 |
MESSAGE(" Trilinos_TPL_INCLUDE_DIRS = ${Trilinos_TPL_INCLUDE_DIRS}") |
| 40 |
MESSAGE(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}") |
| 41 |
MESSAGE(" Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}") |
| 42 |
MESSAGE(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}") |
| 43 |
MESSAGE("End of Trilinos details\n") |
| 44 |
|
| 45 |
# Make sure to use same compilers and flags as Trilinos |
| 46 |
SET(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} ) |
| 47 |
SET(CMAKE_C_COMPILER ${Trilinos_C_COMPILER} ) |
| 48 |
SET(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} ) |
| 49 |
|
| 50 |
SET(CMAKE_CXX_FLAGS "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") |
| 51 |
SET(CMAKE_C_FLAGS "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") |
| 52 |
SET(CMAKE_Fortran_FLAGS "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}") |
| 53 |
|
| 54 |
# |
| 55 |
# End of setup and error checking |
| 56 |
# NOTE: PROJECT command checks for compilers, so this statement |
| 57 |
# is moved AFTER setting CMAKE_CXX_COMPILER from Trilinos |
| 58 |
|
| 59 |
PROJECT(MyApp) |
| 60 |
|
| 61 |
ADD_DEFINITIONS(-DMYAPP_EPETRA) |
| 62 |
|
| 63 |
INCLUDE_DIRECTORIES(${Trilinos_INCLUDE_DIRS} ${Trilinos_TPL_INCLUDE_DIRS}) |
| 64 |
LINK_DIRECTORIES(${Trilinos_LIBRARY_DIRS} ${Trilinos_TPL_LIBRARY_DIRS}) |
| 65 |
|
| 66 |
ADD_LIBRARY(myappLib src_file.cpp src_file.hpp) |
| 67 |
|
| 68 |
ADD_EXECUTABLE(MyApp.exe main_file.cpp) |
| 69 |
|
| 70 |
TARGET_LINK_LIBRARIES(MyApp.exe myappLib ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES}) |
| 71 |
|
| 72 |
enable_testing() |
| 73 |
add_test(NAME MyTest COMMAND MyApp.exe) |
| 74 |
|