Skip to content

Commit a9cc303

Browse files
committed
build: Streamline project build
1 parent 32d49db commit a9cc303

File tree

9 files changed

+71
-64
lines changed

9 files changed

+71
-64
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
cmake_minimum_required (VERSION 3.16.3)
2-
project (TESTCONTAINERS-C)
1+
cmake_minimum_required (VERSION 3.26)
2+
project (TESTCONTAINERS-C
3+
VERSION 0.1.0
4+
DESCRIPTION "Testcontainers for C and other native languages"
5+
LANGUAGES C CXX
6+
)
37

48
include(CTest)
59

6-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/testcontainers-c)
7-
810
add_subdirectory(testcontainers-c)
911
add_subdirectory(modules)
1012
if(NOT DEFINED SKIP_DEMOS)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
project(testcontainers-c-generic-container-demo
2-
VERSION 0.0.1
3-
DESCRIPTION "Demonstrates usage of the generic container API in a simple main app")
1+
cmake_minimum_required (VERSION 3.26)
2+
project (generic-container-demo
3+
VERSION 0.1.0
4+
DESCRIPTION "Demonstrates usage of the generic container API in a simple main app"
5+
LANGUAGES C
6+
)
47

5-
set(TARGET_OUT demo_generic_container.out)
8+
set(TARGET_OUT ${PROJECT_NAME}.out)
69

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

1112
# Vanilla Demo for WireMock
1213
add_executable(${TARGET_OUT} generic_container_demo.c)
13-
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
1414
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
1515
add_test(NAME generic_container_demo COMMAND ${TARGET_OUT})

demo/google-test/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Google Test demo
22
# This is based on https://google.github.io/googletest/quickstart-cmake.html
3-
project(google-test-demo
4-
VERSION 0.0.1
5-
DESCRIPTION "Demonstrates usage of Testcontainers C in Google Test")
3+
cmake_minimum_required (VERSION 3.26)
4+
project (google-test-demo
5+
VERSION 0.1.0
6+
DESCRIPTION "Demonstrates usage of Testcontainers C in Google Test"
7+
LANGUAGES CXX
8+
)
69

710
set(TARGET_OUT ${PROJECT_NAME}.out)
811

@@ -22,7 +25,6 @@ enable_testing()
2225
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
2326

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

demo/wiremock/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
project(testcontainers-c-wiremock-demo
2-
VERSION 0.0.1
3-
DESCRIPTION "Demonstrates usage of the WireMock module for Testcontainers C in a simple main app")
1+
cmake_minimum_required (VERSION 3.26)
2+
project (wiremock-demo
3+
VERSION 0.1.0
4+
DESCRIPTION "Demonstrates usage of the WireMock module for Testcontainers C in a simple main app"
5+
LANGUAGES C
6+
)
47

58
set(TARGET_OUT demo_wiremock_module.out)
69

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

1112
# WireMock Module demo
1213
add_executable(${TARGET_OUT} wiremock_module_demo.c)
13-
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
14-
target_include_directories(${TARGET_OUT} PRIVATE ${testcontainers-c-wiremock_SOURCE_DIR})
1514
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
1615
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c-wiremock)
1716
add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT})

docs/c/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ enable_testing()
121121
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
122122
123123
add_executable(${TARGET_OUT} mytest.cpp)
124-
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
125124
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
126125
add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT})
127126
```

modules/wiremock/CMakeLists.txt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
2-
cmake_minimum_required(VERSION 3.9)
3-
project(testcontainers-c-wiremock VERSION 0.0.1
4-
DESCRIPTION "WireMock module for Testcontainers C")
5-
61
include(GNUInstallDirs)
72

8-
add_library(${PROJECT_NAME} SHARED
9-
testcontainers-c-wiremock.h
3+
set(TARGET testcontainers-c-wiremock)
4+
set(TARGET_NAME ${TARGET})
5+
set(TARGET_DESCRIPTION "Wiremock testcontainer abstractions for C")
6+
set(TARGET_VERSION ${PROJECT_VERSION})
7+
8+
add_library(${TARGET} SHARED
109
impl.c
1110
)
12-
add_dependencies(${PROJECT_NAME} testcontainers-c)
1311

14-
include_directories(${testcontainers-c_SOURCE_DIR})
12+
target_sources(${TARGET}
13+
PUBLIC FILE_SET HEADERS
14+
BASE_DIRS .
15+
FILES testcontainers-c-wiremock.h
16+
)
17+
18+
target_link_libraries(${TARGET} PRIVATE testcontainers-c)
1519

16-
set_target_properties(${PROJECT_NAME} PROPERTIES
17-
VERSION ${PROJECT_VERSION}
20+
set_target_properties(${TARGET} PROPERTIES
21+
VERSION ${TARGET_VERSION}
1822
PUBLIC_HEADER testcontainers-c-wiremock.h)
1923

20-
configure_file(cmake.pc.in ${PROJECT_NAME}.pc @ONLY)
21-
install(TARGETS ${PROJECT_NAME}
24+
configure_file(cmake.pc.in ${TARGET}.pc @ONLY)
25+
install(TARGETS ${TARGET}
2226
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
2327
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
24-
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
28+
install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

modules/wiremock/cmake.pc.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ exec_prefix=@CMAKE_INSTALL_PREFIX@
33
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
44
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
55

6-
Name: @PROJECT_NAME@
7-
Description: @PROJECT_DESCRIPTION@
8-
Version: @PROJECT_VERSION@
6+
Name: @TARGET_NAME@
7+
Description: @TARGET_DESCRIPTION@
8+
Version: @TARGET_VERSION@
99

1010
Requires:
11-
Libs: -L${libdir} -lmylib
11+
Libs: -L${libdir}
1212
Cflags: -I${includedir}

testcontainers-c/CMakeLists.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
cmake_minimum_required(VERSION 3.0)
2-
project(testcontainers-c VERSION 0.0.1
3-
DESCRIPTION "Testcontainers C library")
4-
51
include(GNUInstallDirs)
62

73
set(SRCS testcontainers-c.go)
84

9-
set(TARGET testcontainers-c-shim)
10-
set(TARGET_LIB testcontainers-c.so)
11-
set(TARGET_HEADER testcontainers-c.h)
5+
set(SHIM_TARGET testcontainers-c-shim)
6+
set(SHIM_TARGET_LIB testcontainers-c.so)
7+
set(SHIM_TARGET_HEADER testcontainers-c.h)
128

13-
add_custom_command(OUTPUT ${TARGET_LIB} ${TARGET_HEADER}
9+
add_custom_command(OUTPUT ${SHIM_TARGET_LIB} ${SHIM_TARGET_HEADER}
1410
DEPENDS ${SRCS}
1511
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
1612
COMMAND env GOPATH=${GOPATH} go build -buildmode=c-shared
17-
-o "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB}"
13+
-o "${CMAKE_CURRENT_BINARY_DIR}/${SHIM_TARGET_LIB}"
1814
${CMAKE_GO_FLAGS} ${SRCS}
1915
COMMENT "Building Testcontainers C shared library")
2016

21-
add_custom_target(${TARGET} DEPENDS ${TARGET_LIB} ${TARGET_HEADER})
17+
add_custom_target(${SHIM_TARGET} DEPENDS ${SHIM_TARGET_LIB} ${SHIM_TARGET_HEADER})
18+
19+
set(TARGET testcontainers-c)
20+
set(TARGET_NAME ${TARGET})
21+
set(TARGET_DESCRIPTION ${PROJECT_DESCRIPTION})
22+
set(TARGET_VERSION ${PROJECT_VERSION})
2223

23-
add_library(${PROJECT_NAME} SHARED IMPORTED GLOBAL)
24-
add_dependencies(${PROJECT_NAME} ${TARGET})
25-
set_target_properties(${PROJECT_NAME} PROPERTIES
24+
add_library(${TARGET} SHARED IMPORTED GLOBAL)
25+
add_dependencies(${TARGET} ${SHIM_TARGET})
26+
set_target_properties(${TARGET} PROPERTIES
2627
LINKER_LANGUAGE C
27-
VERSION ${PROJECT_VERSION}
28+
VERSION ${TARGET_VERSION}
2829
PUBLIC_HEADER testcontainers-c.h
29-
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_LIB}
30+
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${SHIM_TARGET_LIB}
3031
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
3132

32-
configure_file(cmake.pc.in ${PROJECT_NAME}.pc @ONLY)
33-
install(FILES ${TARGET_LIB}
33+
configure_file(cmake.pc.in ${TARGET}.pc @ONLY)
34+
install(FILES ${SHIM_TARGET_LIB}
3435
DESTINATION ${CMAKE_INSTALL_LIBDIR})
35-
install(FILES ${TARGET_HEADER}
36+
install(FILES ${SHIM_TARGET_HEADER}
3637
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
37-
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
38+
install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

testcontainers-c/cmake.pc.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ exec_prefix=@CMAKE_INSTALL_PREFIX@
33
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
44
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
55

6-
Name: @PROJECT_NAME@
7-
Description: @PROJECT_DESCRIPTION@
8-
Version: @PROJECT_VERSION@
6+
Name: @TARGET_NAME@
7+
Description: @TARGET_DESCRIPTION@
8+
Version: @TARGET_VERSION@
99

1010
Requires:
11-
Libs: -L${libdir} -lmylib
11+
Libs: -L${libdir}
1212
Cflags: -I${includedir}

0 commit comments

Comments
 (0)