Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source install #69

Merged
merged 12 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ jobs:
sudo cmake --install build
fi

- name: Configure standalone example
run: |
cmake -S examples/standalone -B examples/standalone/build

- name: Build standalone example
run: |
cmake --build examples/standalone/build --target standalone

- name: Run standalone example
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
./examples/standalone/build/${{env.BUILD_TYPE}}/standalone.exe --version
else
./examples/standalone/build/standalone --version
fi

- name: Build unit tests
shell: bash
run: |
Expand Down
10 changes: 9 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Pre-release
- `cmake --build build --target install` now installs staq's source code in
addition to the binaries
- Renamed the "examples" directory to "misc"
- Moved "qpu_specs" and "scripts" directories to "misc"
- Added standalone source code example (requires staq installation) in the
"examples/standalone" directory

Version 3.3
- Implemented the grid synth rotation synthesizer algorithm
https://arxiv.org/abs/1403.2975, enabled only when the GNU MP library is
Expand All @@ -6,7 +14,7 @@ Version 3.3

Version 3.2.3 - 14 August 2023
- Minor bugfix in pystaq setup.py that prevented pip install from remote
- Docker update, see the ["docker/"] directory
- Docker update, see the ["docker"] directory

Version 3.2.2 - 12 June 2023
- This is a maintenance release
Expand Down
40 changes: 32 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ add_compile_definitions(PROJECT_ROOT_DIR="${PROJECT_SOURCE_DIR}")

#### Force clang to use libc++
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
add_compile_options("-stdlib=libc++")
endif ()

#### Windows issues with Microsoft Visual Studio
if (MSVC)
include_directories(SYSTEM libs/pthreadwin32)
include_directories(SYSTEM third_party/libs/pthreadwin32)
add_compile_options(-bigobj)
add_compile_definitions(NOMINMAX)
if (MSVC_VERSION GREATER_EQUAL 1914)
Expand All @@ -38,15 +38,23 @@ if (MINGW OR CYGWIN)
endif ()

#### Libs
include_directories(SYSTEM libs)
include_directories(SYSTEM libs/third_party)

#### staq headers
add_library(libstaq INTERFACE)
target_compile_definitions(libstaq INTERFACE -DSTAQ_VERSION_NUM=${STAQ_VERSION_NUM})
target_compile_definitions(libstaq INTERFACE -DSTAQ_VERSION_STR="${STAQ_VERSION_STR}")
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/>)
#### qasmtools library
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/qasmtools/include/>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/qasmtools/include/>
$<INSTALL_INTERFACE:include/staq/>)
#### 3rd party libs
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libs>
$<INSTALL_INTERFACE:include/staq/third_party>)

#### Enable OpenQASM 2.0 Specs
option(USE_OPENQASM2_SPECS "Use OpenQASM 2.0 standard instead of Qiskit gate specifications" OFF)
Expand All @@ -60,11 +68,11 @@ endif ()

#### Compiler
set(COMPILER "staq")
add_executable(${COMPILER} ${PROJECT_SOURCE_DIR}/staq/main.cpp)
add_executable(${COMPILER} ${PROJECT_SOURCE_DIR}/src/staq/main.cpp)
target_link_libraries(${COMPILER} PUBLIC libstaq)

#### Additional command line tools
add_subdirectory(tools)
add_subdirectory(src/tools)

#### Unit testing
include(cmake/staq_unit_tests.cmake)
Expand All @@ -83,9 +91,23 @@ if (NOT CMAKE_BUILD_TYPE)
FORCE)
endif ()

#### Installation
#### Installation (binaries)
install(TARGETS ${COMPILER} DESTINATION ${CMAKE_INSTALL_BINDIR})

#### Installation (source)
set(STAQ_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}")
install(DIRECTORY include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY qasmtools/include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY libs/third_party DESTINATION ${STAQ_INSTALL_DIR})
install(TARGETS libstaq EXPORT staq_targets)
install(EXPORT staq_targets DESTINATION "lib/cmake/${PROJECT_NAME}")
include(CMakePackageConfigHelpers)
configure_package_config_file(
"cmake/staqConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake"
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake" DESTINATION "lib/cmake/${PROJECT_NAME}")

#### Uninstall
#### https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
#### UNIX/Linux: sudo cmake --build build --target uninstall
Expand All @@ -98,6 +120,8 @@ if (NOT TARGET uninstall)
if (NOT MSVC)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${STAQ_INSTALL_DIR}"
)
else ()
add_custom_target(uninstall
Expand Down
20 changes: 20 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ or in an Administrator Command Prompt (Windows)
cmake --build build --target (un)install
```

staq's source code will be installed in `/usr/local/include/staq`
(UNIX/UNIX-like systems), or in `C:\Program Files (x86)\staq` on Windows
systems. The paths may differ on your system. To use staq's source code, precede
all include paths by `staq` in your own code, i.e.,

```c++
#include <staq/qasmtools/parser/parser.hpp>
```

Third party header-only libraries need to be preceded by `third_party` when
including their corresponding header file(s), i.e.,

```c++
#include <staq/third_party/CLI/CLI.hpp>
```

See the
[standalone example](https://github.com/softwareQinc/staq/tree/main/examples/standalone)
for more details.

---

## macOS/Linux
Expand Down
4 changes: 4 additions & 0 deletions cmake/staqConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/staq_targets.cmake")
message(STATUS "Found staq's source code in @STAQ_INSTALL_DIR@")
5 changes: 4 additions & 1 deletion cmake/staq_uninstall.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ foreach(file ${files})
endif()
endforeach()

if("@MSVC@")
if(NOT "@MSVC@")
message(STATUS "Removing @CMAKE_INSTALL_PREFIX@/lib/cmake/@PROJECT_NAME@")
message(STATUS "Removing @STAQ_INSTALL_DIR@")
else()
message(STATUS "Removing @CMAKE_INSTALL_PREFIX@")
endif()
16 changes: 16 additions & 0 deletions examples/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.26)
project(standalone)
set(CMAKE_CXX_STANDARD 17)

# If staq's installation path was non-standard, i.e., specified by
#
# cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/installed/staq
#
# then uncomment the following line and replace the installation path with yours

# set(CMAKE_PREFIX_PATH "/path/to/installed/staq")

find_package(staq REQUIRED)

add_executable(standalone src/main.cpp)
target_link_libraries(standalone PUBLIC libstaq)
Loading