diff --git a/CMakeLists.txt b/CMakeLists.txt index b6183a0..64fd43e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/demo/generic-container/CMakeLists.txt b/demo/generic-container/CMakeLists.txt index 7559e5f..716c9bd 100644 --- a/demo/generic-container/CMakeLists.txt +++ b/demo/generic-container/CMakeLists.txt @@ -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}) diff --git a/demo/google-test/CMakeLists.txt b/demo/google-test/CMakeLists.txt index ede0901..4d0bd09 100644 --- a/demo/google-test/CMakeLists.txt +++ b/demo/google-test/CMakeLists.txt @@ -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) @@ -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) @@ -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) diff --git a/demo/wiremock/CMakeLists.txt b/demo/wiremock/CMakeLists.txt index b048221..d1e9370 100644 --- a/demo/wiremock/CMakeLists.txt +++ b/demo/wiremock/CMakeLists.txt @@ -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}) diff --git a/docs/c/README.md b/docs/c/README.md index dd5da70..33ca908 100644 --- a/docs/c/README.md +++ b/docs/c/README.md @@ -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}) ``` diff --git a/modules/wiremock/CMakeLists.txt b/modules/wiremock/CMakeLists.txt index 640928a..6527ca6 100644 --- a/modules/wiremock/CMakeLists.txt +++ b/modules/wiremock/CMakeLists.txt @@ -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) diff --git a/modules/wiremock/cmake.pc.in b/modules/wiremock/cmake.pc.in index 9b15f62..8c83ec9 100644 --- a/modules/wiremock/cmake.pc.in +++ b/modules/wiremock/cmake.pc.in @@ -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} diff --git a/testcontainers-c/CMakeLists.txt b/testcontainers-c/CMakeLists.txt index 9583bd6..784274f 100644 --- a/testcontainers-c/CMakeLists.txt +++ b/testcontainers-c/CMakeLists.txt @@ -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) diff --git a/testcontainers-c/cmake.pc.in b/testcontainers-c/cmake.pc.in index 9b15f62..8c83ec9 100644 --- a/testcontainers-c/cmake.pc.in +++ b/testcontainers-c/cmake.pc.in @@ -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}