Skip to content

Commit

Permalink
Add document for build shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
qgymib committed Jul 31, 2024
1 parent cb1fcf9 commit ff9b767
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ option(CUTEST_NO_UINTPTR_SUPPORT
"Disable uinttpr_t support."
OFF
)
option(CUTEST_USE_DLL
"Build as shared library."
OFF
)

###############################################################################
# Functions
Expand All @@ -82,9 +86,12 @@ endfunction()
# Setup library
###############################################################################

add_library(${PROJECT_NAME}
"src/cutest.c"
)
if (CUTEST_USE_DLL)
add_library(${PROJECT_NAME} SHARED "src/cutest.c")
target_compile_options(${PROJECT_NAME} PUBLIC -DCUTEST_USE_DLL)
else()
add_library(${PROJECT_NAME} "src/cutest.c")
endif()

target_include_directories(${PROJECT_NAME}
PUBLIC
Expand Down
32 changes: 29 additions & 3 deletions include/cutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,29 @@ extern "C" {
#define TEST_C_API
#endif

/**
* @defgroup TEST_BUILDING_DLL Build shared library
*
* By default this library is build for static library. If you want to build as
* shared library, you must enable corresponding compile options.
*
* ## If you are using CMake
*
* Enable `CUTEST_USE_DLL` option
* ```cmake
* set(CUTEST_USE_DLL ON)
* add_subdirectory(cutest)
* ```
*
* ## If you are using other compile system
*
* 1. Add `CUTEST_USE_DLL` to build cutest.
* 2. Add `CUTEST_USE_DLL` to your **own** codebase.
*
* @{
*/
#if defined(_WIN32) || defined(__CYGWIN__)
# if defined(CUTEST_DLL_EXPORT)
# if defined(CUTEST_USE_DLL)
# if defined(CUTEST_BUILDING_DLL)
# if defined(__GNUC__) || defined(__clang__)
# define CUTEST_API __attribute__ ((dllexport))
Expand All @@ -149,6 +170,10 @@ extern "C" {
#else
# define CUTEST_API
#endif
/**
* END GROUP: TEST_BUILDING_DLL
* @}
*/

/**
* @example main.c
Expand Down Expand Up @@ -466,7 +491,7 @@ extern "C" {
/** @endcond */

/**
* Group: TEST_DEFINE
* END GROUP: TEST_DEFINE
* @}
*/

Expand Down Expand Up @@ -1926,11 +1951,12 @@ void cutest_porting_setjmp(cutest_porting_setjmp_fn execute, void* data);
int cutest_porting_compare_floating_number(int type, const void* v1, const void* v2);

/**
* Group: TEST_FLOATING_NUMBER
* END GROUP: TEST_FLOATING_NUMBER
* @}
*/

/**
* END GROUP: TEST_PORTING
* @}
*/

Expand Down

0 comments on commit ff9b767

Please sign in to comment.