From 88bbeb862b6017aebcd1732ee2b734d79bab30cf Mon Sep 17 00:00:00 2001 From: Schaich Date: Tue, 30 Mar 2021 19:00:24 +0900 Subject: [PATCH] Move getopt out of the frontend, because it's used in the backend's test, too --- CMakeLists.txt | 6 ++++++ backend/tests/CMakeLists.txt | 6 ++++++ frontend/CMakeLists.txt | 11 +++-------- getopt/CMakeLists.txt | 4 ++++ {frontend => getopt}/getopt.c | 0 {frontend => getopt}/getopt.h | 0 {frontend => getopt}/getopt1.c | 0 7 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 getopt/CMakeLists.txt rename {frontend => getopt}/getopt.c (100%) rename {frontend => getopt}/getopt.h (100%) rename {frontend => getopt}/getopt1.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed64f0cf..29ca251e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ option(ZINT_USE_QT "Build with QT support" ON) include(SetPaths.cmake) include(CheckCXXCompilerFlag) +include(CheckFunctionExists) check_cxx_compiler_flag("-Wall" CXX_COMPILER_FLAG_WALL) if(CXX_COMPILER_FLAG_WALL) @@ -89,6 +90,11 @@ IF(APPLE) ENDIF (UNIVERSAL) ENDIF(APPLE) +check_function_exists(getopt HAVE_GETOPT) +if(NOT HAVE_GETOPT) + add_subdirectory(getopt) +endif(NOT HAVE_GETOPT) + add_subdirectory(backend) add_subdirectory(frontend) diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index 63b32497..88eeea81 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -28,11 +28,17 @@ set(testcommon_SRCS testcommon.c testcommon.h) add_library(testcommon ${testcommon_SRCS}) target_link_libraries(testcommon zint) target_include_directories(testcommon PUBLIC ${zint_backend_tests_SOURCE_DIR}) +if(NOT HAVE_GETOPT) + target_link_libraries(testcommon zint_bundled_getopt) +endif() if(ZINT_STATIC) add_library(testcommon-static ${testcommon_SRCS}) target_link_libraries(testcommon-static zint-static) target_include_directories(testcommon-static PUBLIC ${zint_backend_tests_SOURCE_DIR}) + if(NOT HAVE_GETOPT) + target_link_libraries(testcommon-static zint_bundled_getopt) + endif() endif() zint_add_test(2of5 test_2of5) diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt index b8cf0d4b..f873b43a 100644 --- a/frontend/CMakeLists.txt +++ b/frontend/CMakeLists.txt @@ -2,16 +2,8 @@ project(zint_frontend) -include(CheckFunctionExists) - -check_function_exists(getopt HAVE_GETOPT) - set(zint_frontend_SRCS main.c) -if(NOT HAVE_GETOPT) - set(zint_frontend_SRCS ${zint_frontend_SRCS} getopt.c getopt1.c) -endif(NOT HAVE_GETOPT) - include_directories(BEFORE "${CMAKE_SOURCE_DIR}/backend") add_executable(zint_frontend ${zint_frontend_SRCS}) @@ -19,6 +11,9 @@ add_executable(zint_frontend ${zint_frontend_SRCS}) set_target_properties(zint_frontend PROPERTIES OUTPUT_NAME "zint") target_link_libraries(zint_frontend zint) +if(NOT HAVE_GETOPT) + target_link_libraries(zint_frontend zint_bundled_getopt) +endif(NOT HAVE_GETOPT) install(TARGETS zint_frontend DESTINATION "${BIN_INSTALL_DIR}" RUNTIME) diff --git a/getopt/CMakeLists.txt b/getopt/CMakeLists.txt new file mode 100644 index 00000000..85a98e4f --- /dev/null +++ b/getopt/CMakeLists.txt @@ -0,0 +1,4 @@ +project(zint_bundled_getopt) + +add_library(zint_bundled_getopt STATIC getopt.c getopt1.c) +target_include_directories(zint_bundled_getopt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/frontend/getopt.c b/getopt/getopt.c similarity index 100% rename from frontend/getopt.c rename to getopt/getopt.c diff --git a/frontend/getopt.h b/getopt/getopt.h similarity index 100% rename from frontend/getopt.h rename to getopt/getopt.h diff --git a/frontend/getopt1.c b/getopt/getopt1.c similarity index 100% rename from frontend/getopt1.c rename to getopt/getopt1.c