From 6bab1c54a6930f6b2d4e838ffff6ffa73d613ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Frohm=C3=BCller?= Date: Mon, 3 Oct 2022 23:31:35 +0200 Subject: [PATCH] Implement CMake as build system. --- .gitignore | 11 +++++ CMakeLists.txt | 21 ++++++++++ src/CMakeLists.txt | 32 +++++++++++++++ src/create_script_help/Makefile | 16 -------- src/opensuperclone/CMakeLists.txt | 63 +++++++++++++++++++++++++++++ src/opensuperclone/Makefile | 35 ---------------- src/opensuperclone/opensuperclone.c | 4 +- src/oscviewer/CMakeLists.txt | 28 +++++++++++++ src/oscviewer/Makefile | 25 ------------ 9 files changed, 157 insertions(+), 78 deletions(-) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt delete mode 100644 src/create_script_help/Makefile create mode 100644 src/opensuperclone/CMakeLists.txt delete mode 100644 src/opensuperclone/Makefile create mode 100644 src/oscviewer/CMakeLists.txt delete mode 100644 src/oscviewer/Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61b8896 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8d9606c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.10) + +# OpenSuperClone version 2.3.3 +project(OpenSuperClone VERSION 2.3.3) + +# Set the GTK version to 2.x +set(GTKVER 2) + +set(CMAKE_C_COMPILER gcc) + +set(GCC_OPTIONS + -Wall + -W + -Wno-deprecated-declarations + -fcommon + -lcurl +) + +set(CMAKE_EXE_LINKER_FLAGS "-export-dynamic") + +add_subdirectory(src) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..cb68494 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,32 @@ +# Add GTK dependency +if(GTKVER EQUAL 2) + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK2 REQUIRED gtk+-2.0) + + include_directories(${GTK2_INCLUDE_DIRS}) + link_directories(${GTK2_LIBRARY_DIRS}) + + add_definitions(${GTK2_CFLAGS_OTHER}) + + set(LIBRARIES ${LIBRARIES} ${GTK2_LIBRARIES}) +elseif(GTKVER EQUAL 3) + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + + include_directories(${GTK3_INCLUDE_DIRS}) + link_directories(${GTK3_LIBRARY_DIRS}) + + add_definitions(${GTK3_CFLAGS_OTHER}) + + set(LIBRARIES ${LIBRARIES} ${GTK3_LIBRARIES}) +endif() + +# Add LibUSB dependency +find_library(LIBUSB_LIBRARY + NAMES usb + PATH_SUFFIXES "lib" "lib32" "lib64" +) + +add_subdirectory(opensuperclone) +add_subdirectory(oscviewer) +#add_subdirectory(create_script_help) \ No newline at end of file diff --git a/src/create_script_help/Makefile b/src/create_script_help/Makefile deleted file mode 100644 index 5127210..0000000 --- a/src/create_script_help/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -CC = gcc -ifneq (,$(findstring k,$(MAKEFLAGS))) -CFLAGS = -Wall -W -O0 -g -fcommon -else -CFLAGS = -Wall -W -Wno-deprecated-declarations -fcommon -endif - -bindir = ../../bin/ - -default: create_script_help - -create_script_help : create_script_help.c - $(CC) $(CFLAGS) create_script_help.c -o $(bindir)create_script_help - -clean: - rm -f $(bindir)/create_script_help \ No newline at end of file diff --git a/src/opensuperclone/CMakeLists.txt b/src/opensuperclone/CMakeLists.txt new file mode 100644 index 0000000..59e26b9 --- /dev/null +++ b/src/opensuperclone/CMakeLists.txt @@ -0,0 +1,63 @@ +set(SOURCES + opensuperclone.c + opensuperclone.h + commands.c + commands.h + io.c + io.h + tool.c + tool.h + usbrelay.c + usbrelay.h + common.c + common.h + clone_gui${GTKVER}.c + clone_gui${GTKVER}.h + clone_gui_language.c + clone_gui_language.h +) + +# Generate header files from resources +add_custom_command( + OUTPUT opensuperclone_EULA.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/opensuperclone_EULA.txt opensuperclone_EULA.txt + COMMAND xxd -i opensuperclone_EULA.txt opensuperclone_EULA.h +) +LIST(APPEND RESOURCES opensuperclone_EULA.h) + +add_custom_command( + OUTPUT opensuperclone_help.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/opensuperclone_help.txt opensuperclone_help.txt + COMMAND xxd -i opensuperclone_help.txt opensuperclone_help.h +) +LIST(APPEND RESOURCES opensuperclone_help.h) + +add_custom_command( + OUTPUT opensuperclone${GTKVER}_glade.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/opensuperclone${GTKVER}.glade opensuperclone${GTKVER}.glade + COMMAND xxd -i opensuperclone${GTKVER}.glade opensuperclone${GTKVER}_glade.h +) +LIST(APPEND RESOURCES opensuperclone${GTKVER}_glade.h) + +add_custom_command( + OUTPUT opensupertool_help.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/opensupertool_help.txt opensupertool_help.txt + COMMAND xxd -i opensupertool_help.txt opensupertool_help.h +) +LIST(APPEND RESOURCES opensupertool_help.h) + +add_custom_command( + OUTPUT opensuperclone_driver.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/driver/opensuperclone_driver.c opensuperclone_driver.c + COMMAND xxd -i opensuperclone_driver.c opensuperclone_driver.h +) +LIST(APPEND RESOURCES opensuperclone_driver.h) + +# Include generated header files +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +set(LIBRARIES ${LIBRARIES} ${LIBUSB_LIBRARY}) + +add_executable(opensuperclone ${SOURCES} ${RESOURCES}) +target_link_libraries(opensuperclone ${LIBRARIES}) +target_compile_options(opensuperclone PRIVATE ${GCC_OPTIONS}) \ No newline at end of file diff --git a/src/opensuperclone/Makefile b/src/opensuperclone/Makefile deleted file mode 100644 index a1dea4e..0000000 --- a/src/opensuperclone/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -GTKVER = 2 - -CC = gcc -ifneq (,$(findstring k,$(MAKEFLAGS))) -CFLAGS = -Wall -W -O0 -g -fcommon -else -CFLAGS = -Wall -W -Wno-deprecated-declarations -fcommon -endif -SSLFLAGS = -lssl -lcrypto -USBFLAGS = -lusb -CURLFLAGS = -lcurl -GTKFLAGS = `pkg-config --cflags --libs gtk+-$(GTKVER).0` -export-dynamic - -driverdir = driver/ -bindir = ../../bin/ - -default: clone - -clone : opensuperclone.c - xxd -i opensupertool_help.txt opensupertool_help.h - xxd -i opensuperclone_help.txt opensuperclone_help.h - xxd -i opensuperclone$(GTKVER).glade opensuperclone$(GTKVER)_glade.h - xxd -i opensuperclone_EULA.txt opensuperclone_EULA.h - xxd -i $(driverdir)opensuperclone_driver.c opensuperclone_driver.h - $(CC) $(CFLAGS) opensuperclone.c commands.c io.c tool.c usbrelay.c common.c clone_gui$(GTKVER).c clone_gui_language.c -o $(bindir)opensuperclone $(GTKFLAGS) $(CURLFLAGS) $(USBFLAGS) $(SSLFLAGS) - -clean: - rm -f $(bindir)opensuperclone - rm -f opensupertool_help.h - rm -f opensuperclone_help.h - rm -f opensuperclone_glade.h - rm -f opensuperclone2_glade.h - rm -f opensuperclone3_glade.h - rm -f opensuperclone_EULA.h - rm -f opensuperclone_driver.h \ No newline at end of file diff --git a/src/opensuperclone/opensuperclone.c b/src/opensuperclone/opensuperclone.c index 40e293d..02488b4 100644 --- a/src/opensuperclone/opensuperclone.c +++ b/src/opensuperclone/opensuperclone.c @@ -1243,9 +1243,9 @@ void install_driver_ccc(void) return; } unsigned int i; - for (i = 0; i < driver_opensuperclone_driver_c_len; i++) + for (i = 0; i < opensuperclone_driver_c_len; i++) { - fprintf(writefile, "%c", driver_opensuperclone_driver_c[i]); + fprintf(writefile, "%c", opensuperclone_driver_c[i]); } int fp = fileno(writefile); fsync(fp); diff --git a/src/oscviewer/CMakeLists.txt b/src/oscviewer/CMakeLists.txt new file mode 100644 index 0000000..220ec7c --- /dev/null +++ b/src/oscviewer/CMakeLists.txt @@ -0,0 +1,28 @@ +set(SOURCES + oscviewer${GTKVER}.c + oscviewer${GTKVER}.h +) + +# Generate header file from glade file +add_custom_command( + OUTPUT oscviewer${GTKVER}_glade.h + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/oscviewer${GTKVER}.glade oscviewer${GTKVER}.glade + COMMAND xxd -i oscviewer${GTKVER}.glade oscviewer${GTKVER}_glade.h +) + +# Include generated header file +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(oscviewer ${SOURCES} oscviewer${GTKVER}_glade.h) + +target_link_libraries(oscviewer ${LIBRARIES}) + +set(GCC_OPTIONS + -Wall + -W + -Wno-deprecated-declarations + -fcommon + -lcurl +) + +target_compile_options(oscviewer PRIVATE ${GCC_OPTIONS}) \ No newline at end of file diff --git a/src/oscviewer/Makefile b/src/oscviewer/Makefile deleted file mode 100644 index 48d182a..0000000 --- a/src/oscviewer/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -GTKVER = 2 - -CC = gcc -ifneq (,$(findstring k,$(MAKEFLAGS))) -CFLAGS = -Wall -W -O0 -g -fcommon -else -CFLAGS = -Wall -W -Wno-deprecated-declarations -fcommon -endif -SSLFLAGS = -lssl -lcrypto -CURLFLAGS = -lcurl -GTKFLAGS = `pkg-config --cflags --libs gtk+-$(GTKVER).0` -export-dynamic - -bindir = ../../bin/ - -default: oscviewer - -oscviewer : oscviewer$(GTKVER).c - xxd -i oscviewer$(GTKVER).glade oscviewer$(GTKVER)_glade.h - $(CC) $(CFLAGS) oscviewer$(GTKVER).c -o $(bindir)oscviewer $(GTKFLAGS) $(CURLFLAGS) - -clean: - rm -f $(bindir)oscviewer - rm -f oscviewer_help.h - rm -f oscviewer2_glade.h - rm -f oscviewer3_glade.h \ No newline at end of file