Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  03 Sep 2009, Exaos Lee, Suggestion, Building MIDAS using CMake cmake.zip
    Reply  03 Sep 2009, Exaos Lee, Suggestion, Some screenshot using CMake with MIDAS Screenshot-11.pngScreenshot-13.png
    Reply  06 Sep 2009, Exaos Lee, Suggestion, Updated "CMakeLists.txt" CMakeLists.txt
Message ID: 638     Entry time: 06 Sep 2009     In reply to: 629
Author: Exaos Lee 
Topic: Suggestion 
Subject: Updated "CMakeLists.txt" 
Add installation commands. Please see the attachment.
Attachment 1: CMakeLists.txt  8 kB  | Hide | Hide all
#-*- mode: cmake -*-

## CMake pre-settings
cmake_minimum_required(VERSION 2.6)
cmake_policy(VERSION 2.6)
cmake_policy(SET CMP0011 NEW)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

## Project setup
project(MIDAS)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH    ${PROJECT_BINARY_DIR}/lib)
enable_language(C)
enable_language(CXX)

## Include utilities and options
# Find mxml
include(FindMXML)
include_directories(include ${MXML_PATH})

# OS specific flags
# OS-related CMake variables:
#  1. OS_EXTRA_UTILS   --- Extra utilities for specific OS
#  2. OS_EXTRA_LDFLAGS --- Extra link flags for specific OS
#  3. OS_EXTRA_DEFS    --- Extra definitions for specific OS
#  4. Other flags switched on for specific OS
include(OSflags)

include(FindROOT)  # Find ROOT environment
include(FindMySQL) # Find MySQL
include(FindODBC)  # Find ODBC
include(FindZLIB)  # Find zlib

## Options for MIDAS
set(NEED_CERNLIB TRUE)  # Need CERNLIB or not?
set(NEED_SHLIB   TRUE)  # Need shared library?
set(NEED_ROOT    TRUE)  # Need root?
set(NEED_FTPLIB  TRUE)  # Need ftp protocol?
#set(NEED_STRLCPY TRUE)  # Need strlcpy.h? -- maybe opened in OSflags.cmake
#set(MIDAS_MAX_EVENT_SIZE 1000000)  # maxmimum event size = ?

##############################################################################
## Setup options

## OS-specific
add_definitions(${OS_EXTRA_DEFS})
set(LDFLAGS "${LDFLAGS} ${OS_EXTRA_LDFLAGS}")
set(EXTRA_UTILS ${EXTRA_UTILS} ${OS_EXTRA_UTILS})

## Midas max event size
if(MIDAS_MAX_EVENT_SIZE)
  add_definitions(-DMAX_EVENT_SIZE=${MIDAS_MAX_EVENT_SIZE})
endif(MIDAS_MAX_EVENT_SIZE)

## strlcpy in "MXML"?
if(NEED_STRLCPY)
  set(EXTRA_OBJS ${EXTRA_OBJS} strlcpy)
  add_definitions( -DHAVE_STRLCPY )
  message(STATUS "Using Stephen's own strlcpy()")
endif(NEED_STRLCPY)

## FTPLIB needed?
if(NEED_FTPLIB)
  set(FTPLIB ftplib)
  add_definitions(-DINCLUDE_FTPLIB)
  message(STATUS "Using ftplib (FTP library)")
endif(NEED_FTPLIB)

## ODBC: -lodbc or -liodbc
if(ODBC_FOUND)
  message(STATUS "Add ODBC-specified targets using ${ODBC_LIBRARY}")
  set(EXTRA_UTILS ${EXTRA_UTILS} mh2sql)
  add_definitions(-DHAVE_ODBC)
  set(LDFLAGS "${LDFLAGS} -l${ODBC_NAME}")
else(ODBC_FOUND)
  message(STATUS "ODBC not found!")
endif(ODBC_FOUND)

## ZLIB
if(ZLIB_FOUND)
  add_definitions(-DHAVE_ZLIB)
  set(LDFLAGS "${LDFLAGS} -lz")
endif(ZLIB_FOUND)

## ROOT
if(NEED_ROOT AND ROOT_FOUND)
  message(STATUS "Using ROOT at ${ROOTSYS}")

  if(NEED_RPATH)      # Add rpath ..
    set(ROOT_LIBS "${ROOT_LIBS} -Wl,-rpath,${ROOTSYS}/lib")
  endif(NEED_RPATH)

  ## libRoot.a: Static ROOT library
  if(NEED_LIBROOTA AND ROOT_LIBA)
    set(LDFLAGS "${LDFLAGS} ${ROOTSYS}/lib/libRoot.a -lssl -ldl -lcrypt")
    message(STATUS "Using statlic ROOT library: ${ROOT_LIBA}")
  endif(NEED_LIBROOTA AND ROOT_LIBA)
endif(NEED_ROOT AND ROOT_FOUND)

####### MIDAS library and objects #########################
## Objects needed to build the libmidas(.a,.so,..)

foreach(obj ${FTPLIB} midas system mrpc odb ybos history alarm elog)
  set(LIB_OBJS ${LIB_OBJS} src/${obj}.c)
endforeach(obj)
foreach(obj mxml ${EXTRA_OBJS})
  set(LIB_OBJS ${LIB_OBJS} ${MXML_PATH}/${obj}.c)
endforeach(obj)
if(ODBC_FOUND)
  set(LIB_OBJS ${LIB_OBJS} src/history_odbc.cxx)
endif(ODBC_FOUND)

## Library definition
## Add static lib
add_library(midas-static STATIC ${LIB_OBJS})
set_target_properties(midas-static PROPERTIES OUTPUT_NAME "midas")

if(NEED_SHLIB)  # Add shared lib
  add_library(midas-shared SHARED ${LIB_OBJS})
  set_target_properties(midas-shared PROPERTIES OUTPUT_NAME "midas")
endif(NEED_SHLIB)

########## Utilities ######################################

## Core Utilties
set(CORE_UTILS mserver mhttpd mlogger odbedit lazylogger)

add_executable(mserver    src/mserver.c)
add_executable(mlogger    src/mlogger.c)
add_executable(mhttpd     src/mhttpd.c  src/mgd.c )
add_executable(odbedit    src/odbedit.c src/cmdedit.c )
add_executable(lazylogger src/lazylogger.c)
foreach(exe ${CORE_UTILS})
  target_link_libraries(${exe} midas-static)
  set_target_properties(${exe} PROPERTIES LINK_FLAGS "${LDFLAGS}")
endforeach(exe)

set_target_properties( mhttpd PROPERTIES
  LINK_FLAGS "-lm ${LDFLAGS}" LINKER_LANGUAGE CXX )

## for mlogger --- It's BAD to name a CXX source using ".c" file extension !!!
set_target_properties( mlogger 
  PROPERTIES
  LINK_FLAGS "${MYSQL_LIBS} ${ROOT_LIBS} ${LDFLAGS}"
  LINKER_LANGUAGE CXX
  COMPILE_FLAGS "${ROOT_CFLAGS}" )
set_source_files_properties( src/mlogger.c  PROPERTIES LANGUAGE CXX )

## Utilities
set(UTILS mtape    mhist  mstat  mdump   mchart
  webpaw  odbhist  melog  mcnaf
  mhdump  mtransition # C++ codes
  ${EXTRA_UTILS}  )

foreach(exe mtape mhist mstat mdump melog mchart odbhist webpaw)
  add_executable(${exe} utils/${exe}.c)
endforeach(exe)
add_executable(mhdump  utils/mhdump.cxx)
add_executable(mcnaf   utils/mcnaf.c  drivers/camac/camacrpc.c)
add_executable(mtransition src/mtransition.cxx)

# optional utilities
if("${UTILS}" MATCHES "mh2sql")
  add_executable(mh2sql utils/mh2sql.cxx src/history_odbc.cxx )
endif("${UTILS}" MATCHES "mh2sql")
if("${UTILS}" MATCHES "mlxspeaker")
  add_executable(mlxspeaker utils/mlxspeaker.c)
endif("${UTILS}" MATCHES "mlxspeaker")
if("${UTILS}" MATCHES "dio")
  add_executable(dio utils/dio.c)
endif("${UTILS}" MATCHES "dio")

foreach(exe ${UTILS})
  add_dependencies(${exe} midas-static)
  target_link_libraries(${exe} midas-static)
  set_target_properties(${exe} PROPERTIES  LINK_FLAGS "${LDFLAGS}")
endforeach(exe)

## Scripts
set(SCRIPTS stripchart.tcl )   # TCL script

## Special targets

## for generating mfe.o
add_custom_command( OUTPUT mfe.o DEPENDS src/mfe.c
  COMMAND ${CMAKE_C_COMPILER}
  ARGS -I${CMAKE_SOURCE_DIR}/include -c ${CMAKE_SOURCE_DIR}/src/mfe.c
  WORKING_DIRECTORY lib )
add_custom_target(mfe ALL DEPENDS mfe.o)

## for generating mfe.o
add_custom_command( OUTPUT fal.o DEPENDS src/fal.c
  COMMAND ${CMAKE_C_COMPILER}
  ARGS -I${CMAKE_SOURCE_DIR}/include -Dextname -DMANA_LITE
  -c ${CMAKE_SOURCE_DIR}/src/fal.c
  WORKING_DIRECTORY lib )
add_custom_target(fal ALL DEPENDS fal.o)

## analyzer objects: mana.o
add_custom_command( OUTPUT mana.o DEPENDS src/mana.c
  COMMAND ${CMAKE_C_COMPILER}
  ARGS -I${CMAKE_SOURCE_DIR}/include -c ${CMAKE_SOURCE_DIR}/src/mana.c
  WORKING_DIRECTORY lib )
add_custom_target(mana ALL DEPENDS mana.o)

set(EXTRA_MOBJS mfe.o fal.o mana.o)

# rmana.o
if(NEED_ROOT)
  set(ARG_LIST "-DUSE_ROOT ${ROOT_CFLAGS} -I${CMAKE_SOURCE_DIR}/include -o rmana.o -c ${CMAKE_SOURCE_DIR}/src/mana.c")
  separate_arguments(ARG_LIST)
  add_custom_command( OUTPUT rmana.o DEPENDS src/mana.c
    COMMAND ${CMAKE_CXX_COMPILER}
    ARGS ${ARG_LIST} WORKING_DIRECTORY lib )
  add_custom_target(rmana ALL DEPENDS rmana.o )
  set(EXTRA_MOBJS ${EXTRA_MOBJS} rmana.o )
endif(NEED_ROOT)

## hmana.o
if(NEED_CERNLIB)
  add_custom_command( OUTPUT hmana.o DEPENDS src/mana.c
    COMMAND ${CMAKE_C_COMPILER}
    ARGS -I${CMAKE_SOURCE_DIR}/include -Dextname -DHAVE_HBOOK -o hmana.o
    -c ${CMAKE_SOURCE_DIR}/src/mana.c
    WORKING_DIRECTORY lib )
  add_custom_target(hmana ALL DEPENDS hmana.o)
  set(EXTRA_MOBJS ${EXTRA_MOBJS} hmana.o )
endif(NEED_CERNLIB)

##########  Drivers and modules ################################
#

##########  Examples ###########################################
#

##########  Installation########################################
#
## Library and objects (custom targets)
install(TARGETS midas-static ARCHIVE DESTINATION lib)
if(NEED_SHLIB)
  install(TARGETS midas-shared LIBRARY DESTINATION lib
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ GROUP_EXECUTE WORLD_EXECUTE WORLD_READ)
endif(NEED_SHLIB)

foreach(obj ${EXTRA_MOBJS})
  install(FILES ${PROJECT_BINARY_DIR}/lib/${obj} DESTINATION lib)
endforeach(obj)

## Core and extra utilities, scripts
install(TARGETS ${CORE_UTILS} ${UTILS}
  RUNTIME DESTINATION bin
  PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
  GROUP_READ GROUP_EXECUTE WORLD_EXECUTE WORLD_READ)
#install ${SCRIPTS}
foreach(script ${SCRIPTS})
  install(FILES utils/${script} DESTINATION bin
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ GROUP_EXECUTE WORLD_EXECUTE WORLD_READ)
endforeach(script)

## include, src, examples, drivers
# install(DIRECTORY include/ DESTINATION include/midas
#   FILES_MATCHING PATTERN "*.h")
# install(DIRECTORY src      DESTINATION share/midas)
# install(DIRECTORY examples DESTINATION share/midas)
# install(DIRECTORY drivers  DESTINATION share/midas)
install(DIRECTORY include/ DESTINATION include
  FILES_MATCHING PATTERN "*.h")
install(DIRECTORY src/      DESTINATION src)
install(DIRECTORY examples/ DESTINATION examples)
install(DIRECTORY drivers/  DESTINATION drivers)
ELOG V3.1.4-2e1708b5