CMakeLists.txt 5.56 KB
Newer Older
1
project(xacc LANGUAGES CXX)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
2
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
3
set(CMAKE_STANDARD_REQUIRED ON)
4
set(CMAKE_CXX_STANDARD 14)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
5
6
message(STATUS "C++ version ${CXX_STANDARD} configured.")

7
# Make sure all build libraries have reference to their dependents
Mccaskey, Alex's avatar
Mccaskey, Alex committed
8
9
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
10
11
12
set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage${CMAKE_INSTALL_PREFIX})

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

14
15
16
17
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set (CMAKE_INSTALL_PREFIX "/usr/local/xacc" CACHE PATH "default install path" FORCE )
endif()

18
19
20
21
22
23
24
25
26
# 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)

27
28
29
30
31
32
33
34
35
ExternalProject_Add(cppmicroservices
	GIT_REPOSITORY https://github.com/cppmicroservices/cppmicroservices
	GIT_TAG v3.1.0	
        CMAKE_ARGS -DCMAKE_CXX_FLAGS='-Wimplicit-fallthrough=0'
                   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
                   -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
                   -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
        INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install DESTDIR=${CMAKE_BINARY_DIR}/cppus_install
)
36
37

set(CppMicroServices_BASE_DIR ${CMAKE_BINARY_DIR}/cppus_install/usr/local)
38
39
set(CppMicroServices_INCLUDE_DIR ${CppMicroServices_BASE_DIR}/include/cppmicroservices3)
set(CppMicroServices_LIBRARY_DIR ${CppMicroServices_BASE_DIR}/lib)
40

41
# We require MPI
Mccaskey, Alex's avatar
Mccaskey, Alex committed
42
find_package(MPI)
43
44
if (MPI_FOUND)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXACC_HAS_MPI")
45

46
  # We require Boost with MPI
47
48
  find_package(Boost COMPONENTS mpi system program_options filesystem chrono thread REQUIRED)
  include_directories(${MPI_INCLUDE_PATH})
49
50
else()
  message(STATUS "MPI Not Found.")
51

52
  # We require Boost without MPI
53
  find_package(Boost COMPONENTS system program_options filesystem chrono thread REQUIRED)
54
endif()
55

56
# Look for OpenMP, add it we find it
Mccaskey, Alex's avatar
Mccaskey, Alex committed
57
58
59
60
61
find_package(OpenMP)
if (OPENMP_FOUND)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
ExternalProject_Add(xacc-core
   DEPENDS cppmicroservices
   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}
              -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
              -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
	      -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
	      -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
	      -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
	      -DBoost_INCLUDE_DIRS=${BOOST_INCLUDE_DIRS}
	      -DBoost_LIBRARIES=${Boost_LIBRARIES}
	      -DMPI_INCLUDE_PATH=${MPI_INCLUDE_PATH}
   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_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}")
Mccaskey, Alex's avatar
Mccaskey, Alex committed
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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}
              -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
              -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
              -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
              -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
              -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
	      -DXACC_INCLUDE_DIR=${XACC_INCLUDE_DIR}
	      -DXACC_LIBRARY_DIR=${XACC_LIBRARY_DIR}
	      -DBoost_INCLUDE_DIRS=${BOOST_INCLUDE_DIRS}
	      -DXACC_Boost_LIBRARIES=${XACC_Boost_LIBRARIES}
	      -DMPI_INCLUDE_PATH=${MPI_INCLUDE_PATH}
   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
   )
110
111
112
113
114

# 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
115
116
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
117
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/xacc/)
Mccaskey, Alex's avatar
Mccaskey, Alex committed
118
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
Mccaskey, Alex's avatar
Mccaskey, Alex committed
119
120
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
Mccaskey, Alex's avatar
Mccaskey, Alex committed
121
install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/bin/" DESTINATION bin PATTERN "bin/*" PERMISSIONS OWNER_EXECUTE) 
122
install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/include/" DESTINATION include) 
Mccaskey, Alex's avatar
Mccaskey, Alex committed
123
install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/lib/" DESTINATION lib) 
124
125
install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/share/" DESTINATION share) 
install( DIRECTORY "${CMAKE_BINARY_DIR}/stage/usr/local/xacc/" DESTINATION .)