diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dc9bd3..1849df1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ project(${ARGTABLE3_PROJECT_NAME}) option(ARGTABLE3_ENABLE_CONAN "Enable Conan dependency manager" OFF) option(ARGTABLE3_ENABLE_TESTS "Enable unit tests" ON) -option(ARGTABLE3_USE_AMALGAMATION "Use the amalgamation distribution" OFF) option(ARGTABLE3_BUILD_STATIC_EXAMPLES "Build examples with the static argtable3 library" OFF) get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE) @@ -58,7 +57,6 @@ set(PROJECT_VERSION_TWEAK 0) set(ARGTABLE3_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}) set(ARGTABLE3_FULL_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_BUILD}) - if(ARGTABLE3_ENABLE_CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") conan_basic_setup(TARGETS) @@ -71,36 +69,24 @@ if(ARGTABLE3_ENABLE_TESTS) enable_testing() endif() -if(ARGTABLE3_USE_AMALGAMATION) - if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dist/argtable3.c") - execute_process( - COMMAND "${CMAKE_SOURCE_DIR}/tools/build" dist - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/tools" - ) - endif() - - set(ARGTABLE3_SRC_FILES - ${CMAKE_SOURCE_DIR}/dist/argtable3.c - ) -else() - set(ARGTABLE3_SRC_FILES - ${CMAKE_SOURCE_DIR}/src/arg_cmd.c - ${CMAKE_SOURCE_DIR}/src/arg_date.c - ${CMAKE_SOURCE_DIR}/src/arg_dbl.c - ${CMAKE_SOURCE_DIR}/src/arg_dstr.c - ${CMAKE_SOURCE_DIR}/src/arg_end.c - ${CMAKE_SOURCE_DIR}/src/arg_file.c - ${CMAKE_SOURCE_DIR}/src/arg_hashtable.c - ${CMAKE_SOURCE_DIR}/src/arg_int.c - ${CMAKE_SOURCE_DIR}/src/arg_lit.c - ${CMAKE_SOURCE_DIR}/src/arg_rem.c - ${CMAKE_SOURCE_DIR}/src/arg_rex.c - ${CMAKE_SOURCE_DIR}/src/arg_str.c - ${CMAKE_SOURCE_DIR}/src/arg_utils.c - ${CMAKE_SOURCE_DIR}/src/argtable3.c - ${CMAKE_SOURCE_DIR}/src/getopt_long.c - ) -endif() +set(ARGTABLE3_AMALGAMATION_SRC_FILE ${PROJECT_SOURCE_DIR}/dist/argtable3.c) +set(ARGTABLE3_SRC_FILES + ${PROJECT_SOURCE_DIR}/src/arg_cmd.c + ${PROJECT_SOURCE_DIR}/src/arg_date.c + ${PROJECT_SOURCE_DIR}/src/arg_dbl.c + ${PROJECT_SOURCE_DIR}/src/arg_dstr.c + ${PROJECT_SOURCE_DIR}/src/arg_end.c + ${PROJECT_SOURCE_DIR}/src/arg_file.c + ${PROJECT_SOURCE_DIR}/src/arg_hashtable.c + ${PROJECT_SOURCE_DIR}/src/arg_int.c + ${PROJECT_SOURCE_DIR}/src/arg_lit.c + ${PROJECT_SOURCE_DIR}/src/arg_rem.c + ${PROJECT_SOURCE_DIR}/src/arg_rex.c + ${PROJECT_SOURCE_DIR}/src/arg_str.c + ${PROJECT_SOURCE_DIR}/src/arg_utils.c + ${PROJECT_SOURCE_DIR}/src/argtable3.c + ${PROJECT_SOURCE_DIR}/src/getopt_long.c +) # Platform specific settings for installation if(UNIX) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 56b9d9f..44e0eb3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,9 +28,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################ - -# Get all the .c files in the examples directory -file(GLOB EXAMPLES_SOURCES RELATIVE ${CMAKE_SOURCE_DIR}/examples *.c) +file(GLOB EXAMPLES_SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/examples *.c) if(NOT ARGTABLE3_BUILD_STATIC_EXAMPLES) add_definitions(-Dargtable3_IMPORTS) @@ -42,8 +40,8 @@ endif() foreach(examples_src ${EXAMPLES_SOURCES}) string(REPLACE ".c" "" examplename ${examples_src}) - add_executable(${examplename} ${CMAKE_SOURCE_DIR}/examples/${examples_src}) - target_include_directories(${examplename} PRIVATE ${CMAKE_SOURCE_DIR}/src) + add_executable(${examplename} ${PROJECT_SOURCE_DIR}/examples/${examples_src}) + target_include_directories(${examplename} PRIVATE ${PROJECT_SOURCE_DIR}/src) if(ARGTABLE3_BUILD_STATIC_EXAMPLES) target_link_libraries(${examplename} argtable3_static ${ARGTABLE3_EXTRA_LIBS}) else() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1e2d6bb..e4a553c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,7 +28,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################ -set(TEST_SRC_FILES +set(TEST_PUBLIC_SRC_FILES testall.c testarglit.c testargstr.c @@ -37,17 +37,53 @@ set(TEST_SRC_FILES testargdbl.c testargfile.c testargrex.c - testarghashtable.c testargdstr.c testargcmd.c CuTest.c - ${ARGTABLE3_SRC_FILES} ) -add_executable(testall ${TEST_SRC_FILES}) -target_include_directories(testall PRIVATE ${CMAKE_SOURCE_DIR}/src) +set(TEST_SRC_FILES + ${TEST_PUBLIC_SRC_FILES} + testarghashtable.c +) + if(UNIX) - target_link_libraries(testall m) + set(ARGTABLE3_EXTRA_LIBS m) endif() -add_test(NAME testall COMMAND "$") +add_executable(test_shared ${TEST_PUBLIC_SRC_FILES}) +target_compile_definitions(test_shared PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY) +target_include_directories(test_shared PRIVATE ${PROJECT_SOURCE_DIR}/src) +target_link_libraries(test_shared argtable3 ${ARGTABLE3_EXTRA_LIBS}) +add_custom_command(TARGET test_shared POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" + "$" +) + +add_executable(test_static ${TEST_SRC_FILES}) +target_compile_definitions(test_static PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY) +target_include_directories(test_static PRIVATE ${PROJECT_SOURCE_DIR}/src) +target_link_libraries(test_static argtable3_static ${ARGTABLE3_EXTRA_LIBS}) + +add_executable(test_src ${TEST_SRC_FILES} ${ARGTABLE3_SRC_FILES}) +target_include_directories(test_src PRIVATE ${PROJECT_SOURCE_DIR}/src) +target_link_libraries(test_src ${ARGTABLE3_EXTRA_LIBS}) + +add_custom_command(OUTPUT ${ARGTABLE3_AMALGAMATION_SRC_FILE} + COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools" +) + +add_executable(test_amalgamation ${TEST_SRC_FILES} ${ARGTABLE3_AMALGAMATION_SRC_FILE}) +target_include_directories(test_amalgamation PRIVATE ${PROJECT_SOURCE_DIR}/src) +target_link_libraries(test_amalgamation ${ARGTABLE3_EXTRA_LIBS}) +add_custom_command(TARGET test_amalgamation PRE_BUILD + COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools" +) + +add_test(NAME test_shared COMMAND "$") +add_test(NAME test_static COMMAND "$") +add_test(NAME test_src COMMAND "$") +add_test(NAME test_amalgamation COMMAND "$") diff --git a/tests/testall.c b/tests/testall.c index f38edfb..e2aab5c 100644 --- a/tests/testall.c +++ b/tests/testall.c @@ -39,10 +39,13 @@ CuSuite* get_argdate_testsuite(); CuSuite* get_argdbl_testsuite(); CuSuite* get_argfile_testsuite(); CuSuite* get_argrex_testsuite(); -CuSuite* get_arghashtable_testsuite(); CuSuite* get_argdstr_testsuite(); CuSuite* get_argcmd_testsuite(); +#ifndef ARGTABLE3_TEST_PUBLIC_ONLY +CuSuite* get_arghashtable_testsuite(); +#endif + void RunAllTests(void) { CuString* output = CuStringNew(); CuSuite* suite = CuSuiteNew(); @@ -54,9 +57,11 @@ void RunAllTests(void) { CuSuiteAddSuite(suite, get_argdbl_testsuite()); CuSuiteAddSuite(suite, get_argfile_testsuite()); CuSuiteAddSuite(suite, get_argrex_testsuite()); - CuSuiteAddSuite(suite, get_arghashtable_testsuite()); CuSuiteAddSuite(suite, get_argdstr_testsuite()); CuSuiteAddSuite(suite, get_argcmd_testsuite()); +#ifndef ARGTABLE3_TEST_PUBLIC_ONLY + CuSuiteAddSuite(suite, get_arghashtable_testsuite()); +#endif CuSuiteRun(suite); CuSuiteSummary(suite, output);