Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
cmake_minimum_required (VERSION 3.16.3)
project (TESTCONTAINERS-C)

include(CTest)

include_directories(${CMAKE_CURRENT_BINARY_DIR}/testcontainers-c)

add_subdirectory(testcontainers-c)
add_subdirectory(modules)
if(NOT DEFINED SKIP_DEMOS)
add_subdirectory(demo)
endif()
cmake_minimum_required (VERSION 3.26)
project (TESTCONTAINERS-C
VERSION 0.1.0
DESCRIPTION "Testcontainers for C and other native languages"
LANGUAGES C CXX
)

include(GNUInstallDirs)
include(CTest)

add_subdirectory(testcontainers-c)
add_subdirectory(modules)
if(NOT DEFINED SKIP_DEMOS)
add_subdirectory(demo)
endif()
14 changes: 7 additions & 7 deletions demo/generic-container/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
project(testcontainers-c-generic-container-demo
VERSION 0.0.1
DESCRIPTION "Demonstrates usage of the generic container API in a simple main app")
cmake_minimum_required (VERSION 3.26)
project (generic-container-demo
VERSION 0.1.0
DESCRIPTION "Demonstrates usage of the generic container API in a simple main app"
LANGUAGES C
)

set(TARGET_OUT demo_generic_container.out)
set(TARGET_OUT ${PROJECT_NAME}.out)

include_directories(${testcontainers-c_SOURCE_DIR})
# WORKING_DIRECTORY breaks shared lib loading
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# Vanilla Demo for WireMock
add_executable(${TARGET_OUT} generic_container_demo.c)
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
add_test(NAME generic_container_demo COMMAND ${TARGET_OUT})
13 changes: 8 additions & 5 deletions demo/google-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Google Test demo
# This is based on https://google.github.io/googletest/quickstart-cmake.html
project(google-test-demo
VERSION 0.0.1
DESCRIPTION "Demonstrates usage of Testcontainers C in Google Test")
cmake_minimum_required (VERSION 3.26)
project (google-test-demo
VERSION 0.1.0
DESCRIPTION "Demonstrates usage of Testcontainers C in Google Test"
LANGUAGES CXX
)

set(TARGET_OUT ${PROJECT_NAME}.out)

Expand All @@ -12,7 +15,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
Expand All @@ -21,7 +25,6 @@ enable_testing()
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_executable(${TARGET_OUT} test.cpp)
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
target_link_libraries(${TARGET_OUT} PRIVATE GTest::gtest_main)

Expand Down
37 changes: 18 additions & 19 deletions demo/wiremock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
project(testcontainers-c-wiremock-demo
VERSION 0.0.1
DESCRIPTION "Demonstrates usage of the WireMock module for Testcontainers C in a simple main app")

set(TARGET_OUT demo_wiremock_module.out)

include_directories(${testcontainers-c_SOURCE_DIR})
# WORKING_DIRECTORY breaks shared lib loading
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# WireMock Module demo
add_executable(${TARGET_OUT} wiremock_module_demo.c)
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
target_include_directories(${TARGET_OUT} PRIVATE ${testcontainers-c-wiremock_SOURCE_DIR})
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c-wiremock)

# FIXME: APi call crashes on the recent version
# add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT})
cmake_minimum_required (VERSION 3.26)
project (wiremock-demo
VERSION 0.1.0
DESCRIPTION "Demonstrates usage of the WireMock module for Testcontainers C in a simple main app"
LANGUAGES C
)

set(TARGET_OUT demo_wiremock_module.out)

file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# WireMock Module demo
add_executable(${TARGET_OUT} wiremock_module_demo.c)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c-wiremock)

# FIXME: API call crashes on the recent version
# add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT})
1 change: 0 additions & 1 deletion docs/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ enable_testing()
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_executable(${TARGET_OUT} mytest.cpp)
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT})
```
Expand Down
30 changes: 14 additions & 16 deletions modules/wiremock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
set(TARGET testcontainers-c-wiremock)
set(TARGET_NAME ${TARGET})
set(TARGET_DESCRIPTION "Wiremock testcontainer abstractions for C")
set(TARGET_VERSION ${PROJECT_VERSION})

cmake_minimum_required(VERSION 3.9)
project(testcontainers-c-wiremock VERSION 0.0.1
DESCRIPTION "WireMock module for Testcontainers C")

include(GNUInstallDirs)

add_library(${PROJECT_NAME} SHARED
testcontainers-c-wiremock.h
add_library(${TARGET} SHARED
impl.c
)
add_dependencies(${PROJECT_NAME} testcontainers-c)

include_directories(${testcontainers-c_SOURCE_DIR})
target_sources(${TARGET}
PUBLIC FILE_SET HEADERS
BASE_DIRS .
FILES testcontainers-c-wiremock.h
)

set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER testcontainers-c-wiremock.h)
target_link_libraries(${TARGET} PRIVATE testcontainers-c)

configure_file(cmake.pc.in ${PROJECT_NAME}.pc @ONLY)
install(TARGETS ${PROJECT_NAME}
configure_file(cmake.pc.in ${TARGET}.pc @ONLY)
install(TARGETS ${TARGET}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
8 changes: 4 additions & 4 deletions modules/wiremock/cmake.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Name: @TARGET_NAME@
Description: @TARGET_DESCRIPTION@
Version: @TARGET_VERSION@

Requires:
Libs: -L${libdir} -lmylib
Libs: -L${libdir}
Cflags: -I${includedir}
73 changes: 36 additions & 37 deletions testcontainers-c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
cmake_minimum_required(VERSION 3.0)
project(testcontainers-c VERSION 0.0.1
DESCRIPTION "Testcontainers C library")

include(GNUInstallDirs)

set(SRCS testcontainers-c.go)

set(TARGET testcontainers-c-shim)
set(TARGET_LIB testcontainers-c.so)
set(TARGET_HEADER testcontainers-c.h)

add_custom_command(OUTPUT ${TARGET_LIB} ${TARGET_HEADER}
DEPENDS ${SRCS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND env GOPATH=${GOPATH} go build -buildmode=c-shared
-o "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB}"
${CMAKE_GO_FLAGS} ${SRCS}
COMMENT "Building Testcontainers C shared library")

add_custom_target(${TARGET} DEPENDS ${TARGET_LIB} ${TARGET_HEADER})

add_library(${PROJECT_NAME} SHARED IMPORTED GLOBAL)
add_dependencies(${PROJECT_NAME} ${TARGET})
set_target_properties(${PROJECT_NAME} PROPERTIES
LINKER_LANGUAGE C
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER testcontainers-c.h
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})

configure_file(cmake.pc.in ${PROJECT_NAME}.pc @ONLY)
install(FILES ${TARGET_LIB}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${TARGET_HEADER}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
set(SRCS testcontainers-c.go)

set(SHIM_TARGET testcontainers-c-shim)
set(SHIM_TARGET_LIB testcontainers-c.so)
set(SHIM_TARGET_HEADER testcontainers-c.h)

add_custom_command(OUTPUT ${SHIM_TARGET_LIB} ${SHIM_TARGET_HEADER}
DEPENDS ${SRCS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND env GOPATH=${GOPATH} go build -buildmode=c-shared
-o "${CMAKE_CURRENT_BINARY_DIR}/${SHIM_TARGET_LIB}"
${CMAKE_GO_FLAGS} ${SRCS}
COMMENT "Building Testcontainers C shared library")

add_custom_target(${SHIM_TARGET} DEPENDS ${SHIM_TARGET_LIB} ${SHIM_TARGET_HEADER})

set(TARGET testcontainers-c)
set(TARGET_NAME ${TARGET})
set(TARGET_DESCRIPTION ${PROJECT_DESCRIPTION})
set(TARGET_VERSION ${PROJECT_VERSION})

add_library(${TARGET} SHARED IMPORTED GLOBAL)
add_dependencies(${TARGET} ${SHIM_TARGET})
set_target_properties(${TARGET} PROPERTIES
LINKER_LANGUAGE C
VERSION ${TARGET_VERSION}
PUBLIC_HEADER testcontainers-c.h
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${SHIM_TARGET_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})

configure_file(cmake.pc.in ${TARGET}.pc @ONLY)
install(FILES ${SHIM_TARGET_LIB}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${SHIM_TARGET_HEADER}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
8 changes: 4 additions & 4 deletions testcontainers-c/cmake.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Name: @TARGET_NAME@
Description: @TARGET_DESCRIPTION@
Version: @TARGET_VERSION@

Requires:
Libs: -L${libdir} -lmylib
Libs: -L${libdir}
Cflags: -I${includedir}