|
| 1 | +cmake_minimum_required(VERSION 2.8) |
| 2 | +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake-modules) |
| 3 | +project(sapi-c-client CXX C) |
| 4 | +include(ExternalProject) |
| 5 | + |
| 6 | +file(STRINGS ../version.txt SAPI_VERSION LIMIT_COUNT 1) |
| 7 | +if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) |
| 8 | + set(BITS 64) |
| 9 | +else() |
| 10 | + set(BITS 32) |
| 11 | +endif() |
| 12 | +if(CMAKE_HOST_WIN32) |
| 13 | + set(SAPI_ARCH "win${BITS}") |
| 14 | +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 15 | + set(SAPI_ARCH "linux${BITS}") |
| 16 | +elseif(CMAKE_HOST_APPLE) |
| 17 | + set(SAPI_ARCH "osx") # No more 32-bit OSX |
| 18 | +else() |
| 19 | + message(SEND_ERROR "Unknown system type") |
| 20 | +endif() |
| 21 | +set(SAPI_CLIENT C) |
| 22 | +configure_file("${CMAKE_SOURCE_DIR}/../remote/src/user-agent.cpp.in" |
| 23 | + user-agent.cpp @ONLY ESCAPE_QUOTES) |
| 24 | + |
| 25 | +set(PRODUCT_NAME "D-WAVE C PACK") |
| 26 | + |
| 27 | +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 28 | + set(README_LINUX_NSS " |
| 29 | +Linux users: if you see an error message like this: |
| 30 | +
|
| 31 | + libssl3.so: cannot open shared object file: No such file or directory |
| 32 | +
|
| 33 | +your system is likely missing NSS libraries. Install the libnss3 (Ubuntu, |
| 34 | +Debian) or nss (Fedora, Red Hat) package.") |
| 35 | +else() |
| 36 | + set(README_LINUX_NSS) |
| 37 | +endif() |
| 38 | +configure_file(README.txt.in README.txt @ONLY) |
| 39 | +configure_file(${CMAKE_SOURCE_DIR}/licenses/eula.txt.in |
| 40 | + ${CMAKE_CURRENT_BINARY_DIR}/licenses/eula.txt @ONLY) |
| 41 | + |
| 42 | +set(DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download) |
| 43 | + |
| 44 | +# Enable C++11 support |
| 45 | +# requires g++ >=4.4 on Linux |
| 46 | +if(CMAKE_COMPILER_IS_GNUCXX) |
| 47 | + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion |
| 48 | + OUTPUT_VARIABLE GXX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE |
| 49 | + ERROR_QUIET) |
| 50 | + if(GXX_VERSION VERSION_LESS 4.4) |
| 51 | + message(SEND_ERROR "g++ >= 4.4 required") |
| 52 | + elseif(GXX_VERSION VERSION_LESS 4.7) |
| 53 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 54 | + else() |
| 55 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 56 | + endif() |
| 57 | +elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) |
| 58 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
| 59 | +elseif(MSVC) |
| 60 | + add_definitions(/D_WIN32_WINNT=0x501) |
| 61 | + if(MSVC_VERSION EQUAL 1700) |
| 62 | + add_definitions(/D_VARIADIC_MAX=10) |
| 63 | + endif() |
| 64 | +endif() |
| 65 | + |
| 66 | +configure_file(src/version.c.in version.c @ONLY ESCAPE_QUOTES) |
| 67 | + |
| 68 | +# Boost |
| 69 | +find_package(Boost 1.53 REQUIRED COMPONENTS system) |
| 70 | +add_definitions(-DBOOST_ALL_NO_LIB) |
| 71 | +include_directories(SYSTEM ${Boost_INCLUDE_DIR}) |
| 72 | + |
| 73 | +# coin-or |
| 74 | +include(coinor) |
| 75 | +include_directories(${COINOR_INCLUDE_DIR}) |
| 76 | + |
| 77 | +# External: orang |
| 78 | +ExternalProject_Add(orang |
| 79 | + GIT_REPOSITORY "http://git.dwavesys.local/scm/~marshall/orang.git" |
| 80 | + GIT_TAG "v1.1" |
| 81 | + UPDATE_COMMAND "" |
| 82 | + CONFIGURE_COMMAND "" |
| 83 | + CMAKE_COMMAND "" |
| 84 | + BUILD_COMMAND "" |
| 85 | + INSTALL_COMMAND "") |
| 86 | + |
| 87 | +set(FIND_EMBEDDING_SOURCES |
| 88 | + ${CMAKE_SOURCE_DIR}/../find-embedding/src/find_embedding.cpp) |
| 89 | + |
| 90 | +set(FIX_VARIABLES_SOURCES |
| 91 | + ${CMAKE_SOURCE_DIR}/../fix-variables/src/fix_variables.cpp) |
| 92 | + |
| 93 | +set(SAPI_LOCAL_SOURCES |
| 94 | + ${CMAKE_SOURCE_DIR}/../local-solvers/src/orang-heuristic.cpp |
| 95 | + ${CMAKE_SOURCE_DIR}/../local-solvers/src/orang-solvers.cpp |
| 96 | + ${CMAKE_SOURCE_DIR}/../local-solvers/src/problems.cpp) |
| 97 | + |
| 98 | +set(QSAGE_SOURCES |
| 99 | + ${CMAKE_SOURCE_DIR}/../qsage/src/blackbox.cpp) |
| 100 | + |
| 101 | +set(SAPI_REMOTE_SOURCES |
| 102 | + ${CMAKE_SOURCE_DIR}/../remote/src/answer-service.cpp |
| 103 | + ${CMAKE_SOURCE_DIR}/../remote/src/await.cpp |
| 104 | + ${CMAKE_SOURCE_DIR}/../remote/src/base64.cpp |
| 105 | + ${CMAKE_SOURCE_DIR}/../remote/src/decode-answer.cpp |
| 106 | + ${CMAKE_SOURCE_DIR}/../remote/src/decode-qp.cpp |
| 107 | + ${CMAKE_SOURCE_DIR}/../remote/src/encode-qp.cpp |
| 108 | + ${CMAKE_SOURCE_DIR}/../remote/src/http-service.cpp |
| 109 | + ${CMAKE_SOURCE_DIR}/../remote/src/json.cpp |
| 110 | + ${CMAKE_SOURCE_DIR}/../remote/src/problem-manager.cpp |
| 111 | + ${CMAKE_SOURCE_DIR}/../remote/src/retry-service.cpp |
| 112 | + ${CMAKE_SOURCE_DIR}/../remote/src/sapi-service.cpp |
| 113 | + ${CMAKE_SOURCE_DIR}/../remote/src/threadpool.cpp |
| 114 | + ${CMAKE_CURRENT_BINARY_DIR}/user-agent.cpp) |
| 115 | + |
| 116 | +include_directories(${CMAKE_SOURCE_DIR}/include |
| 117 | + ${CMAKE_SOURCE_DIR}/../find-embedding/include |
| 118 | + ${CMAKE_SOURCE_DIR}/../fix-variables/include |
| 119 | + ${CMAKE_SOURCE_DIR}/../local-solvers/include |
| 120 | + ${CMAKE_SOURCE_DIR}/../qsage/include |
| 121 | + ${CMAKE_SOURCE_DIR}/../remote/include |
| 122 | + ${CMAKE_CURRENT_BINARY_DIR}/orang-prefix/src/orang/src) |
| 123 | + |
| 124 | + |
| 125 | +option(ENABLE_LIBRARY "Build client library" ON) |
| 126 | +if(ENABLE_LIBRARY) |
| 127 | + # libcurl |
| 128 | + find_package(CURL 7.28 REQUIRED) |
| 129 | + include_directories(SYSTEM ${CURL_INCLUDE_DIRS}) |
| 130 | + |
| 131 | + add_library(dwave_sapi SHARED |
| 132 | + src/dwave_sapi.cpp |
| 133 | + src/embed-problem.cpp |
| 134 | + src/unembed-answer.cpp |
| 135 | + src/fix-variables.cpp |
| 136 | + src/conversions.cpp |
| 137 | + src/internal.cpp |
| 138 | + src/global.cpp |
| 139 | + src/remote.cpp |
| 140 | + src/local.cpp |
| 141 | + src/freefuncs.cpp |
| 142 | + src/defaults.cpp |
| 143 | + src/sapi-impl.cpp |
| 144 | + ${CMAKE_BINARY_DIR}/version.c |
| 145 | + ${FIND_EMBEDDING_SOURCES} |
| 146 | + ${FIX_VARIABLES_SOURCES} |
| 147 | + ${SAPI_LOCAL_SOURCES} |
| 148 | + ${QSAGE_SOURCES} |
| 149 | + ${SAPI_REMOTE_SOURCES}) |
| 150 | + |
| 151 | + target_link_libraries(dwave_sapi |
| 152 | + ${Boost_SYSTEM_LIBRARY} |
| 153 | + ${CURL_LIBRARY} |
| 154 | + ${COINOR_LIBRARIES}) |
| 155 | + |
| 156 | + add_dependencies(dwave_sapi orang) |
| 157 | + |
| 158 | + get_target_property(DWAVE_SAPI_LINK_FLAGS dwave_sapi LINK_FLAGS) |
| 159 | + |
| 160 | + if(NOT DWAVE_SAPI_LINK_FLAGS) |
| 161 | + set(DWAVE_SAPI_LINK_FLAGS) |
| 162 | + endif() |
| 163 | + |
| 164 | + if(CMAKE_HOST_APPLE) |
| 165 | + list(APPEND DWAVE_SAPI_LINK_FLAGS |
| 166 | + "-Wl,-exported_symbols_list,${CMAKE_SOURCE_DIR}/exported-symbols-osx.map") |
| 167 | + elseif(CMAKE_HOST_UNIX) |
| 168 | + list(APPEND DWAVE_SAPI_LINK_FLAGS |
| 169 | + "-Wl,--version-script=${CMAKE_SOURCE_DIR}/version.map") |
| 170 | + endif() |
| 171 | + |
| 172 | + set_target_properties(dwave_sapi PROPERTIES |
| 173 | + COMPILE_DEFINITIONS DWAVE_SAPI_BUILD |
| 174 | + LINK_FLAGS "${DWAVE_SAPI_LINK_FLAGS}") |
| 175 | + |
| 176 | + if(CMAKE_BUILD_TYPE MATCHES "Release|MinSizeRel") |
| 177 | + set(STRIP_ARGS) |
| 178 | + if(CMAKE_HOST_APPLE) |
| 179 | + set(STRIP_ARGS "-x") |
| 180 | + endif() |
| 181 | + |
| 182 | + if(CMAKE_STRIP) |
| 183 | + get_target_property(DWAVE_SAPI_OUTPUT_NAME dwave_sapi LOCATION) |
| 184 | + add_custom_command(TARGET dwave_sapi POST_BUILD |
| 185 | + COMMAND ${CMAKE_STRIP} ${STRIP_ARGS} ${DWAVE_SAPI_OUTPUT_NAME} |
| 186 | + COMMENT "Stripping dwave_sapi c library" |
| 187 | + VERBATIM) |
| 188 | + endif() |
| 189 | + endif() |
| 190 | + |
| 191 | + install(FILES |
| 192 | + ${CMAKE_BINARY_DIR}/README.txt |
| 193 | + ${CMAKE_CURRENT_SOURCE_DIR}/include/dwave_sapi.h |
| 194 | + DESTINATION .) |
| 195 | + |
| 196 | + install(TARGETS dwave_sapi DESTINATION .) |
| 197 | + |
| 198 | + install(DIRECTORY examples DESTINATION .) |
| 199 | + |
| 200 | + install(FILES |
| 201 | + ${CMAKE_CURRENT_BINARY_DIR}/licenses/eula.txt |
| 202 | + ../licenses.txt |
| 203 | + DESTINATION licenses) |
| 204 | + |
| 205 | + # Packaging |
| 206 | + |
| 207 | + if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) |
| 208 | + set(BITS 64) |
| 209 | + else() |
| 210 | + set(BITS 32) |
| 211 | + endif() |
| 212 | + |
| 213 | + if(CMAKE_HOST_WIN32) |
| 214 | + set(CPACK_SYSTEM_NAME "win${BITS}") |
| 215 | + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 216 | + set(CPACK_SYSTEM_NAME "linux${BITS}") |
| 217 | + elseif(CMAKE_HOST_APPLE) |
| 218 | + set(CPACK_SYSTEM_NAME "osx") # No more 32-bit OSX |
| 219 | + else() |
| 220 | + message(SEND_ERROR "Unknown system type") |
| 221 | + endif() |
| 222 | + |
| 223 | + set(CPACK_PACKAGE_NAME sapi-c-client) |
| 224 | + set(CPACK_PACKAGE_VERSION "${SAPI_VERSION}") |
| 225 | + include(CPack) |
| 226 | +endif() |
| 227 | + |
| 228 | +option(ENABLE_TESTS "Enable sapi c client tests" OFF) |
| 229 | +if(ENABLE_TESTS) |
| 230 | + # Google Mock |
| 231 | + set(GMOCK_INCLUDEDIR "" CACHE PATH "Google Mock header file directory") |
| 232 | + set(GMOCK_LIBRARYDIR "" CACHE PATH "Google Mock library directory") |
| 233 | + find_path(GMock_INCLUDE_DIRS gmock/gmock.h HINTS ${GMOCK_INCLUDEDIR}) |
| 234 | + find_library(GMock_LIBRARY gmock HINTS ${GMOCK_LIBRARYDIR}) |
| 235 | + |
| 236 | + # Google Test |
| 237 | + set(GTEST_INCLUDEDIR "" CACHE PATH "GTest header file directory") |
| 238 | + set(GTEST_LIBRARYDIR "" CACHE PATH "GTest library directory") |
| 239 | + set(GTEST_LIBRARYDIRS ${GTEST_LIBRARYDIR}) |
| 240 | + if(GMOCK_LIBRARYDIR) |
| 241 | + list(APPEND GTEST_LIBRARYDIRS ${GMOCK_LIBRARYDIR}/gtest) |
| 242 | + endif() |
| 243 | + |
| 244 | + find_path(GTest_INCLUDE_DIRS gtest/gtest.h PATHS ${GTEST_INCLUDEDIR}) |
| 245 | + find_library(GTest_LIBRARY gtest HINTS ${GTEST_LIBRARYDIRS}) |
| 246 | + |
| 247 | + add_subdirectory(test) |
| 248 | +endif() |
0 commit comments