forked from slaclab/rogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
200 lines (159 loc) · 5.8 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# ----------------------------------------------------------------------------
# Title : ROGUE CMAKE Control
# ----------------------------------------------------------------------------
# File : CMakeLists.txt
# Created : 2018-02-27
# ----------------------------------------------------------------------------
# This file is part of the rogue software package. It is subject to
# the license terms in the LICENSE.txt file found in the top-level directory
# of this distribution and at:
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
# No part of the rogue software package, including this file, may be
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
# ----------------------------------------------------------------------------
# Add support for building in conda environment
if (DEFINED ENV{CONDA_PREFIX})
set(CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX}")
endif()
# Check cmake version
cmake_minimum_required(VERSION 3.5)
include(InstallRequiredSystemLibraries)
# Project name
project (rogue)
# C/C++
enable_language(CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
# Set version from git tag
find_package(Git)
if (GIT_FOUND)
execute_process (
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
OUTPUT_VARIABLE ROGUE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "^v([0-9]+)\\.([0-9]+)" ROGUE_SOVER ${ROGUE_VERSION})
else()
message(FATAL_ERROR "Git is required to build rogue!")
endif()
#####################################
# Find python3
#####################################
set(DO_PYTHON 0)
find_package(PythonInterp 3.6)
if (PYTHONINTERP_FOUND)
find_package(PythonLibs 3.6)
if (PYTHONLIBS_FOUND)
set(DO_PYTHON 1)
endif()
endif()
#####################################
# Boost Configuration
#####################################
set(Boost_USE_MULTITHREADED ON)
# Boost may need help on SLAC machines
set(BOOST_ROOT:PATHNAME $ENV{BOOST_PATH})
# First try standard suffix for boost
if (DO_PYTHON)
find_package(Boost 1.58 COMPONENTS system thread python3)
endif()
# Next try Debian/Ubuntu suffix for boost
if ((NOT Boost_FOUND) AND DO_PYTHON)
find_package(Boost 1.58 COMPONENTS system thread python-py36)
endif()
# Next try Mac with homebrew boost/python36
if ((NOT Boost_FOUND) AND DO_PYTHON)
find_package(Boost 1.58 COMPONENTS system thread python36)
endif()
# Try without python
if (NOT Boost_FOUND)
set(DO_PYTHON 0)
find_package(Boost 1.58 COMPONENTS system thread)
endif()
# Nothing worked
if (NOT Boost_FOUND)
message(FATAL_ERROR "Failed to find boost libraries!")
endif()
#####################################
# Optional EPICS V3
#####################################
if(DO_PYTHON AND DEFINED ENV{EPICS_BASE})
set(DO_EPICS_V3 1)
set(EPICSV3_BASE_DIR $ENV{EPICS_BASE})
set(EPICSV3_LIB_DIR ${EPICSV3_BASE_DIR}/lib/rhel6-x86_64 )
set(EPICSV3_INCLUDES ${EPICSV3_BASE_DIR}/include
${EPICSV3_BASE_DIR}/include/compiler/gcc
${EPICSV3_BASE_DIR}/include/os/Linux)
set(EPICSV3_LIBRARIES ${EPICSV3_LIB_DIR}/libcas.so
${EPICSV3_LIB_DIR}/libca.so
${EPICSV3_LIB_DIR}/libCom.so
${EPICSV3_LIB_DIR}/libgdd.so )
else()
set(DO_EPICS_V3 0)
endif()
#####################################
# Setup build
#####################################
# Configuration File
configure_file (
${PROJECT_SOURCE_DIR}/include/rogue/RogueConfig.in
${PROJECT_BINARY_DIR}/RogueConfig.h
)
# Add include directories
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/drivers/include)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${EPICSV3_INCLUDES})
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
# Create rogue core library
add_library(rogue-core SHARED "")
# Find rogue core sources
add_subdirectory(src/rogue)
# Set output to TOP/lib
set_target_properties(rogue-core PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib
VERSION ${ROGUE_VERSION} SOVERSION ${ROGUE_SOVER})
# Link rogue core to boost, python and bzip
TARGET_LINK_LIBRARIES(rogue-core LINK_PUBLIC ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(rogue-core LINK_PUBLIC ${PYTHON_LIBRARIES})
TARGET_LINK_LIBRARIES(rogue-core LINK_PUBLIC ${EPICSV3_LIBRARIES})
TARGET_LINK_LIBRARIES(rogue-core LINK_PUBLIC bz2)
if (DO_PYTHON)
# Create rogue python library
add_library(rogue SHARED "")
# Find python package sources
add_subdirectory(src)
# Set output to TOP/python, remove lib prefix
set_target_properties(rogue PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/python)
set_target_properties(rogue PROPERTIES PREFIX "")
# Link to rogue core
TARGET_LINK_LIBRARIES(rogue LINK_PUBLIC rogue-core)
else()
add_definitions( -DNO_PYTHON )
endif()
# Setup configuration file
set(CONF_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include)
set(CONF_LIBRARIES ${PROJECT_SOURCE_DIR}/lib/librogue-core.so.${ROGUE_SOVER})
# Create the config file
configure_file(RogueConfig.cmake.in ${PROJECT_SOURCE_DIR}/lib/RogueConfig.cmake @ONLY)
message("")
message("----------------------------------------------------------------------")
message("-- Success!")
message("")
message("-- Rogue Version: ${ROGUE_VERSION}")
message("")
message("-- Found boost: ${Boost_INCLUDE_DIRS}")
message("")
if (DO_PYTHON)
message("-- Found python: ${PYTHON_LIBRARIES}")
else()
message("-- Compiling without python!")
endif()
message("")
if (DO_EPICS_V3)
message("-- Found EPICS V3: ${EPICSV3_BASE_DIR}")
else()
message("-- EPICS V3 not included!")
endif()
message("----------------------------------------------------------------------")
message("")