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

Tweak build for QIREE (downstream) #587

Closed
wants to merge 2 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ set(PATCH_VERSION 0)
# their CMake builds, and pass -DXACC_DIR=/path/to/install/xacc
# and CMake loads include paths, libs, etc
configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config.cmake" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config-version.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config-version.cmake" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/xacc-config.cmake" DESTINATION .)
install(FILES "${CMAKE_BINARY_DIR}/xacc-config-version.cmake" DESTINATION .)
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/format.cmake" DESTINATION share/xacc/)
install(FILES "${CMAKE_SOURCE_DIR}/tpls/mpark-variant/variant.hpp" DESTINATION include/xacc/)
install(FILES "${CMAKE_SOURCE_DIR}/tpls/taocpp/operators.hpp" DESTINATION include/xacc/)
Expand Down
8 changes: 8 additions & 0 deletions cmake/xacc-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(PACKAGE_VERSION "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@")
# The quotes for the right operand are intentional here: if CMake executes this
# file without ${PACKAGE_FIND_VERSION} set, then if() will still get three
# operands. Without the quotes, if() will only get two operands in that case,
# throwing an error.
if(${PACKAGE_VERSION} VERSION_GREATER_EQUAL "${PACKAGE_FIND_VERSION}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this behavior is right. For reference, here is the LLVMConfigVersion.cmake on my system:

set(PACKAGE_VERSION "18.1.6")

# LLVM is API-compatible only with matching major.minor versions
# and patch versions not less than that requested.
if("18.1" VERSION_EQUAL
    "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
   AND NOT "6" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
  set(PACKAGE_VERSION_COMPATIBLE 1)
  if("6" VERSION_EQUAL
      "${PACKAGE_FIND_VERSION_PATCH}")
    set(PACKAGE_VERSION_EXACT 1)
  endif()
endif()

Note that it's doing more careful logic there. If we release XACC 2.0 that breaks everything, then maybe this should not pass (it currently would say "ok, looks compatible to me")

set(PACKAGE_VERSION_COMPATIBLE 1)
endif()
4 changes: 0 additions & 4 deletions cmake/xacc-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ if(NOT TARGET format)
endif()

# Set version info
set(XACC_VERSION_MAJOR @MAJOR_VERSION@)
set(XACC_VERSION_MINOR @MINOR_VERSION@)
set(XACC_VERSION_PATCH @PATCH_VERSION@)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are set by find_package() automatically. See the end of this section: https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection

set(XACC_VERSION_SUFFIX @XACC_BUILD_VERSION@)
set(XACC_VERSION "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@-@XACC_BUILD_VERSION@")

set(XACC_LIBRARY_DIR "${XACC_ROOT}/lib")

Expand Down
62 changes: 32 additions & 30 deletions tpls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,43 @@ if (NOT XACC_USE_EXTERNAL_CPR)
add_subdirectory(cpr)
endif()

# Googletest
set(BUILD_SHARED_LIBS TRUE)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY "https://github.com/google/googletest"
GIT_TAG release-1.12.1
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
if(XACC_BUILD_TESTS)
# Googletest
set(BUILD_SHARED_LIBS TRUE)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY "https://github.com/google/googletest"
GIT_TAG release-1.12.1
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

if(APPLE)
set_target_properties(gtest PROPERTIES INSTALL_RPATH "@loader_path")
set_target_properties(gtest_main PROPERTIES INSTALL_RPATH "@loader_path")
else()
set_target_properties(gtest PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(gtest_main PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
if(APPLE)
set_target_properties(gtest PROPERTIES INSTALL_RPATH "@loader_path")
set_target_properties(gtest_main PROPERTIES INSTALL_RPATH "@loader_path")
else()
set_target_properties(gtest PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(gtest_main PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()

set(GTEST_FOUND TRUE)
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
set(GTEST_INCLUDE_DIRS ${googletest_SOURCE_DIR}/googletest/include)
set(GTEST_FOUND TRUE)
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
set(GTEST_INCLUDE_DIRS ${googletest_SOURCE_DIR}/googletest/include)

set_property(TARGET gtest PROPERTY FOLDER "tests/gtest")
set_property(TARGET gtest_main PROPERTY FOLDER "tests/gtest")
set_property(TARGET gtest PROPERTY FOLDER "tests/gtest")
set_property(TARGET gtest_main PROPERTY FOLDER "tests/gtest")

set_cache_variable(GTEST_FOUND "Set if libgtest was found or built")
set_cache_variable(GTEST_LIBRARIES "Location of libgtest")
set_cache_variable(GTEST_MAIN_LIBRARIES "Location of libgtest-main")
set_cache_variable(GTEST_BOTH_LIBRARIES "Location of both gtest libraries")
set_cache_variable(GTEST_INCLUDE_DIRS "Location of gtest include files")
set_cache_variable(GTEST_FOUND "Set if libgtest was found or built")
set_cache_variable(GTEST_LIBRARIES "Location of libgtest")
set_cache_variable(GTEST_MAIN_LIBRARIES "Location of libgtest-main")
set_cache_variable(GTEST_BOTH_LIBRARIES "Location of both gtest libraries")
set_cache_variable(GTEST_INCLUDE_DIRS "Location of gtest include files")

install(DIRECTORY "${googletest_SOURCE_DIR}/googletest/include/gtest" DESTINATION include/gtest )
install(DIRECTORY "${googletest_SOURCE_DIR}/googletest/include/gtest" DESTINATION include/gtest )
endif()

set(BUILD_SHARED_LIBS FALSE)
set(BOOST_LIBS_OPTIONAL graph CACHE STRING "" FORCE)
Expand Down
Loading