From 153045016d79b55c8debd38730cda2a7b703d2c8 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Thu, 22 Jun 2023 23:49:44 +1000 Subject: [PATCH] Generate list of available data sources --- .gitignore | 3 ++- CMakeLists.txt | 20 ++++++++++++++++++- include/data.h | 11 +++------- {include => sources}/AVISO.h | 0 {src => sources}/AVISOLOCAL.cpp | 0 {include => sources}/AVISOLOCAL.h | 0 {src => sources}/BINFILE.cpp | 0 {include => sources}/BINFILE.h | 0 {include => sources}/HYCOM.h | 0 {src => sources}/MODISBINLOCAL.cpp | 0 {include => sources}/MODISBINLOCAL.h | 0 {include => sources}/NEMO.h | 0 {include => sources}/NEMOBIO.h | 0 src/CMakeLists.txt | 30 ++++++++++++++++++++++++++-- 14 files changed, 52 insertions(+), 12 deletions(-) rename {include => sources}/AVISO.h (100%) rename {src => sources}/AVISOLOCAL.cpp (100%) rename {include => sources}/AVISOLOCAL.h (100%) rename {src => sources}/BINFILE.cpp (100%) rename {include => sources}/BINFILE.h (100%) rename {include => sources}/HYCOM.h (100%) rename {src => sources}/MODISBINLOCAL.cpp (100%) rename {include => sources}/MODISBINLOCAL.h (100%) rename {include => sources}/NEMO.h (100%) rename {include => sources}/NEMOBIO.h (100%) diff --git a/.gitignore b/.gitignore index dad6e6c..790c6ae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.so *.kdev4 .kdev4/* -actions-add/* \ No newline at end of file +actions-add/* +sources-add/* diff --git a/CMakeLists.txt b/CMakeLists.txt index b673298..c9c3e3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,24 @@ if(${srcdir} STREQUAL ${bindir}) " Please remove them.") endif() +string(ASCII 27 Esc) +set(ColorReset "${Esc}[m") +set(ColorBold "${Esc}[1m") +set(Red "${Esc}[31m") +set(Green "${Esc}[32m") +set(Yellow "${Esc}[33m") +set(Blue "${Esc}[34m") +set(Magenta "${Esc}[35m") +set(Cyan "${Esc}[36m") +set(White "${Esc}[37m") +set(BoldRed "${Esc}[1;31m") +set(BoldGreen "${Esc}[1;32m") +set(BoldYellow "${Esc}[1;33m") +set(BoldBlue "${Esc}[1;34m") +set(BoldMagenta "${Esc}[1;35m") +set(BoldCyan "${Esc}[1;36m") +set(BoldWhite "${Esc}[1;37m") + set(STATIC_ANALYZER OFF CACHE BOOL "Using GCC static analyzer if available") project(odm C CXX) @@ -20,7 +38,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) -include_directories(include GSW-C) +include_directories(include sources sources-add GSW-C) add_compile_options(-Wall) # Dwarf-4 support check diff --git a/include/data.h b/include/data.h index 22acd4b..c621dd5 100644 --- a/include/data.h +++ b/include/data.h @@ -1,14 +1,9 @@ #pragma once -#include "AVISO.h" -#include "AVISOLOCAL.h" -#include "BINFILE.h" -#include "HYCOM.h" -#include "MODISBINLOCAL.h" -#include "NEMO.h" -#include "NEMOBIO.h" +#include "datalist.h" #include "varhelpers.h" +#include -using DataVariants = std::variant; +using DataVariants = std::variant; class Data: public DataVariants { public: diff --git a/include/AVISO.h b/sources/AVISO.h similarity index 100% rename from include/AVISO.h rename to sources/AVISO.h diff --git a/src/AVISOLOCAL.cpp b/sources/AVISOLOCAL.cpp similarity index 100% rename from src/AVISOLOCAL.cpp rename to sources/AVISOLOCAL.cpp diff --git a/include/AVISOLOCAL.h b/sources/AVISOLOCAL.h similarity index 100% rename from include/AVISOLOCAL.h rename to sources/AVISOLOCAL.h diff --git a/src/BINFILE.cpp b/sources/BINFILE.cpp similarity index 100% rename from src/BINFILE.cpp rename to sources/BINFILE.cpp diff --git a/include/BINFILE.h b/sources/BINFILE.h similarity index 100% rename from include/BINFILE.h rename to sources/BINFILE.h diff --git a/include/HYCOM.h b/sources/HYCOM.h similarity index 100% rename from include/HYCOM.h rename to sources/HYCOM.h diff --git a/src/MODISBINLOCAL.cpp b/sources/MODISBINLOCAL.cpp similarity index 100% rename from src/MODISBINLOCAL.cpp rename to sources/MODISBINLOCAL.cpp diff --git a/include/MODISBINLOCAL.h b/sources/MODISBINLOCAL.h similarity index 100% rename from include/MODISBINLOCAL.h rename to sources/MODISBINLOCAL.h diff --git a/include/NEMO.h b/sources/NEMO.h similarity index 100% rename from include/NEMO.h rename to sources/NEMO.h diff --git a/include/NEMOBIO.h b/sources/NEMOBIO.h similarity index 100% rename from include/NEMOBIO.h rename to sources/NEMOBIO.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 716f657..367813b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,13 @@ set(EXENAME odm) set(ACTIONLISTINC ${CMAKE_CURRENT_BINARY_DIR}/../include/actionlist.h) # Include actions files and define the actions classes list +set(DATALISTINC ${CMAKE_CURRENT_BINARY_DIR}/../include/datalist.h) # Include data sources files and define the data sources classes list find_library(netcdf netcdf REQUIRED) find_package(OpenMP REQUIRED) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") file(GLOB srcs CONFIGURE_DEPENDS *.cpp) -add_executable(${EXENAME} ${srcs} ${ACTIONLISTINC}) +add_executable(${EXENAME} ${srcs} ${ACTIONLISTINC} ${SOURCELISTINC}) target_include_directories(${EXENAME} PRIVATE ../michlib/michlib ${CMAKE_CURRENT_BINARY_DIR}/../include) target_link_libraries(${EXENAME} ${linker_options} ${netcdf} OpenMP::OpenMP_CXX teos) @@ -25,7 +26,7 @@ foreach(actfile ${actfiles}) string(REGEX MATCH "ADD ACTION CLASS: [^ ;\n]+" outstr "${outfull}") string(REGEX REPLACE ".+: " "" act "${outstr}") if(NOT (("${act}" EQUAL "") OR ("${act}" IN_LIST excluded))) - message("Action: ${act} in file ${actfile}") + message("Action: ${Yellow}${act}${ColorReset} in file ${actfile}") list(APPEND actlist ${act}) list(APPEND actfilelist ${actfile}) endif() @@ -39,3 +40,28 @@ foreach(actfile ${actfilelist}) file(APPEND ${ACTIONLISTINC} "#include \"${actfile}\"\n") endforeach(actfile) # End generation of actions list + +# Begin generation of data sources list +separate_arguments(excluded UNIX_COMMAND "${EXCLUDE_SOURCES}") +file(GLOB sourcefiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS ../sources/*.h ../sources-add/*.h) +foreach(sourcefile ${sourcefiles}) + string(REGEX REPLACE "(\.h$|.*/)" "" source "${sourcefile}") + string(REGEX REPLACE "\.h$" ".cpp" sourcecpp "${sourcefile}") + if(NOT (("${source}" EQUAL "") OR ("${source}" IN_LIST excluded))) + message("Source: ${Cyan}${source}${ColorReset} in file ${sourcefile}") + list(APPEND sourcelist ${source}) + list(APPEND sourcefilelist ${sourcefile}) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${sourcecpp} ) + target_sources(${EXENAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${sourcecpp}) + endif() + endif() +endforeach(sourcefile) + +list(TRANSFORM sourcelist APPEND "Data") +string(REPLACE ";" "," sourceclist "${sourcelist}") +file(WRITE ${DATALISTINC} "#define DATALIST ${sourceclist}\n") + +foreach(sourcefile ${sourcefilelist}) + file(APPEND ${DATALISTINC} "#include \"${sourcefile}\"\n") +endforeach(sourcefile) +# End generation of sources list