| 1 | project(XtalOpt) |
|---|
| 2 | |
|---|
| 3 | cmake_minimum_required(VERSION 2.6) |
|---|
| 4 | set(CMAKE_MODULE_PATH ${XtalOpt_SOURCE_DIR}/cmake/modules) |
|---|
| 5 | |
|---|
| 6 | set(QT_MIN_VERSION "4.6.0") |
|---|
| 7 | find_package(Qt4 REQUIRED) |
|---|
| 8 | find_package(OpenBabel2 REQUIRED) |
|---|
| 9 | find_package(Avogadro REQUIRED) |
|---|
| 10 | |
|---|
| 11 | include(${Avogadro_USE_FILE}) |
|---|
| 12 | include_directories( ${CMAKE_CURRENT_BINARY_DIR} |
|---|
| 13 | ${OPENBABEL2_INCLUDE_DIR} |
|---|
| 14 | ${XtalOpt_SOURCE_DIR}/src/) |
|---|
| 15 | |
|---|
| 16 | link_directories(${OPENBABEL2_LIBRARIES_DIRS}) |
|---|
| 17 | include(MacroEnsureVersion) |
|---|
| 18 | |
|---|
| 19 | option( BUILD_TESTS |
|---|
| 20 | "Whether to compile the test suite as well as the main code." |
|---|
| 21 | OFF ) |
|---|
| 22 | |
|---|
| 23 | if(BUILD_TESTS) |
|---|
| 24 | enable_testing() |
|---|
| 25 | endif(BUILD_TESTS) |
|---|
| 26 | |
|---|
| 27 | option( ENABLE_SSH |
|---|
| 28 | "Enable SSH. Only the local queue interface will be available if disabled." |
|---|
| 29 | ON ) |
|---|
| 30 | |
|---|
| 31 | option( USE_CLI_SSH |
|---|
| 32 | "Use command line ssh/scp commands for remote communication. Use this if on linux/mac and Kerberos authentication is needed." |
|---|
| 33 | OFF ) |
|---|
| 34 | |
|---|
| 35 | if(ENABLE_SSH) |
|---|
| 36 | add_definitions(-DENABLE_SSH) |
|---|
| 37 | message(STATUS "SSH Enabled") |
|---|
| 38 | # Pull in libssh |
|---|
| 39 | if(USE_CLI_SSH) |
|---|
| 40 | add_definitions(-DUSE_CLI_SSH) |
|---|
| 41 | message(STATUS "Using command-line SSH interface") |
|---|
| 42 | else(USE_CLI_SSH) |
|---|
| 43 | message(STATUS "Using libssh SSH interface") |
|---|
| 44 | set(LibSSH_FIND_VERSION ON) |
|---|
| 45 | set(LibSSH_MIN_VERSION "0.4.8") |
|---|
| 46 | find_package(LibSSH REQUIRED) |
|---|
| 47 | if(NOT LIBSSH_FOUND) |
|---|
| 48 | message(FATAL_ERROR "libssh not found!") |
|---|
| 49 | endif() |
|---|
| 50 | macro_ensure_version(${LibSSH_MIN_VERSION} ${LibSSH_VERSION} |
|---|
| 51 | LIBSSH_VERSION_OK) |
|---|
| 52 | if(NOT LIBSSH_VERSION_OK) |
|---|
| 53 | message(FATAL_ERROR |
|---|
| 54 | "libssh too old! Installed version is ${LibSSH_VERSION}, need at least " |
|---|
| 55 | "libssh ${LibSSH_MIN_VERSION}") |
|---|
| 56 | endif() |
|---|
| 57 | message(STATUS "LibSSH found: ${LibSSH_VERSION} ${LIBSSH_INCLUDE_DIRS} ${LIBSSH_LIBRARIES}") |
|---|
| 58 | include_directories(${LIBSSH_INCLUDE_DIRS}) |
|---|
| 59 | endif(USE_CLI_SSH) |
|---|
| 60 | endif() |
|---|
| 61 | |
|---|
| 62 | # This is a modified version of the avogadro_plugin function that produces |
|---|
| 63 | # a SHARED library instead of a MODULE |
|---|
| 64 | function(process_plugin plugin_name src_list) |
|---|
| 65 | string(REPLACE ".cpp" ".h" hdr_list "${src_list}") |
|---|
| 66 | qt4_wrap_cpp(moc_files ${hdr_list}) |
|---|
| 67 | if(NOT "${ARGV2}" STREQUAL "") |
|---|
| 68 | # Process the UI file for this plugin |
|---|
| 69 | qt4_wrap_ui(plugin_UIS_H ${ARGV2}) |
|---|
| 70 | endif(NOT "${ARGV2}" STREQUAL "") |
|---|
| 71 | if(NOT "${ARGV3}" STREQUAL "") |
|---|
| 72 | # Process the RC file and add it to the plugin |
|---|
| 73 | qt4_add_resources(plugin_RC_SRCS ${ARGV3}) |
|---|
| 74 | endif(NOT "${ARGV3}" STREQUAL "") |
|---|
| 75 | # Build static lib for linking to tests |
|---|
| 76 | if(BUILD_TESTS) |
|---|
| 77 | add_library(${plugin_name}_static STATIC ${src_list} ${plugin_UIS_H} |
|---|
| 78 | ${plugin_RC_SRCS} ${moc_files}) |
|---|
| 79 | target_link_libraries(${plugin_name}_static avogadro) |
|---|
| 80 | endif(BUILD_TESTS) |
|---|
| 81 | add_library(${plugin_name} SHARED ${src_list} ${plugin_UIS_H} |
|---|
| 82 | ${plugin_RC_SRCS} ${moc_files}) |
|---|
| 83 | target_link_libraries(${plugin_name} avogadro) |
|---|
| 84 | |
|---|
| 85 | install(TARGETS ${plugin_name} DESTINATION "${Avogadro_PLUGIN_DIR}/contrib") |
|---|
| 86 | |
|---|
| 87 | set_target_properties(${plugin_name} PROPERTIES |
|---|
| 88 | OUTPUT_NAME ${plugin_name} |
|---|
| 89 | PREFIX "") |
|---|
| 90 | endfunction(process_plugin) |
|---|
| 91 | |
|---|
| 92 | # Set -fPIC on x86_64 |
|---|
| 93 | if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") |
|---|
| 94 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" ) |
|---|
| 95 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" ) |
|---|
| 96 | endif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") |
|---|
| 97 | |
|---|
| 98 | # USING_DYNAMIC_LIBS needs to be defined for OpenBabel to properly export some symbols |
|---|
| 99 | if (MSVC) |
|---|
| 100 | add_definitions(-DUSING_DYNAMIC_LIBS) |
|---|
| 101 | endif (MSVC) |
|---|
| 102 | |
|---|
| 103 | add_subdirectory(src) |
|---|
| 104 | |
|---|
| 105 | if(BUILD_TESTS) |
|---|
| 106 | add_subdirectory(tests) |
|---|
| 107 | endif(BUILD_TESTS) |
|---|