mirror of https://github.com/Qiskit/qiskit.git
CMake improvements! (#468)
* CMake improvements: * Static linking is not the default anymore. * Platform Wheel Tag is now configurable via cmake variable. * Updated documentation * CI config file updated accordingly * Added support for Win64 builds on Visual Studio 2017 * Windows C++ Simulator now links with a prebuilt version of OpenBLAS (64 bits), so there's no need to link against LAPACK anymore * cmake added as a dependency * Restored --static-libgcc flag for static MacOS builds so gcc can create *semi* static executables again. Clang doesn't have static compilation. * Remove default WHEEL_TAG value so if not specified, the tag is choosen by the wheel module
This commit is contained in:
parent
f0e3e40620
commit
72eae89453
|
@ -51,7 +51,7 @@ stage_linux: &stage_linux
|
|||
dist: trusty
|
||||
language: python
|
||||
python: 3.5
|
||||
env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-5 -D ENABLE_TARGETS_QA=False"
|
||||
env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-5 -D ENABLE_TARGETS_QA=False -D WHEEL_TAG=-pmanylinux1_x86_64 -D STATIC_LINKING=True"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
@ -66,7 +66,7 @@ stage_osx: &stage_osx
|
|||
os: osx
|
||||
osx_image: xcode9.2
|
||||
language: generic
|
||||
env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-6 -D ENABLE_TARGETS_QA=False"
|
||||
env: CMAKE_FLAGS="-D CMAKE_CXX_COMPILER=g++-6 -D ENABLE_TARGETS_QA=False -D STATIC_LINKING=True"
|
||||
before_install:
|
||||
# Travis does not provide support for Python 3 under osx - it needs to be
|
||||
# installed manually.
|
||||
|
|
|
@ -83,6 +83,65 @@ more info about where to find libphreads.a for later building. Furthermore,
|
|||
we are forcing CMake to generate MingGW makefiles, because we don't support
|
||||
other toolchain at the moment.
|
||||
|
||||
Useful CMake flags
|
||||
------------------
|
||||
|
||||
There are some useful flags that can be set during cmake command invocation and
|
||||
will help you change some default behavior. To make use of them, you just need to
|
||||
pass them right after ``-D`` cmake argument. Example:
|
||||
.. code::
|
||||
|
||||
qiskit-sdk-py/out$ cmake -DUSEFUL_FLAG=Value ..
|
||||
|
||||
Flags:
|
||||
|
||||
USER_LIB_PATH
|
||||
This flag tells CMake to look for libraries that are needed by some of the native
|
||||
components to be built, but they are not in a common place where CMake could find
|
||||
it automatically.
|
||||
Values: An absolute path with file included.
|
||||
Default: No value.
|
||||
Example: ``cmake -DUSER_LIB_PATH=C:\path\to\mingw64\lib\libpthreads.a ..``
|
||||
|
||||
STATIC_LINKING
|
||||
Tells the build system whether to create static versions of the programs being built or not.
|
||||
Notes: On MacOS static linking is not fully working for all versions of GNU G++/Clang
|
||||
compilers, so enable this flag in this platform could cause errors.
|
||||
Values: True|False
|
||||
Default: False
|
||||
Example: ``cmake -DSTATIC_LINKING=True ..``
|
||||
|
||||
CMAKE_BUILD_TYPE
|
||||
Tells the build system to create executables/libraries for debugging purposes
|
||||
or highly optimized binaries ready for distribution.
|
||||
Values: Debug|Release
|
||||
Default: "Release"
|
||||
Example: ``cmake -DCMAKE_BUILD_TYPE="Debug" ..``
|
||||
|
||||
ENABLE_TARGETS_NON_PYTHON
|
||||
We can enable or disable non-python code generation by setting this flag to True or False
|
||||
respectively. This is mostly used in our CI systems so they can launch some fast tests
|
||||
for the Python code (which is currently a majority).
|
||||
Values: True|False
|
||||
Default: True
|
||||
Example: ``cmake -DENABLE_TARGETS_NON_PYTHON=True ..``
|
||||
|
||||
ENABLE_TARGETS_QA
|
||||
We can enable or disable QA stuff (lintering, styling and testing) by setting this flag to
|
||||
True or False respectively. This is mostly used in our CI systems so they can run light
|
||||
stages pretty fast, and fail fast if they found any issues within the code.
|
||||
Values: True|False
|
||||
Default: True
|
||||
Example: ``cmake -DENABLE_TARGETS_QA=True ..``
|
||||
|
||||
WHEEL_TAG
|
||||
This is used to force platform specific tag name generation when creating wheels package
|
||||
for Pypi.
|
||||
Values: "-pWhateverTagName"
|
||||
Default: No value.
|
||||
Example: ``cmake -DWHEEL_TAG="-pmanylinux1_x86_64" ..``
|
||||
|
||||
|
||||
Test
|
||||
~~~~
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
# Default values for global scope variables.
|
||||
# They can be overriden by passing -DVARIABLE=Value to cmake, like:
|
||||
# out$ cmake -DSTATIC_LINKING=False ..
|
||||
# out$ cmake -DSTATIC_LINKING=True ..
|
||||
#
|
||||
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
set(STATIC_LINKING True CACHE BOOL "Static linking of executables")
|
||||
set(STATIC_LINKING False CACHE BOOL "Static linking of executables")
|
||||
set(ENABLE_TARGETS_NON_PYTHON True CACHE BOOL "Enable targets for non Python code")
|
||||
set(ENABLE_TARGETS_QA True CACHE BOOL "Enable targets for QA targets")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH64 True CACHE BOOL "We are on a 64 bits platform")
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(ARCH32 True CACHE BOOL "We are on a 32 bits platform")
|
||||
endif()
|
|
@ -23,11 +23,11 @@ function(add_pypi_package_target TARGET_NAME PACKAGE_TYPE)
|
|||
|
||||
if(PACKAGE_TYPE STREQUAL "both")
|
||||
set(PIP_PACKAGE_SOURCE_DIST sdist --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel -p manylinux1_x86_64 --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel ${WHEEL_TAG} --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
elseif(PACKAGE_TYPE STREQUAL "sdist")
|
||||
set(PIP_PACKAGE_SOURCE_DIST sdist --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
elseif(PACKAGE_TYPE STREQUAL "bdist_wheel")
|
||||
set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel -p manylinux1_x86_64 --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
set(PIP_PACKAGE_PLATFORM_WHEELS bdist_wheel ${WHEEL_TAG} --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
|
||||
endif()
|
||||
|
||||
# For ' make clean' target
|
||||
|
|
|
@ -6,3 +6,4 @@ ply==3.10
|
|||
scipy>=0.19,<1.1
|
||||
sympy>=1.0
|
||||
pillow>=4.2.1
|
||||
cmake>=3.11,<3.12
|
||||
|
|
|
@ -39,35 +39,40 @@ set_target_properties(qasm_simulator_cpp PROPERTIES LINKER_LANGUAGE CXX)
|
|||
# Toolchain options
|
||||
set_property(TARGET qasm_simulator_cpp PROPERTY CXX_STANDARD 11)
|
||||
|
||||
# Compiler flags
|
||||
enable_cxx_compiler_flag_if_supported("-O3")
|
||||
enable_cxx_compiler_flag_if_supported("-march=native")
|
||||
enable_cxx_compiler_flag_if_supported("-fopenmp")
|
||||
|
||||
# We force static linking on Windows
|
||||
if(STATIC_LINKING OR MINGW)
|
||||
if(STATIC_LINKING)
|
||||
# Hack: Seems like enable_cxx_compiler_flag_if_supported() is not properly
|
||||
# working on MacOS, when a flag is not supported, it cascades errors
|
||||
# to the rest of the flags being tested... and -static compilation on Mac
|
||||
# with gcc is failing...
|
||||
if(NOT APPLE)
|
||||
enable_cxx_compiler_flag_if_supported("-static")
|
||||
enable_cxx_compiler_flag_if_supported("-static-libgcc")
|
||||
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(WARNING "Clang on MacOS doesn't support some -static-* flags. Switching to dyn compilation...")
|
||||
else()
|
||||
# MacOS compilers don't support -static flag either
|
||||
if(NOT APPLE)
|
||||
enable_cxx_compiler_flag_if_supported("-static")
|
||||
endif()
|
||||
# This is enough to build a semi-static executable on Mac
|
||||
enable_cxx_compiler_flag_if_supported("-static-libgcc")
|
||||
enable_cxx_compiler_flag_if_supported("-static-libstdc++")
|
||||
endif()
|
||||
enable_cxx_compiler_flag_if_supported("-static-libstdc++")
|
||||
endif()
|
||||
|
||||
# Warnings and Errors
|
||||
enable_cxx_compiler_flag_if_supported("-pedantic")
|
||||
enable_cxx_compiler_flag_if_supported("-Wall")
|
||||
enable_cxx_compiler_flag_if_supported("-Wfloat-equal")
|
||||
enable_cxx_compiler_flag_if_supported("-Wundef")
|
||||
enable_cxx_compiler_flag_if_supported("-Wcast-align")
|
||||
enable_cxx_compiler_flag_if_supported("-Wwrite-strings")
|
||||
enable_cxx_compiler_flag_if_supported("-Wmissing-declarations")
|
||||
enable_cxx_compiler_flag_if_supported("-Wredundant-decls")
|
||||
enable_cxx_compiler_flag_if_supported("-Wshadow")
|
||||
enable_cxx_compiler_flag_if_supported("-Woverloaded-virtual")
|
||||
if(NOT MSVC)
|
||||
# Compiler flags
|
||||
enable_cxx_compiler_flag_if_supported("-O3")
|
||||
enable_cxx_compiler_flag_if_supported("-march=native")
|
||||
# Warnings and Errors
|
||||
enable_cxx_compiler_flag_if_supported("-pedantic")
|
||||
enable_cxx_compiler_flag_if_supported("-Wall")
|
||||
enable_cxx_compiler_flag_if_supported("-Wfloat-equal")
|
||||
enable_cxx_compiler_flag_if_supported("-Wundef")
|
||||
enable_cxx_compiler_flag_if_supported("-Wcast-align")
|
||||
enable_cxx_compiler_flag_if_supported("-Wwrite-strings")
|
||||
enable_cxx_compiler_flag_if_supported("-Wmissing-declarations")
|
||||
enable_cxx_compiler_flag_if_supported("-Wredundant-decls")
|
||||
enable_cxx_compiler_flag_if_supported("-Wshadow")
|
||||
enable_cxx_compiler_flag_if_supported("-Woverloaded-virtual")
|
||||
endif()
|
||||
|
||||
target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR})
|
||||
target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR}/backends)
|
||||
|
@ -76,12 +81,21 @@ target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_D
|
|||
target_include_directories(qasm_simulator_cpp PRIVATE ${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/headers)
|
||||
|
||||
# For header only libraries
|
||||
SET(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
|
||||
SET(CMAKE_FIND_LIBRARY_PREFIXES "" ${CMAKE_FIND_LIBRARY_PREFIXES})
|
||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .hpp)
|
||||
|
||||
# We force static linking on Windows
|
||||
if(STATIC_LINKING OR MINGW)
|
||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
if(STATIC_LINKING)
|
||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
if(WIN32)
|
||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(OpenMP)
|
||||
if (OPENMP_FOUND)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Looking for external libraries
|
||||
|
@ -94,44 +108,33 @@ if(NOT LIB_JSON)
|
|||
message(FATAL_ERROR "JSON library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there")
|
||||
endif()
|
||||
|
||||
find_library(LIB_LAPACK
|
||||
NAMES lapack
|
||||
find_library(BLAS_LIB
|
||||
NAMES openblas mkl blas
|
||||
PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS})
|
||||
if(NOT LIB_LAPACK)
|
||||
message(FATAL_ERROR "LAPACK library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there")
|
||||
if(NOT BLAS_LIB)
|
||||
message(FATAL_ERROR "BLAS library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there")
|
||||
endif()
|
||||
|
||||
find_library(LIB_BLAS
|
||||
NAMES blas
|
||||
PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS})
|
||||
if(NOT LIB_BLAS)
|
||||
message(FATAL_ERROR "BLAS library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there")
|
||||
endif()
|
||||
|
||||
find_library(LIB_THREADS
|
||||
NAMES pthread
|
||||
PATHS ${QASM_SIMULATOR_CPP_EXTERNAL_LIBS})
|
||||
if(NOT LIB_THREADS)
|
||||
message(FATAL_ERROR "Pthreads library not found!. Please provide with a USER_LIB_PATH to CMake so it can be searched there")
|
||||
endif()
|
||||
|
||||
set(LIBRARIES PRIVATE ${LIB_BLAS}
|
||||
${LIB_LAPACK}
|
||||
${LIB_THREADS})
|
||||
|
||||
set(LIBRARIES PRIVATE ${BLAS_LIB})
|
||||
|
||||
# Linking
|
||||
target_link_libraries(qasm_simulator_cpp ${LIBRARIES})
|
||||
|
||||
set(QASM_SIMULATOR_CPP_OUTPUT_DIR $<TARGET_FILE_DIR:qasm_simulator_cpp>
|
||||
CACHE INTERNAL "Output directory for building QISKit C++ Simulator")
|
||||
|
||||
if(MINGW)
|
||||
set(QASM_SIMULATOR_CPP_THIRD_PARTY_DLLS
|
||||
"${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libblas.dll"
|
||||
"${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libgfortran_64-3.dll"
|
||||
"${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win64/dll/libquadmath_64-0.dll"
|
||||
CACHE INTERNAL "Third-party C++ Simulator DLLs")
|
||||
# TODO Windows 32 bits builds are not supported yet
|
||||
set(ARCH_BITS "64")
|
||||
if(ARCH32)
|
||||
set(ARCH_BITS "32")
|
||||
endif()
|
||||
|
||||
# Copying necessary .dll files to output
|
||||
# TODO look into "install()" CMake function
|
||||
if(WIN32) # Windows 64 bits is also true here
|
||||
set(QASM_SIMULATOR_CPP_THIRD_PARTY_DLLS
|
||||
"${QASM_SIMULATOR_CPP_SRC_DIR}/third-party/win${ARCH_BITS}/dll/openblas.dll"
|
||||
CACHE INTERNAL "Third-party C++ Simulator DLLs")
|
||||
foreach(dll_file ${QASM_SIMULATOR_CPP_THIRD_PARTY_DLLS})
|
||||
add_custom_command(
|
||||
TARGET qasm_simulator_cpp
|
||||
|
@ -146,7 +149,7 @@ if(MINGW)
|
|||
${QASM_SIMULATOR_CPP_OUTPUT_DIR}/${FINAL_FILE})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
# Tests
|
||||
# TODO: Enable them when ready
|
||||
#add_subdirectory(${QASM_SIMULATOR_CPP_DIR}/test)
|
||||
|
|
|
@ -28,6 +28,8 @@ limitations under the License.
|
|||
#include <complex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "base_backend.hpp"
|
||||
#include "qubit_vector.hpp"
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue