diff --git a/scripts/genactionslist b/scripts/genactionslist deleted file mode 100755 index 74cef87..0000000 --- a/scripts/genactionslist +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -DIR="$(dirname $0)/../include" -COMPILER="$1" -OUT="$2" -shift -shift -declare -a EXCLUDE_ACTIONS=( $@ ) - -included() -{ - local name="$1" - - local i=0 - while [ $i -lt ${#EXCLUDE_ACTIONS[@]} ]; do - if [ "$name" == "${EXCLUDE_ACTIONS[$i]}" ]; then - return 1 - fi - let i++ - done - return 0 -} - -if [ -z "$COMPILER" ]; then - exit 1 -fi - -actlist="" -echo "">"$OUT" - -cdir="$(pwd)" -pushd "$DIR">/dev/null -for f in ../actions/action*.h ../actions-add/action*.h; do - if [ -f "$f" ]; then -# echo Compiler=$COMPILER -# echo Exclude list=${EXCLUDE_ACTIONS[@]} - name="$($COMPILER -E -DGENACTIONLIST "$f" 2>/dev/null| grep "ADD ACTION CLASS: " | sed "s/.*: //")" - name=${name//;/} - if included "$name"; then - pushd "$cdir">/dev/null - echo "#include \"$f\"">>"$OUT" - actlist+=" Action$name" - popd>/dev/null - fi - fi -done - -actlist=${actlist## } -actlist=${actlist%% } -actlist=${actlist// /,} -pushd "$cdir">/dev/null -echo "#define ACTLIST $actlist">>"$OUT" -popd>/dev/null diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6dcfd6..716f657 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,18 +1,41 @@ set(EXENAME odm) -set(ACTIONLIST ../include/actionlist.h) -set(GENALIST ${CMAKE_SOURCE_DIR}/scripts/genactionslist) +set(ACTIONLISTINC ${CMAKE_CURRENT_BINARY_DIR}/../include/actionlist.h) # Include actions files and define the actions 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} ${ACTIONLIST}) +add_executable(${EXENAME} ${srcs} ${ACTIONLISTINC}) target_include_directories(${EXENAME} PRIVATE ../michlib/michlib ${CMAKE_CURRENT_BINARY_DIR}/../include) -file(GLOB actfiles CONFIGURE_DEPENDS ../actions/action*.h ../actions-add/action*.h) -add_custom_command(OUTPUT ${ACTIONLIST} COMMAND ${GENALIST} ARGS "${CMAKE_CXX_COMPILER} -I$, -I>" ${ACTIONLIST} ${EXCLUDE_ACTIONS} DEPENDS ${GENALIST} ${actfiles}) - target_link_libraries(${EXENAME} ${linker_options} ${netcdf} OpenMP::OpenMP_CXX teos) set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) install(TARGETS ${EXENAME}) + +# Begin generation of actions list +get_target_property(INCS ${EXENAME} INCLUDE_DIRECTORIES) +list(TRANSFORM INCS PREPEND "-I") + +separate_arguments(excluded UNIX_COMMAND "${EXCLUDE_ACTIONS}") + +file(GLOB actfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS ../actions/action*.h ../actions-add/action*.h) +foreach(actfile ${actfiles}) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${INCS} -E -DGENACTIONLIST ${actfile} OUTPUT_VARIABLE outfull ERROR_VARIABLE err WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + 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}") + list(APPEND actlist ${act}) + list(APPEND actfilelist ${actfile}) + endif() +endforeach(actfile) + +list(TRANSFORM actlist PREPEND "Action") +string(REPLACE ";" "," actclist "${actlist}") +file(WRITE ${ACTIONLISTINC} "#define ACTLIST ${actclist}\n") + +foreach(actfile ${actfilelist}) + file(APPEND ${ACTIONLISTINC} "#include \"${actfile}\"\n") +endforeach(actfile) +# End generation of actions list