Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020 
<== Date ==> <== Thread ==>

Subject: cagateway: building with CMake, creating Debian/RPM packages
From: Martin Konrad <konrad@ikp.tu-darmstadt.de>
To: tech-talk@aps.anl.gov
Cc: Ralph.Lange@helmholtz-berlin.de
Date: Wed, 19 Oct 2011 01:34:02 +0200
Hello,
here are the files that are needed to build cagateway with CMake.

Up to now this has been tested for

linux-x86_64 (Ubuntu 11.04)
linux-x86 (Ubuntu 11.10)

Can anybody help testing this stuff with Solaris/Windows/<your OS here>?

@Ralph: Can you add these files to the cagateway repository please?

It's possible to build cagateway on Debian/Ubuntu against Michael
Davidsaver's Debian packages. Just make sure you have epics-pcas-dev
installed.

I still don't understand why casCtx.h is included by cagateway while it
is not installed into the include directory of base. To me this seems to
be a bug either in cagateway or base. Handling this situation becomes
more difficult with 3.15 because the file has been moved to another
directory in this revision. Can someone help to resolve this issue? Does
it make sense to add this file to the include directory in 3.15? This
would make the epics-pcas-dev package unnecessary for 3.15+, too.

Cheers

Martin

P.S.: The path to pcre.h was wrong on my machine (in gateAs.h) - this
works for me:
-#include <pcre/pcre.h>
+#include <pcre.h>

-- 
Dipl. Phys. Martin Konrad
Technische Universität Darmstadt
Institut für Kernphysik
Schlossgartenstr. 9
64289 Darmstadt
Tel.: +49-6151-16-5121
Fax: +49-6151-16-4321

# Find EPICS
#
# Use as:
#  FIND_PACKAGE(EPICS REQUIRED)
#
# To use a local version first set:
#  SET(CMAKE_MODULE_PATH "/somedir/epics/cmake")
#
# Creates variables:
#  EPICS_BASE           - Location
#
#  EPICS_FOUND          - Where all components found?
#  EPICS_INCLUDE_DIRS   - CPP search path (global and OS)
#
#  EPICS_Com_LIBRARIES  - libCom and dependencies
#  EPICS_*_LIBRARY      - Individual libs w/o dependencies
#  EPICS_HOST_LIBRARIES - All *Host libraries and cas/gdd
#  EPICS_IOC_LIBRARIES  - All *Ioc libraries
#
#  EPICS_INCLUDE_DIR
#  EPICS_OS_INCLUDE_DIR
#

# EPICS OS classes
#     AIX cygwin32 Darwin freebsd
#     hpux interix Linux osf RTEMS
#     solaris vxWorks WIN32

set(_EPICS_ALL_LIBS
  cas gdd asHost dbStaticHost registryIoc
  recIoc softDevIoc miscIoc rsrvIoc dbtoolsIoc asIoc
  dbIoc registryIoc dbStaticIoc ca Com
)

find_package(EPICSArch)

include(FindPackageHandleStandardArgs)

find_path(EPICS_BASE
  NAMES include/epicsVersion.h
        dbd/base.dbd
  PATHS /usr/lib/epics
        /opt/epics/current
  DOC "Location of EPICS Base"
)

if(NOT EPICS_BASE)
  if(EPICS_FIND_REQUIRED)
    message(FATAL_ERROR "Failed to find EPICS Base location")
  endif(EPICS_FIND_REQUIRED)
endif(NOT EPICS_BASE)

find_path(EPICS_INCLUDE_DIR epicsVersion.h
  PATHS ${EPICS_BASE}/include
  DOC "EPICS include dir"
  NO_DEFAULT_PATH
)

if(EPICS_INCLUDE_DIR)

  find_path(EPICS_OS_INCLUDE_DIR
    NAMES epicsMath.h osdTime.h osiUnistd.h
    PATHS ${EPICS_INCLUDE_DIR}/os/
    PATH_SUFFIXES ${OS_CLASS}
    DOC "EPICS OSD include dir"
    NO_DEFAULT_PATH
  )

  if(EPICS_OS_INCLUDE_DIR)
    SET(EPICS_INCLUDE_DIRS
      ${EPICS_INCLUDE_DIR}
      ${EPICS_OS_INCLUDE_DIR}
    )

  endif(EPICS_OS_INCLUDE_DIR)

endif(EPICS_INCLUDE_DIR)

if(EPICS_INCLUDE_DIR AND EPICS_OS_INCLUDE_DIR)

  foreach(COMP ${_EPICS_ALL_LIBS})
    find_library(EPICS_${COMP}_LIBRARY ${COMP}
      PATHS ${EPICS_BASE}/lib
      PATH_SUFFIXES ${T_A}
      NO_DEFAULT_PATH
      DOC "Location of the EPICS ${COMP} library"
    )

  endforeach(COMP)

endif(EPICS_INCLUDE_DIR AND EPICS_OS_INCLUDE_DIR)

# Ensure all components are present if needed
# When find_package() is invoked with REQUIRED
# ensure that all of the following are set
find_package_handle_standard_args(EPICS DEFAULT_MSG
  EPICS_BASE
  EPICS_INCLUDE_DIR EPICS_OS_INCLUDE_DIR
  EPICS_Com_LIBRARY
  EPICS_ca_LIBRARY
  EPICS_cas_LIBRARY
  EPICS_gdd_LIBRARY
  EPICS_asHost_LIBRARY
  EPICS_dbStaticHost_LIBRARY
  EPICS_registryIoc_LIBRARY
  EPICS_recIoc_LIBRARY
  EPICS_softDevIoc_LIBRARY
  EPICS_miscIoc_LIBRARY
  EPICS_rsrvIoc_LIBRARY
  EPICS_dbtoolsIoc_LIBRARY
  EPICS_asIoc_LIBRARY
  EPICS_dbIoc_LIBRARY
  EPICS_registryIoc_LIBRARY
  EPICS_dbStaticIoc_LIBRARY
)

set(EPICS_Com_LIBRARIES ${EPICS_Com_LIBRARY})

#TODO: error checking below

if(NOT RTEMS)
  find_package(Threads REQUIRED)
  list(APPEND EPICS_Com_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif(NOT RTEMS)

if(UNIX AND NOT RTEMS)
  find_library(LIBRT rt)
  find_library(LIBDL dl)
  list(APPEND EPICS_Com_LIBRARIES ${LIBRT} ${LIBDL})
endif(UNIX AND NOT RTEMS)

if(RTEMS)
  find_library(RTEMSCPU rtemscpu)
  find_library(RTEMSNFS nfs)
  list(APPEND EPICS_Com_LIBRARIES ${RTEMSCPU} ${RTEMSNFS})
  if(RTEMS_NEED_BSPEXT)
    find_library(BSPEXT bspExt)
    list(APPEND EPICS_Com_LIBRARIES ${BSPEXT})
  endif(RTEMS_NEED_BSPEXT)
endif(RTEMS)

# Libraries needed to build an IOC
set(EPICS_BASE_IOC_LIBS
  ${EPICS_recIoc_LIBRARY}
  ${EPICS_softDevIoc_LIBRARY}
  ${EPICS_miscIoc_LIBRARY}
  ${EPICS_rsrvIoc_LIBRARY}
  ${EPICS_dbtoolsIoc_LIBRARY}
  ${EPICS_asIoc_LIBRARY}
  ${EPICS_dbIoc_LIBRARY}
  ${EPICS_registryIoc_LIBRARY}
  ${EPICS_dbStaticIoc_LIBRARY}
  ${EPICS_ca_LIBRARY}
  ${EPICS_Com_LIBRARIES}
)

set(EPICS_INSTALL_BIN "bin/${T_A}" CACHE FILEPATH "Location for installed binaries")
set(EPICS_INSTALL_LIB "lib/${T_A}" CACHE FILEPATH "Location for all libraries")
set(EPICS_INSTALL_INCLUDE "include" CACHE FILEPATH "Location for C/C++ headers")
set(EPICS_INSTALL_INCLUDE_OS "include/os/${OS_CLASS}" CACHE FILEPATH "Location for OSD C/C++ Headers")
set(EPICS_INSTALL_DBD "dbd" CACHE FILEPATH "Location for EPICS DBD files")
set(EPICS_INSTALL_DB "db" CACHE FILEPATH "Location for EPICS DB files")

mark_as_advanced(
  EPICS_BIN_DIR EPICS_LIB_DIR
  EPICS_INCLUDE_DIR EPICS_OS_INCLUDE_DIR
  EPICS_DBD_DIR EPICS_DB_DIR
  EPICS_CMAKE_DIR
)

# Determine EPICS Arch and OS Class
#
# Use as:
#  find_package(EPICSArch)
#
# Creates variables:
#  T_A        - Target Archetecture
#  OS_CLASS   - Primary (first) OSI system class
#  OS_CLASSES - List of all OSI classes
#  IOC        - True if target can build IOC things
#  HOST       - True if target can build Host things
#

include(FindPackageMessage)

if(UNIX)
  if(CMAKE_SYSTEM_NAME MATCHES Linux)
    set(HOST 1)
    set(IOC 1)
    set(OS_CLASS Linux)
    set(OS_CLASSES Linux posix default)
    if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
      set(T_A "linux-x86")
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64$")
      set(T_A "linux-x86_64")
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc")
      set(T_A "linux-ppc")
    else(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
      message(FATAL_ERROR "Unknown Linux Variant: ${CMAKE_SYSTEM_PROCESSOR}")
    endif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")

  elseif(RTEMS)
    set(HOST 0)
    set(IOC 1)
    set(OS_CLASS RTEMS)
    set(OS_CLASSES RTEMS posix default)
    set(T_A "RTEMS-${RTEMS_BSP}")

  else(CMAKE_SYSTEM_NAME MATCHES Linux)
    message(FATAL_ERROR "Unknown *nix Variant: ${CMAKE_SYSTEM_NAME}")
  endif(CMAKE_SYSTEM_NAME MATCHES Linux)

elseif(WIN32)
  set(HOST 1)
  set(IOC 1)
  set(OS_CLASS WIN32)
  set(OS_CLASSES WIN32 default)
  if(MINGW)
    set(T_A "win32-x86-mingw")
  elseif(CYGWIN)
    set(T_A "win32-x86-cygwin")
  elseif(MSVC)
    set(T_A "win32-x86")
  elseif(BORLAND)
    set(T_A "win32-x86-borland")
  else(MINGW)
    message(FATAL_ERROR "Unknown Windows variant")
  endif(MINGW)

else(UNIX)
  message(FATAL_ERROR "Unable to determine EPICS OS class")
endif(UNIX)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(T_A "${T_A}-debug")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")

find_package_message(EPICSArch
   "EPICS Target: ${T_A} (${OS_CLASS})"
   "[${T_A}][${OS_CLASS}]"
)

# Martin Konrad <konrad@ikp.tu-darmstadt.de>
# License: GPLv2/v3
#
# Try to find libpcre (Perl Compatible Regular Expressions)
#
# Once done this will define
#
# PCRE_FOUND - system has libpcre
# PCRE_INCLUDE_DIR - the libpcre include directory
# PCRE_LIBRARY - where to find libpcre
# PCRE_LIBRARIES - Link these to use libpcre

if(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES)
	# in cache already
	set(LIBUSB_FOUND TRUE)
else(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES)
	if(NOT WIN32)
		# use pkg-config to get the directories and then use these values
		# in the FIND_PATH() and FIND_LIBRARY() calls
		find_package(PkgConfig)
		pkg_check_modules(PC_PCRE libpcre)
	endif(NOT WIN32)

	find_path(PCRE_INCLUDE_DIR
		NAMES
			pcre.h
		HINTS
			${PCRE_PKG_INCLUDE_DIRS}
		PATHS
			/usr/include
			/usr/local/include
	)

	find_library(PCRE_LIBRARY
		NAMES
			pcre
		HINTS
			${PCRE_PKG_LIBRARY_DIRS}
		PATHS
			/usr/lib
			/usr/local/lib
	)

	set(PCRE_LIBRARIES ${PCRE_LIBRARY})

	# handle the QUIETLY AND REQUIRED arguments AND set PCRE_FOUND to TRUE if
	# all listed variables are TRUE
	# include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
	include(FindPackageHandleStandardArgs)
	find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)

	mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARY)
endif(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES)

Using CMake instead of the classical EPICS build environment is recommended to build CA gateway.

BUILDING:
=========
To build cagateway using CMake run the following commands in the top level directory of CA gateway:

 mkdir build
 cd build/
 cmake ..
 make

If you want to change the defaults (e.g. use the perl compatible regular expression library) you can use either

 cmake -DUSE_PCRE ..

or you can use ccmake/cmake-gui to adjust the options in an interactive manner.


PACKAGING:
==========
After building the project you can create Debian and RPM packages by entering:

 make package

If you want only a deb file use

 cpack -G DEB

instead, if you only want a RPM file say

 cpack -G RPM

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(epics-cagateway)

set(VERSION_MAJOR 2)
set(VERSION_MINOR 0)
set(VERSION_MAINTENANCE 4)
set(VERSION_BUILD 0)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MAINTENANCE}.${VERSION_BUILD}")

set(gateway_SRCS
	gateway.cc
	gateAsCa.cc
	gateAs.cc
	gateAsyncIO.cc
	gatePv.cc
	gateResources.cc
	gateServer.cc
	gateStat.cc
	gateVc.cc
)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
find_package(EPICS REQUIRED ca cas asHost gdd Com)
include_directories(${EPICS_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "-Dlinux -O3 -Wall")

option(NODEBUG "Turn off Gateway debug calls" OFF)
if(NODEBUG)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNODEBUG")
endif(NODEBUG)

option(STAT_PVS "Use status PVs" ON)
if(STAT_PVS)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTAT_PVS")
endif(STAT_PVS)

option(RATE_STATS "Use rate statistics" ON)
if(RATE_STATS)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRATE_STATS")
endif(RATE_STATS)

option(CONTROL_PVS "Use control PV's" ON)
if(CONTROL_PVS)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCONTROL_PVS")
endif(CONTROL_PVS)

option(HEARTBEAT_PV "Use heartbeat PV" OFF)
if(HEARTBEAT_PV)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHEARTBEAT_PV")
endif(HEARTBEAT_PV)

option(CAS_DIAGNOSTICS "Use CAS diagnostics statistics" ON)
if(CAS_DIAGNOSTICS)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCAS_DIAGNOSTICS")
endif(CAS_DIAGNOSTICS)

option(HANDLE_EXCEPTIONS "Install exception handler and print exceptions to log file" ON)
if(CAS_DIAGNOSTICS)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCAS_DIAGNOSTICS")
endif(CAS_DIAGNOSTICS)

option(USE_DENYFROM "Use deny from" YES)
if(USE_DENYFROM)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_DENYFROM")
endif(USE_DENYFROM)

option(USE_NEG_REGEXP "Use neg regexp" ON)
if(USE_NEG_REGEXP)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_NEG_REGEXP")
endif(USE_NEG_REGEXP)

option(USE_PCRE "Use Perl compatible regular expressions" OFF)
if(USE_PCRE)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_PCRE")
	find_package(PCRE REQUIRED)
endif(USE_PCRE)

add_executable(gateway ${gateway_SRCS})
target_link_libraries(gateway ${EPICS_Com_LIBRARY} ${EPICS_HOST_LIBRARIES} ${EPICS_ca_LIBRARY} ${EPICS_asHost_LIBRARY} ${EPICS_cas_LIBRARY} ${EPICS_gdd_LIBRARY} ${PCRE_LIBRARIES})

# Package information
set(CPACK_PACKAGE_VERSION             ${VERSION_STRING})
set(CPACK_PACKAGE_CONTACT             "Martin Konrad <konrad@ikp.physik.tu-darmstadt.de>")
set(CPACK_PACKAGE_DESCRIPTION         "Channel access gateway for EPICS\n The Experimental Physics and Industrial Control System is a collection of tools, libraries and applications for creating a distributed soft real-time control system.\n .\n This package provides the EPICS channel access gateway. It acts as a kind of proxy for channel access and therefore allows clients to access IOCs in other subnets. In addition to that it provides channel access security.")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE     "http://www.aps.anl.gov/epics/extensions/gateway/";)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION  ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS      "libepics3.14.11 (>=3.14.11)")
if(USE_PCRE)
	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libpcre3")
endif(USE_PCRE)

# Package settings
if(${UNIX})
  set(CPACK_GENERATOR                 "DEB;RPM")
  set(CPACK_CMAKE_GENERATOR           "Unix Makefiles")
  set(CPACK_PACKAGE_NAME              ${PROJECT_NAME})
  set(CPACK_PACKAGE_FILE_NAME         ${PROJECT_NAME}-${VERSION_STRING}${PACK_ARCH})
endif(${UNIX})

install(TARGETS gateway DESTINATION bin)
install(DIRECTORY docs/ DESTINATION share/doc/${PROJECT_NAME} PATTERN ".svn" EXCLUDE)

include(CPack)

Replies:
Re: cagateway: building with CMake, creating Debian/RPM packages Ralph Lange

Navigate by Date:
Prev: EZCA and ezcaIDL improvements? Mark Rivers
Next: Re: cagateway: building with CMake, creating Debian/RPM packages Ralph Lange
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020 
Navigate by Thread:
Prev: RE: EZCA and ezcaIDL improvements? Mark Rivers
Next: Re: cagateway: building with CMake, creating Debian/RPM packages Ralph Lange
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·