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
|
#
# This script can be used to create static executables linking to the static
# OpenBabel3 library.
#
# This script requires OpenBabel to be build and installed. For example:
#
# cd openbabel
# mkdir build
# cd build
# cmake -DBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=/home/me/some/path ..
# make
# make install
#
# To compile your static executable:
#
# cd myproject
# mkdir build
# cd build
# cmake -DOpenBabel3_DIR=/home/me/some/path/lib/openbabel ..
# make
#
# All plugins are inside the static libopenbabel.a but the symbols for the
# plugin classes have to be undefined. Plugins can be disabled by removing
# the class names from the format_classes, descriptor_classes, ... lists below.
#
# This line is required for cmake backwards compatibility.
cmake_minimum_required(VERSION 2.6)
# Name of your project
project(myproject)
# Create a list of source files (easier to maintain)
set(sources myexe.cpp)
# Set the name for the executable
set(executable_target myexe)
################################################################################
#
# Set compile flags for various compilers.
#
if(MSVC)
# Set cl flags for static compiling
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT")
# Note: static libraries are specified when running cmake
else()
# Use -static flag to create static executable
set(CMAKE_CXX_FLAGS "-static ${CMAKE_CXX_FLAGS}")
# Make sure we find static libraries
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
# Set the path containing OpenBabel3Config.cmake, needed for find_package below.
find_path(OpenBabel3_DIR OpenBabel3Config.cmake PATHS
${OpenBabel3_DIR}
"/usr/lib/openbabel"
"/usr/local/lib/openbabel")
#
# Find and setup OpenBabel3.
#
find_package(OpenBabel3 REQUIRED)
include_directories(${OpenBabel3_INCLUDE_DIRS})
# Dependencies
find_package(LibXml2)
# The executable
add_executable(${executable_target} ${sources})
# Link against imported openbabel target
target_link_libraries(${executable_target} openbabel ${LIBXML2_LIBRARIES})
# Prevent -Wl,-Bdynamic from being added to the end of the link line.
set_target_properties(${executable_target} PROPERTIES
LINK_SEARCH_END_STATIC TRUE)
install(TARGETS ${executable_target} DESTINATION bin)
|