From 0c10fa0211c9447f7b155ba25154886bac36301c Mon Sep 17 00:00:00 2001 From: Jeroen Doggen Date: Thu, 7 Mar 2024 11:46:19 +0100 Subject: [PATCH 1/3] Add CMakeLists.txt: runs 'autogen.sh & ./configure' before building libmodbus --- .github/workflows/build.yml | 10 ++++++++++ CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77d7b3531..f23c9837f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,3 +18,13 @@ jobs: run: make - name: make distcheck run: make distcheck + + build_cmake: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build + - name: Build + run: cmake --build ${{github.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..c6cf30207 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.23) + +project(modbus) + +if(NOT TARGET ${PROJECT_NAME}) + + message(STATUS "Running ./autogen.sh") + execute_process(COMMAND ./autogen.sh + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + RESULT_VARIABLE AUTOGEN_RESULT) + + if(NOT AUTOGEN_RESULT EQUAL "0") + message(FATAL_ERROR "autogen.sh failed") + endif() + + message(STATUS "Running ./configure") + execute_process(COMMAND ./configure + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + RESULT_VARIABLE CONFIGURE_RESULT) #cd ${CMAKE_CURRENT_LIST_DIR} && ./autogen.sh && ./configure) + + if(NOT CONFIGURE_RESULT EQUAL "0") + message(FATAL_ERROR "configure failed") + endif() + + add_library(${PROJECT_NAME}) + + target_sources(${PROJECT_NAME} PRIVATE FILE_SET configuration TYPE HEADERS FILES config.h) + target_sources(${PROJECT_NAME} PUBLIC FILE_SET public_headers TYPE HEADERS FILES src/modbus.h src/modbus-rtu.h src/modbus-tcp.h src/modbus-version.h) + target_sources(${PROJECT_NAME} PRIVATE src/modbus.c src/modbus-data.c src/modbus-rtu.c src/modbus-tcp.c) +endif() From ecb9f6c7db7385b59699b7828477540f0101a020 Mon Sep 17 00:00:00 2001 From: jeroendoggen Date: Thu, 7 Mar 2024 14:12:10 +0100 Subject: [PATCH 2/3] Clean up CMakeLists.txt --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6cf30207..385df16d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ cmake_minimum_required(VERSION 3.23) - project(modbus) if(NOT TARGET ${PROJECT_NAME}) - message(STATUS "Running ./autogen.sh") execute_process(COMMAND ./autogen.sh WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} @@ -16,7 +14,7 @@ if(NOT TARGET ${PROJECT_NAME}) message(STATUS "Running ./configure") execute_process(COMMAND ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - RESULT_VARIABLE CONFIGURE_RESULT) #cd ${CMAKE_CURRENT_LIST_DIR} && ./autogen.sh && ./configure) + RESULT_VARIABLE CONFIGURE_RESULT) if(NOT CONFIGURE_RESULT EQUAL "0") message(FATAL_ERROR "configure failed") From 70e6f725400a29e262e5c3782355f6af55184702 Mon Sep 17 00:00:00 2001 From: Jeroen Doggen Date: Mon, 11 Mar 2024 16:05:12 +0100 Subject: [PATCH 3/3] CMake: set'--host' for crosscompilation --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 385df16d4..915ef7575 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@ if(NOT TARGET ${PROJECT_NAME}) message(FATAL_ERROR "autogen.sh failed") endif() - message(STATUS "Running ./configure") - execute_process(COMMAND ./configure + message(STATUS "Running ./configure --host=${CMAKE_SYSTEM_PROCESSOR}") + execute_process(COMMAND ./configure --host=${CMAKE_SYSTEM_PROCESSOR} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE CONFIGURE_RESULT)