forked from aprobinson/CMakeTutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
90 lines (73 loc) · 2.71 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Define the minimum required version of CMake
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
# set project directories
SET( PROJECT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
SET( PROJ_CLI_DIR ${PROJECT_SRC_DIR}/cli )
SET( PROJ_SRC_DIR ${PROJECT_SRC_DIR}/src )
SET( PROJ_TEST_DIR ${PROJECT_SRC_DIR}/test )
SET( PROJ_CMAKE_DIR ${PROJECT_SRC_DIR}/cmake )
# Tell CMake where the modules are
SET(
CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_DIR}/share/cmake-2.8/Modules"
${PROJ_CMAKE_DIR}
)
# Define the project name, no need to fully spell it out because it's now in the
# CMAKE_MODULE_PATH, which CMAKE queries for its INCLUDEs
INCLUDE(ProjectName)
# Define the project version
INCLUDE(Version)
# Include the macros that have been defined for this project
INCLUDE(Macros)
# This makes all the libraries build as SHARED
SET(BUILD_SHARED_LIBS true)
# Setup build locations.
IF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
endif()
IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
endif()
# Set the runtime install path
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Enforce an out-of-source build, no one should be building in the src dir!
ENFORCE_OUT_OF_SOURCE_BUILD()
# Add MPI support if requested
IF(${${PROJECT_NAME}_ENABLE_MPI})
SET(HAVE_${PROJECT_NAME}_MPI "1")
ENABLE_MPI_SUPPORT(${PROJECT_NAME}_LIBS)
ENDIF()
# Parse the MPI configure file so that it can be used in our source files
SET(CMAKEDEFINE \#cmakedefine)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/mpi_config.hpp.in
${CMAKE_BINARY_DIR}/${PROJECT_NAME}_mpi_config.hpp.in)
CONFIGURE_FILE(${CMAKE_BINARY_DIR}/${PROJECT_NAME}_mpi_config.hpp.in
${CMAKE_BINARY_DIR}/${PROJECT_NAME}_mpi_config.hpp)
# Add Design-by-Contract support if requested
IF(${${PROJECT_NAME}_ENABLE_DBC})
SET(HAVE_${PROJECT_NAME}_DBC "1")
ELSE(${${PROJECT_NAME}_ENABLE_DBC})
SET(HAVE_${PROJECT_NAME}_DBC "0")
ENDIF()
# Parse the DBC configure file so that is can be used in our source files
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/cmake/dbc_config.hpp.in
${CMAKE_BINARY_DIR}/${PROJECT_NAME}_dbc_config.hpp
)
# Add the CMAKE_BINARY_DIR to the include path to access config files
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
# Set up the project directory hierarchy
ADD_SUBDIRECTORY(${PROJ_SRC_DIR})
ADD_SUBDIRECTORY(${PROJ_CLI_DIR})
# Enable testing through CTest
ENABLE_TESTING()
ADD_SUBDIRECTORY(${PROJ_TEST_DIR})
CONFIGURE_FILE(
"${PROJ_CMAKE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
ADD_CUSTOM_TARGET(
uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)