CMakeLists.txt 8.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# *******************************************************************************
# Copyright (c) 2017 UT-Battelle, LLC.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v.10 which accompany this distribution. 
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html 
# and the Eclipse Distribution License is available at 
# https://eclipse.org/org/documents/edl-v10.php
#
# Contributors:
#   Alexander J. McCaskey - initial API and implementation 
# *******************************************************************************/
13
project(xacc LANGUAGES CXX)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
14
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
15
set(CMAKE_STANDARD_REQUIRED ON)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
16
set(CMAKE_CXX_STANDARD 11)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
17
18
message(STATUS "C++ version ${CXX_STANDARD} configured.")

19
# Make sure all build libraries have reference to their dependents
Mccaskey, Alex's avatar
Mccaskey, Alex committed
20
21
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
22
23

include(ExternalProject)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
24

Mccaskey, Alex's avatar
Mccaskey, Alex committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
if(NOT WIN32)
  string(ASCII 27 Esc)
  set(ColorReset "${Esc}[m")
  set(ColorBold  "${Esc}[1m")
  set(Red         "${Esc}[31m")
  set(Green       "${Esc}[32m")
  set(Yellow      "${Esc}[33m")
  set(Blue        "${Esc}[34m")
  set(Magenta     "${Esc}[35m")
  set(Cyan        "${Esc}[36m")
  set(White       "${Esc}[37m")
  set(BoldRed     "${Esc}[1;31m")
  set(BoldGreen   "${Esc}[1;32m")
  set(BoldYellow  "${Esc}[1;33m")
  set(BoldBlue    "${Esc}[1;34m")
  set(BoldMagenta "${Esc}[1;35m")
  set(BoldCyan    "${Esc}[1;36m")
  set(BoldWhite   "${Esc}[1;37m")
endif()

45
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
46
	set (CMAKE_INSTALL_PREFIX "$ENV{HOME}/.xacc" CACHE PATH "default install path" FORCE )
47
48
endif()

Mccaskey, Alex's avatar
Mccaskey, Alex committed
49
50
message(STATUS "${BoldGreen}Installing XACC to ${CMAKE_INSTALL_PREFIX}. Override with -DCMAKE_INSTALL_PREFIX=...${ColorReset}")

51
52
53
54
55
56
57
58
59
# Setup Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" 
    VERBATIM)
endif(DOXYGEN_FOUND)

60
61
62
63
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "7.0.0")
        set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wimplicit-fallthrough=0")
endif()

64
65
66
ExternalProject_Add(cppmicroservices
	GIT_REPOSITORY https://github.com/cppmicroservices/cppmicroservices
	GIT_TAG v3.1.0	
67
	CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
68
               -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
69
               -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
70
71
72
73
74
               -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
		       -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
        INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install 
)

Mccaskey, Alex's avatar
Mccaskey, Alex committed
75
76
77
78
79
80
81
82
# Make it so you don't always have to 
# specify openssl dir on mac
if(APPLE AND NOT OPENSSL_ROOT_DIR)
	if (EXISTS /usr/local/opt/openssl) 
		message(STATUS "${BoldGreen}Searching for OpenSSL from /usr/local/opt/openssl. Override with -DOPENSSL_ROOT_DIR=...${ColorReset}")
		set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
	endif()
endif()
83
84
find_package(OpenSSL 1.0.2 REQUIRED)

Mccaskey, Alex's avatar
Mccaskey, Alex committed
85
message(STATUS "${BoldGreen}Found OpenSSL version ${OPENSSL_VERSION}${ColorReset}")
86
87

ExternalProject_Add(cpprestsdk
88
    DEPENDS cppmicroservices
89
	GIT_REPOSITORY https://github.com/Microsoft/cpprestsdk
90
	GIT_TAG master
91
92
93
	CONFIGURE_COMMAND ${CMAKE_COMMAND} ../cpprestsdk/Release/ -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
               -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
               -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
94
               -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
95
96
		   	   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
		   	   -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
97
		   	   -DBUILD_TESTS=OFF
98
    INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install 
99
)
100

101
102
set(CppMicroServices_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/cppmicroservices3)
set(CppMicroServices_LIBRARY_DIR ${CMAKE_INSTALL_PREFIX}/lib)
103

104
105
106
set(CppRSDK_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
set(CppRSDK_LIBRARY_DIR ${CMAKE_INSTALL_PREFIX}/lib)

107
# Look for OpenMP, add it we find it
Mccaskey, Alex's avatar
Mccaskey, Alex committed
108
109
110
111
112
find_package(OpenMP)
if (OPENMP_FOUND)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

113
ExternalProject_Add(xacc-core
114
   DEPENDS cppmicroservices cpprestsdk
115
116
117
118
119
   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xacc
   CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
              -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
              -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
              -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
120
              -DBOOST_ROOT=${BOOST_ROOT}
121
122
123
124
	      	  -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
	          -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
	          -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
	          -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
125
		  -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
126
127
	          -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
	          -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
128
		  -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
129
130
   CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
   BUILD_ALWAYS 1
Mccaskey, Alex's avatar
Mccaskey, Alex committed
131
   INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install # DESTDIR=${CMAKE_BINARY_DIR}/stage
132
133
134
135
136
137
138
   TEST_BEFORE_INSTALL 1
   )

set(XACC_BASE_DIR ${CMAKE_BINARY_DIR}/stage${CMAKE_INSTALL_PREFIX})
set(XACC_INCLUDE_DIR ${XACC_BASE_DIR}/include/xacc)
set(XACC_LIBRARY_DIR ${XACC_BASE_DIR}/lib)
string (REPLACE ";" " " XACC_Boost_LIBRARIES "${Boost_LIBRARIES}")
139
string (REPLACE ";" " " XACC_MPI_INCLUDE_PATHS "${MPI_CXX_INCLUDE_PATH}")
Mccaskey, Alex's avatar
Mccaskey, Alex committed
140

141
142
143
144
145
146
147
ExternalProject_Add(xacc-quantum
   DEPENDS xacc-core
   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/quantum
   CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
              -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
              -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
              -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
148
149
	          -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
	          -DBOOST_ROOT=${BOOST_ROOT}
150
151
              -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
              -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
152
153
154
155
156
	          -DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc
	          -DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib
	          -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
	          -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
	          -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
157
		  -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
158
159
160
161
162
163
164
165
166
167
168
169
170
   CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
   BUILD_ALWAYS 1
   INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
   TEST_AFTER_INSTALL 1
   )

ExternalProject_Add(xacc-python
   DEPENDS xacc-core xacc-quantum
   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python
   CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
              -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
              -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
              -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
171
172
173
	      -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
	      -DBOOST_ROOT=${BOOST_ROOT}
	      -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
174
              -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
175
176
177
178
179
180
181
182
	      -DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include #${XACC_INCLUDE_DIR}
	      -DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR}
	      -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
	      -DFROM_SETUP_PY=${FROM_SETUP_PY}
              -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
              -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
              -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
              -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
183
184
   CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
   BUILD_ALWAYS 1
Mccaskey, Alex's avatar
Mccaskey, Alex committed
185
   INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
186
187
   TEST_AFTER_INSTALL 1
   )
188
189
190
191
192

# Install the config file for external projects to use
# This is cool, users just add find_package(XACC REQUIRED) to 
# their CMake builds, and pass -DXACC_DIR=/path/to/install/xacc
# and CMake loads include paths, libs, etc
193
194
configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config.cmake")
install(FILES "${CMAKE_BINARY_DIR}/xacc-config.cmake" DESTINATION .)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
195
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/xacc/)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
196
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
Mccaskey, Alex's avatar
Mccaskey, Alex committed
197
198
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
199
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/pybind11" DESTINATION include )
Mccaskey, Alex's avatar
Mccaskey, Alex committed
200
install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/framework/xacc-framework" DESTINATION bin)