--- CMakeLists.txt | 189 ++++++++++++++++++++++++++++++ CMakeModules/CompilerFlags.cmake | 25 ++++ CMakeModules/check_features.cmake | 96 +++++++++++++++ CMakeModules/version.cmake | 39 ++++++ version.c | 4 + 5 files changed, 353 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 CMakeModules/CompilerFlags.cmake create mode 100644 CMakeModules/check_features.cmake create mode 100644 CMakeModules/version.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f05b1e6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,189 @@ +# +# Copyright (C) 2021 Luigi Mantellini <luigi.mantell...@sm-optics.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +cmake_minimum_required(VERSION 3.10) + +project(linuxptp) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + +include(GNUInstallDirs) +include(CompilerFlags) +include(check_features) + +set(FILTERS_SRC filter.c mave.c mmedian.c) +set(SERVOS_SRC linreg.c ntpshm.c nullf.c pi.c servo.c) +set(TRANSP_SRC raw.c transport.c udp.c udp6.c uds.c) + +set(PTP4L_SRC bmc.c clock.c clockadj.c clockcheck.c config.c designated_fsm.c + e2e_tc.c fault.c fsm.c hash.c interface.c monitor.c msg.c phc.c + port.c port_signaling.c pqueue.c print.c ptp4l.c p2p_tc.c rtnl.c + sk.c stats.c tc.c telecom.c tlv.c tsproc.c unicast_client.c + unicast_fsm.c unicast_service.c util.c version.c) + +set(NSM_SRC config.c hash.c interface.c msg.c nsm.c phc.c print.c + rtnl.c sk.c tlv.c tsproc.c util.c version.c) + +set(PMC_SRC config.c hash.c interface.c msg.c phc.c pmc.c pmc_common.c print.c sk.c + tlv.c util.c version.c) + +set(PHC2SYS_SRC clockadj.c clockcheck.c config.c hash.c interface.c msg.c + phc.c phc2sys.c pmc_agent.c pmc_common.c print.c sk.c stats.c + sysoff.c tlv.c util.c version.c) + +set(HWSTAMP_CTL_SRC hwstamp_ctl.c version.c) + +set(PHC_CTL_SRC phc_ctl.c phc.c sk.c util.c clockadj.c sysoff.c print.c version.c) + +set(TIMEMASTER_SRC phc.c print.c rtnl.c sk.c timemaster.c util.c version.c) + +set(TS2PHC_SRC config.c clockadj.c hash.c interface.c phc.c print.c sk.c + ts2phc.c lstab.c nmea.c serial.c sock.c ts2phc_generic_master.c + ts2phc_master.c ts2phc_phc_master.c ts2phc_nmea_master.c ts2phc_slave.c util.c + version.c) + +# Generate .version file +add_custom_command( + OUTPUT always_rebuild + COMMAND true + COMMENT "") +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.version.h" + BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/.version.h" + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/version.cmake + COMMENT "Generate .version.h" + DEPENDS + always_rebuild) +add_custom_target(version + ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/.version.h") + +add_library(filters STATIC ${FILTERS_SRC}) +add_library(servos STATIC ${SERVOS_SRC}) +add_library(transp STATIC ${TRANSP_SRC}) + +add_executable(ptp4l + ${PTP4L_SRC}) +add_dependencies(ptp4l + version + filters + servos + transp) +target_include_directories(ptp4l + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(ptp4l + PRIVATE + filters + servos + transp + ${LIB_M}) + +add_executable(nsm + ${NSM_SRC}) +add_dependencies(nsm + version + filters + transp) +target_include_directories(nsm + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(nsm + PRIVATE + filters + transp) + +add_executable(pmc + ${PMC_SRC}) +add_dependencies(pmc + version + transp) +target_include_directories(pmc + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(pmc + PRIVATE + transp) + +add_executable(phc2sys + ${PHC2SYS_SRC}) +add_dependencies(phc2sys + version + transp) +target_include_directories(phc2sys + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(phc2sys + PRIVATE + servos + transp + ${LIB_M}) + +add_executable(hwstamp_ctl + ${HWSTAMP_CTL_SRC}) +add_dependencies(hwstamp_ctl + version) +target_include_directories(hwstamp_ctl + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(hwstamp_ctl + PRIVATE) + +add_executable(phc_ctl + ${PHC_CTL_SRC}) +add_dependencies(phc_ctl + version) +target_include_directories(phc_ctl + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(phc_ctl + PRIVATE + ${LIB_M}) + +add_executable(timemaster + ${TIMEMASTER_SRC}) +add_dependencies(timemaster + version) +target_include_directories(timemaster + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(timemaster + PRIVATE) + +add_executable(ts2phc + ${TS2PHC_SRC}) +add_dependencies(ts2phc + version + servos) +target_include_directories(ts2phc + PUBLIC + -I${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(ts2phc + PRIVATE + servos + ${LIB_M} + ${LIB_PTHREAD}) + +install(FILES ptp4l.8 + DESTINATION ${CMAKE_INSTALL_MANDIR}) + +install(TARGETS ptp4l nsm pmc phc2sys hwstamp_ctl phc_ctl timemaster ts2phc + DESTINATION "${CMAKE_INSTALL_SBINDIR}") diff --git a/CMakeModules/CompilerFlags.cmake b/CMakeModules/CompilerFlags.cmake new file mode 100644 index 0000000..20c07e7 --- /dev/null +++ b/CMakeModules/CompilerFlags.cmake @@ -0,0 +1,25 @@ +# +# Copyright (C) 2021 Luigi Mantellini <luigi.mantell...@sm-optics.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +if (MSVC) + # warning level 4 and all warnings as errors + add_compile_options(/W4 /WX) +else() + # lots of warnings and all warnings as errors + add_compile_options(-Wall -Werror) +endif() diff --git a/CMakeModules/check_features.cmake b/CMakeModules/check_features.cmake new file mode 100644 index 0000000..bd5f485 --- /dev/null +++ b/CMakeModules/check_features.cmake @@ -0,0 +1,96 @@ +# +# Copyright (C) 2021 Luigi Mantellini <luigi.mantell...@sm-optics.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +include(CheckSymbolExists) +include(CheckCSourceCompiles) + +add_definitions(-D_GNU_SOURCE) + +set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") +check_symbol_exists(clock_adjtime "time.h;sys/timex.h;sys/time.h" HAVE_CLOCK_ADJTIME) +if(DEFINED HAVE_CLOCK_ADJTIME) + add_definitions(-DHAVE_CLOCK_ADJTIME) +endif() + +check_symbol_exists(posix_spawn "spawn.h" HAVE_POSIX_SPAWN) +if(DEFINED HAVE_POSIX_SPAWN) + add_definitions(-DHAVE_POSIX_SPAWN) +endif() + +if(DEFINED $ENV{KBUILD_OUTPUT}) + # With KBUILD_OUTPUT set, we are building against + # either a custom kernel or a cross compiled kernel. + + set(KERNEL_BUILD_DIR $ENV{KBUILD_OUTPUT}) + + message(STATUS "KERNEL_BUILD_DIR=${KERNEL_BUILD_DIR}") + + # Find the headers + find_path(KERNELHEADERS_DIR + linux/net_tstamp.h + PATHS + ${KERNEL_BUILD_DIR}/usr/include/ + ) +else() + # If the currently running kernel is a custom build + # with the headers installed, then we should use them. + execute_process( + COMMAND uname -r + OUTPUT_VARIABLE KERNEL_RELEASE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Find the headers + find_path(KERNELHEADERS_DIR + linux/net_tstamp.h + ) +endif() + +message(STATUS "Kernel headers: ${KERNELHEADERS_DIR}") +include_directories(${KERNELHEADERS_DIR}) + +check_c_source_compiles(" + #include <linux/net_tstamp.h> + int main(int argc, char **argv) { + argc = argc; argv = argv; + enum hwtstamp_tx_types t; + t = HWTSTAMP_TX_ONESTEP_SYNC; + t = t; + return 0; + }" HAVE_ONESTEP_SYNC) +if(HAVE_ONESTEP_SYNC) + add_definitions(-DHAVE_ONESTEP_SYNC) +endif() + +check_c_source_compiles(" + #include <linux/net_tstamp.h> + int main(int argc, char **argv) { + argc = argc; argv = argv; + enum hwtstamp_tx_types t; + t = HWTSTAMP_TX_ONESTEP_P2P; + t = t; + return 0; + }" HAVE_ONESTEP_P2P) +if(HAVE_ONESTEP_P2P) + add_definitions(-DHAVE_ONESTEP_P2P) +endif() + +set(LIB_PTHREAD pthread) +set(LIB_M m) +set(LIB_RT rt) + diff --git a/CMakeModules/version.cmake b/CMakeModules/version.cmake new file mode 100644 index 0000000..4cb5237 --- /dev/null +++ b/CMakeModules/version.cmake @@ -0,0 +1,39 @@ +# +# Copyright (C) 2021 Luigi Mantellini <luigi.mantell...@sm-optics.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../version.sh ${CMAKE_CURRENT_SOURCE_DIR}/.. + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(VERSION_ "#ifndef VER +#define VER ${VERSION} +#endif +") + +if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/.version.h") + file(READ "${CMAKE_CURRENT_BINARY_DIR}/.version.h" VERSION__) +else() + set(VERSION__ "") +endif() + +if (NOT "${VERSION_}" STREQUAL "${VERSION__}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/.version.h" "${VERSION_}") + message("Version ${VERSION} (changed)") +else() + message("Version ${VERSION} (not changed)") +endif() diff --git a/version.c b/version.c index b82887e..5e8edea 100644 --- a/version.c +++ b/version.c @@ -19,6 +19,10 @@ */ #include "version.h" +#ifndef VER +#include ".version.h" +#endif + #define STRINGIFY_(x) #x #define STRINGIFY(x) STRINGIFY_(x) -- 2.31.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel