Skip to content

Commit

Permalink
refactor: update to use latest asap template
Browse files Browse the repository at this point in the history
BREAKING
For large scale projects, it is important to properly scope the module's include
files. Therefore, now, to include from asap.contract, you should use
#include <asap/contract/...>

The target name for the `contract` module is now `asap.contract`.

The target name for the `contract-ut` module is now `asap.contract-ut`.
  • Loading branch information
abdes committed Oct 21, 2024
1 parent d9698f4 commit 5207fcf
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"console": "externalTerminal"
}
]
}
}
22 changes: 9 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV)
if(NOT GIT_SHA1)
set(GIT_REV "0")
set(GIT_REV "0")
endif()

# Meta information about the project
Expand All @@ -53,12 +53,8 @@ set(META_VERSION_MAJOR "1")
set(META_VERSION_MINOR "0")
set(META_VERSION_PATCH "2")
set(META_VERSION_REVISION "${GIT_REV}")
set(META_VERSION
"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
)
set(META_NAME_VERSION
"${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})"
)
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
# cmake-format: on

string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
Expand All @@ -67,10 +63,10 @@ string(TOLOWER ${META_PROJECT_ID} META_PROJECT_ID_LOWER)

# Determine if this is built as a subproject or if it is the master project.
if(NOT DEFINED ${META_PROJECT_ID}_IS_MASTER_PROJECT)
set(${META_PROJECT_ID}_IS_MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(${META_PROJECT_ID}_IS_MASTER_PROJECT ON)
endif()
set(${META_PROJECT_ID}_IS_MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(${META_PROJECT_ID}_IS_MASTER_PROJECT ON)
endif()
endif()

# Push the project on the hierarchy stack after we have determined if it is a
Expand Down Expand Up @@ -277,7 +273,7 @@ endif()
# ------------------------------------------------------------------------------

if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_MACOSX_RPATH ON)
endif()

# Set runtime path
Expand All @@ -287,7 +283,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

if(NOT SYSTEM_DIR_INSTALL)
set(CMAKE_INSTALL_RPATH "$ORIGIN/${ASAP_INSTALL_LIB}")
set(CMAKE_INSTALL_RPATH "$ORIGIN/${ASAP_INSTALL_LIB}")
endif()

# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Folder.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c5180220_002Ddc42_002D434c_002D8729_002D2ed3d6c70d09/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;asap-contract&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="D:\dev\projects\asap_repos\asap-contract" Presentation="&amp;lt;asap-contract&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
172 changes: 88 additions & 84 deletions contract-ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#

set(my_name "contract-ut")
set(my_name "asap.contract-ut")
asap_push_module("${my_name}")

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -36,7 +36,7 @@ asap_declare_module(
# Main module target
# ------------------------------------------------------------------------------

set(MODULE_TARGET_NAME "asap_contract-ut")
set(MODULE_TARGET_NAME "${my_name}")

asap_add_library(
${MODULE_TARGET_NAME}
Expand All @@ -45,22 +45,23 @@ asap_add_library(
WARNING
SOURCES
# Headers
"include/contract/ut/gtest.h"
"include/contract/ut/framework.h"
"include/asap/contract/ut/gtest.h"
"include/asap/contract/ut/framework.h"
# Sources
"src/contract-ut.cpp"
)

target_include_directories(
${MODULE_TARGET_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
${MODULE_TARGET_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(${MODULE_TARGET_NAME} PUBLIC asap::contract)
target_link_libraries(${MODULE_TARGET_NAME} PUBLIC asap.contract)

target_compile_features(${MODULE_TARGET_NAME} PUBLIC cxx_std_17)

Expand All @@ -76,94 +77,97 @@ asap_create_module_config_files()
# ------------------------------------------------------------------------------

if(ASAP_BUILD_TESTS)
# Add support for (optional) code quality tools
asap_add_sanitizers(${MODULE_TARGET_NAME})
# Add support for (optional) code quality tools
asap_add_sanitizers(${MODULE_TARGET_NAME})

add_subdirectory(test)
add_subdirectory(test)
endif()

# ------------------------------------------------------------------------------
# API Documentation
# ------------------------------------------------------------------------------

asap_with_doxygen(
MODULE_NAME
${MODULE_TARGET_NAME}
VERSION
${META_MODULE_VERSION}
TITLE
"\"Unit testing for contracts\""
BRIEF
"\"Provides optional helpers to unit test contract checks without death tests.\""
INPUT_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include"
)
if(ASAP_WITH_DOXYGEN)
asap_with_doxygen(
MODULE_NAME
${MODULE_TARGET_NAME}
VERSION
${META_MODULE_VERSION}
TITLE
"\"Unit testing for contracts\""
BRIEF
"\"Provides optional helpers to unit test contract checks without death tests.\""
INPUT_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include"
)
endif()

# ==============================================================================
# Deployment instructions
# ==============================================================================

if(${META_PROJECT_ID}_INSTALL)
set(TARGETS_EXPORT_NAME "${MODULE_TARGET_NAME}Targets")
set(runtime "${MODULE_TARGET_NAME}_runtime")
set(dev "${MODULE_TARGET_NAME}_dev")

# Library
install(
TARGETS ${MODULE_TARGET_NAME}
EXPORT "${TARGETS_EXPORT_NAME}"
COMPONENT dev
RUNTIME
DESTINATION ${ASAP_INSTALL_BIN}
COMPONENT ${runtime}
LIBRARY
DESTINATION ${ASAP_INSTALL_SHARED}
COMPONENT ${runtime}
ARCHIVE
DESTINATION ${ASAP_INSTALL_LIB}
COMPONENT ${dev}
)

# Header files
set(TARGETS_EXPORT_NAME "${MODULE_TARGET_NAME}Targets")
set(runtime "${MODULE_TARGET_NAME}_runtime")
set(dev "${MODULE_TARGET_NAME}_dev")

# Library
install(
TARGETS
${MODULE_TARGET_NAME}
EXPORT "${TARGETS_EXPORT_NAME}"
COMPONENT
dev
RUNTIME
DESTINATION ${ASAP_INSTALL_BIN}
COMPONENT ${runtime}
LIBRARY
DESTINATION ${ASAP_INSTALL_SHARED}
COMPONENT ${runtime}
ARCHIVE
DESTINATION ${ASAP_INSTALL_LIB}
COMPONENT ${dev}
)

# Header files
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/include/${META_MODULE_NAME}
DESTINATION ${ASAP_INSTALL_INCLUDE}
COMPONENT ${dev}
FILES_MATCHING
PATTERN
"*.h"
)

# Generated header files
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${META_MODULE_NAME} DESTINATION ${ASAP_INSTALL_INCLUDE} COMPONENT ${dev})

# Target config
install(
EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE ${META_PROJECT_NAME}::
DESTINATION ${ASAP_INSTALL_CMAKE}/${META_MODULE_NAME}
COMPONENT ${dev}
)

# Package configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET_NAME}ConfigVersion.cmake
DESTINATION ${ASAP_INSTALL_CMAKE}/${META_MODULE_NAME}
)

# Docs
if(EXISTS ${SPHINX_BUILD_DIR}/${MODULE_TARGET_NAME})
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${META_MODULE_NAME}
DESTINATION ${ASAP_INSTALL_INCLUDE}
COMPONENT ${dev}
FILES_MATCHING
PATTERN "*.h"
DIRECTORY
${SPHINX_BUILD_DIR}/${MODULE_TARGET_NAME}
DESTINATION ${ASAP_INSTALL_DOC}
COMPONENT ${MODULE_TARGET_NAME}_docs
)

# Generated header files
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${META_MODULE_NAME}
DESTINATION ${ASAP_INSTALL_INCLUDE}
COMPONENT ${dev}
)

# Target config
install(
EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE ${META_PROJECT_NAME}::
DESTINATION ${ASAP_INSTALL_CMAKE}/${META_MODULE_NAME}
COMPONENT ${dev}
)

# Package configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET_NAME}ConfigVersion.cmake
DESTINATION ${ASAP_INSTALL_CMAKE}/${META_MODULE_NAME}
)

# Docs
if(EXISTS ${SPHINX_BUILD_DIR}/${MODULE_TARGET_NAME})
install(
DIRECTORY ${SPHINX_BUILD_DIR}/${MODULE_TARGET_NAME}
DESTINATION ${ASAP_INSTALL_DOC}
COMPONENT ${MODULE_TARGET_NAME}_docs
)
endif()
endif()
endif()

asap_pop_module("${my_name}")
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <csetjmp>

#include <contract-ut/asap_contract-ut_export.h>
#include <asap/contract-ut/api_export.h>

namespace asap::contract {

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions contract-ut/src/contract-ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <csetjmp>
#include <iostream>

#include <contract/contract.h>
#include <contract/ut/framework.h>
#include <asap/contract/contract.h>
#include <asap/contract/ut/framework.h>

namespace asap::contract {

Expand Down
7 changes: 4 additions & 3 deletions contract-ut/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# If running with google sanitizers, skill all these targets as they are abort
# and segmentation fault tests that do not make sense to run under sanitizers
if(ASAP_WITH_GOOGLE_ASAN OR ASAP_WITH_GOOGLE_UBSAN OR ASAP_WITH_GOOGLE_TSAN)
return()
return()
endif()

# ------------------------------------------------------------------------------
Expand All @@ -34,8 +34,9 @@ asap_add_test(
"contract_ut_gtest_test.cpp"
"main.cpp"
LINK
asap::contract-ut
asap::common
asap.common
asap.contract
asap.contract-ut
gtest
gmock
COMMENT
Expand Down
4 changes: 2 additions & 2 deletions contract-ut/test/contract_ut_gtest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <contract/ut/framework.h>
#include <contract/ut/gtest.h>
#include <asap/contract/ut/framework.h>
#include <asap/contract/ut/gtest.h>

using asap::contract::testing::TestAssertDefault;
using asap::contract::testing::TestEnsureDefault;
Expand Down
2 changes: 1 addition & 1 deletion contract-ut/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <gtest/gtest.h>

#include <contract/ut/framework.h>
#include <asap/contract/ut/framework.h>

auto main(int argc, char** argv) -> int
{
Expand Down
2 changes: 1 addition & 1 deletion contract-ut/test/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "test_helper.h"

#include <contract/contract.h>
#include <asap/contract/contract.h>

namespace asap::contract::testing {

Expand Down
Loading

0 comments on commit 5207fcf

Please sign in to comment.