OpenOffice CMake Integration

From Apache OpenOffice Wiki
Jump to: navigation, search

Overview

CMake is a cross-platform build system for build automation with support of popular programming languages including C++ and Java. Also, it could be used as a convenient configurator for existing build system.

Features

  • Automatically finds the next OOo SDK version on Unix platforms:
    • Official stable build of OOo SDK
    • Official development build of OOo SDK
    • Installation of OOo SDK, provided by Linux distribution (in most cases)
  • Automatically skips all OpenOffice.org installations without SDK, found in the system
  • Allows developer to override automatic choice of OOo SDK with custom path

After successful run module sets the next CMake variables:

  • OpenOffice_FOUND - System has OpenOffice.org with SDK (logical)
  • OpenOffice_VERSION - Version of OpenOffice.org with SDK
  • OOO_PREFIX - Prefix of OpenOffice.org installation
  • OOO_BASIS_DIR - "basis" directory of OpenOffice.org
  • OOO_PROGRAM_DIR - "program" directory of OpenOffice.org
  • OOO_URE_DIR - "ure" directory of OpenOffice.org
  • OOO_SDK_DIR - "sdk" directory of OpenOffice.org
  • OOO_INCLUDE_DIR - include directory of OpenOffice.org
  • UNOPKG_EXECUTABLE - Absolute path of unopkg tool

CMake module "FindOpenOffice" can be downloaded here:

File:FindOpenOffice.cmake.gz

Finding OpenOffice.org SDK

To use it, download this file, uncompress it, copy into your project directory (it's traditional to use subdirectory cmake/modules/ for this purpose), and add line

find_package(OpenOffice)

into your CMakeLists.txt. It's needed to set variable CMAKE_MODULE_PATH in the beginning of project, see example below. If OpenOffice.org SDK is mandatory for building of your project, use

find_package(OpenOffice REQUIRED)

to stop configuration process if OpenOffice.org SDK was not found.

Usage example

CMakeLists.txt from OOChemistry project (https://sourceforge.net/projects/oochemistry/)

project(oochemistry Java)
cmake_minimum_required(VERSION 2.6)

set(CMAKE_MODULE_PATH "${oochemistry_SOURCE_DIR}/cmake/modules")
set(CLEAN_FILES
  ${oochemistry_BINARY_DIR}/classes
  ${oochemistry_BINARY_DIR}/cpreg
  ${oochemistry_BINARY_DIR}/img
  ${oochemistry_BINARY_DIR}/MANIFEST.MF
  ${oochemistry_BINARY_DIR}/idlc.compile
  ${oochemistry_BINARY_DIR}/regclass.properties
  ${oochemistry_SOURCE_DIR}/dist
)
set_directory_properties(PROPERTIES 
  ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILES}")

find_package(OpenOffice REQUIRED)
if(OpenOffice_VERSION LESS 300)
  message("Warning! Your OpenOffice.org is too old, OOChemistry may not work with it!")
endif(OpenOffice_VERSION LESS 300)

find_file(ANT_EXECUTABLE NAMES ant)
mark_as_advanced(ANT_EXECUTABLE)

if(NOT ANT_EXECUTABLE)
  message(FATAL_ERROR "Could not find unopkg executable")
endif(NOT ANT_EXECUTABLE)
message(STATUS "Found ant executable: ${ANT_EXECUTABLE}")

# Add JCP, Jmol, and "OOo library" to classpath
file(GLOB jars 
  "${OOO_URE_JAVA_DIR}/*.jar"
  "${OOO_BASIS_DIR}/program/classes/*.jar"
#  "${oochemistry_SOURCE_DIR}/lib/*.jar"
)
foreach(jar ${jars})
  set(OOO_CLASSPATH "${jar}:${OOO_CLASSPATH}")
endforeach(jar ${jars})

file(GLOB jars 
  ${jars}
  "${oochemistry_SOURCE_DIR}/lib/*.jar"
)
foreach(jar ${jars})
  set(OOCHEM_CLASSPATH "${jar}:${OOCHEM_CLASSPATH}")
endforeach(jar ${jars})

# Generate build.xml
configure_file(
  "${oochemistry_SOURCE_DIR}/build.xml.in"
  "${oochemistry_SOURCE_DIR}/build.xml"
  @ONLY
)

# Generate properties file for cmake-initiated build
configure_file(
  "${oochemistry_SOURCE_DIR}/oochemistry.properties.in"
  "${oochemistry_BINARY_DIR}/oochemistry.properties"
  @ONLY
)

# Make NetBeans happy
# Don't forget to port changes in project to project.properties.in!
configure_file(
  "${oochemistry_SOURCE_DIR}/nbproject/project.properties.in"
  "${oochemistry_SOURCE_DIR}/nbproject/project.properties"
  @ONLY
)

option(VERBOSE_ANT "Run Ant in verbose mode" OFF)
if(VERBOSE_ANT)
  set(VERBOSE_FLAG "-v")
else(VERBOSE_ANT)
  set(VERBOSE_FLAG "")
endif(VERBOSE_ANT)

set(JAVAC_FLAGS "" CACHE STRING "Flags used by Java compiler")

# Build oochemistry.oxt
add_custom_target(oochemistry 
  ALL
  WORKING_DIRECTORY "${oochemistry_SOURCE_DIR}"
  COMMAND 
    ${ANT_EXECUTABLE} ${VERBOSE_FLAG} -Djavac.compilerargs="${JAVAC_FLAGS}" -propertyfile "${oochemistry_BINARY_DIR}/oochemistry.properties" uno-package
)

add_custom_target(install 
  WORKING_DIRECTORY "${oochemistry_SOURCE_DIR}"
  COMMAND ${UNOPKG_EXECUTABLE} add -f dist/oochemistry.oxt
)

add_dependencies(install oochemistry)
Personal tools