diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e87cd9..b612608 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,8 @@ FortranCInterface_VERIFY() # Fortran module set(TREXIO_MOD_FILE ${CMAKE_SOURCE_DIR}/include/trexio_f.f90) +# Export to parent scope so tests directory picks this up. +set(TREXIO_MOD_FILE ${TREXIO_MOD_FILE} PARENT_SCOPE) # Add TREXIO Fortran module as a library. add_library(trexio_f SHARED) target_sources(trexio_f PUBLIC ${TREXIO_MOD_FILE}) @@ -114,10 +116,28 @@ if(TREXIO_DEVEL) ${TREXIO_PRIVATE_HEADERS} ${TREXIO_MOD_FILE} COMMAND ./build_trexio.sh - DEPENDS ${ORG_FILES} + DEPENDS ${ORG_FILES} ${CMAKE_SOURCE_DIR}/include/config.h WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tools COMMENT "Generating TREXIO source code from org-mode files." VERBATIM) + + set_source_files_properties(${TREXIO_SOURCES} + ${TREXIO_PUBLIC_HEADERS} + ${TREXIO_PRIVATE_HEADERS} + ${TREXIO_MOD_FILE} + PROPERTIES GENERATED TRUE) + + add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/include/config.h + COMMAND bash -c "echo -e '#define TREXIO_PACKAGE_VERSION \"${PROJECT_VERSION}\"\\n#define TREXIO_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}\\n#define TREXIO_VERSION_MINOR ${PROJECT_VERSION_MINOR}\\n#define TREXIO_VERSION_PATCH ${PROJECT_VERSION_PATCH}' > config.h" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/include + COMMENT "Generates minimal include/config.h without using autotools." + VERBATIM) + + set_source_files_properties( + ${CMAKE_SOURCE_DIR}/include/config.h + PROPERTIES GENERATED TRUE) + endif() # ============= INSTALL TREXIO ============== diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 4d75e07..895dff4 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -12,10 +12,10 @@ VERSION_PATCH_VAL=`grep "VERSION_PATCH" ../../include/config.h | cut -d " " -f 3 # grep some usefull constants from the config.h echo "" >> trexio.h -echo "#define TREXIO_PACKAGE_VERSION ${VERSION_VAL}" >> trexio.h -echo "#define TREXIO_VERSION_MAJOR ${VERSION_MAJOR_VAL}" >> trexio.h -echo "#define TREXIO_VERSION_MINOR ${VERSION_MINOR_VAL}" >> trexio.h -echo "#define TREXIO_VERSION_PATCH ${VERSION_PATCH_VAL}" >> trexio.h +echo "#define TREXIO_PACKAGE_VERSION ${VERSION_VAL:='0.0.0'}" >> trexio.h +echo "#define TREXIO_VERSION_MAJOR ${VERSION_MAJOR_VAL:=0}" >> trexio.h +echo "#define TREXIO_VERSION_MINOR ${VERSION_MINOR_VAL:=0}" >> trexio.h +echo "#define TREXIO_VERSION_PATCH ${VERSION_PATCH_VAL:=0}" >> trexio.h echo "" >> trexio.h cat prefix_s_front.h > trexio_s.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 94fe414..4af2ac1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,4 +44,8 @@ endforeach() # Add Fortran test and link it with trexio_f (Fortran module) library. add_executable(test_f test_f.f90) target_link_libraries(test_f PRIVATE trexio_f) +if(TREXIO_DEVEL) + set_source_files_properties(${TREXIO_MOD_FILE} + PROPERTIES GENERATED TRUE) +endif() add_test(NAME test_f COMMAND $)