From 8f1fc8a73cd8362ca8365b8c66385902d72416b7 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Tue, 11 Aug 2020 23:46:18 +0200 Subject: [PATCH 1/4] Generate m4 files out of tree --- CMakeLists.txt | 29 +++++++++++++++-------------- libsrc/CMakeLists.txt | 29 ++++++++++++++--------------- nc_test/CMakeLists.txt | 17 ++++++++--------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a592dba0..9ce05b168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1535,22 +1535,23 @@ ELSE() MESSAGE(STATUS "m4 not found.") ENDIF() -MACRO(GEN_m4 filename) - +MACRO(GEN_m4 filename dest) + set(${dest} "${CMAKE_CURRENT_BINARY_DIR}/${filename}.c") IF(HAVE_M4) - - # If m4 is available, remove generated file if it exists. - IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) - FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) - ENDIF() - - ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c - COMMAND ${NC_M4} - ARGS ${M4FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.m4 > ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c - VERBATIM + ADD_CUSTOM_COMMAND( + OUTPUT ${${dest}} + COMMAND ${NC_M4} + ARGS ${M4FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.m4 > ${${dest}} + VERBATIM ) -ENDIF(HAVE_M4) + ELSE(HAVE_M4) + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) + FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + ELSE() + MESSAGE(FATAL_ERROR "File ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c does not exists, and can not be generated") + ENDIF() + ENDIF(HAVE_M4) ENDMACRO(GEN_m4) # Binary tests, but ones which depend on value of 'TEMP_LARGE' being defined. diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index 65a3f8745..aa11b3988 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -1,35 +1,34 @@ ## This is a CMake file, part of Unidata's netCDF package. # Copyright 2012-2018, see the COPYRIGHT file for more information. -# Process these files with m4. -SET(m4_SOURCES attr ncx putget t_ncxx) -foreach (f ${m4_SOURCES}) - IF(HAVE_M4) - GEN_m4(${f}) - ENDIF() -endforeach(f) - SET(libsrc_SOURCES v1hpg.c putget.c attr.c nc3dispatch.c nc3internal.c var.c dim.c ncx.c lookup3.c ncio.c) -SET(libsrc_SOURCES ${libsrc_SOURCES} pstdint.h ncio.h ncx.h) +# Process these files with m4. +SET(m4_SOURCES attr ncx putget) +foreach (f ${m4_SOURCES}) + GEN_m4(${f} dest) + LIST(APPEND libsrc_SOURCES ${dest}) +endforeach(f) -SET(libsrc_SOURCES ${libsrc_SOURCES} memio.c) +LIST(APPEND libsrc_SOURCES pstdint.h ncio.h ncx.h) + +LIST(APPEND libsrc_SOURCES memio.c) IF (BUILD_MMAP) - SET(libsrc_SOURCES ${libsrc_SOURCES} mmapio.c) + LIST(APPEND libsrc_SOURCES mmapio.c) ENDIF( BUILD_MMAP) IF (USE_FFIO) - SET(libsrc_SOURCES ${libsrc_SOURCES} ffio.c) + LIST(APPEND libsrc_SOURCES ffio.c) ELSEIF (USE_STDIO) - SET(libsrc_SORUCES ${libsrc_SOURCES} ncstdio.c) + IST(APPEND libsrc_SOURCES ncstdio.c) ELSE (USE_FFIO) - SET(libsrc_SOURCES ${libsrc_SOURCES} posixio.c) + LIST(APPEND libsrc_SOURCES posixio.c) ENDIF (USE_FFIO) IF (ENABLE_BYTERANGE) - SET(libsrc_SOURCES ${libsrc_SOURCES} httpio.c) + LIST(APPEND libsrc_SOURCES httpio.c) ENDIF(ENABLE_BYTERANGE) add_library(netcdf3 OBJECT ${libsrc_SOURCES}) diff --git a/nc_test/CMakeLists.txt b/nc_test/CMakeLists.txt index 13c84404f..ffeed2bcc 100644 --- a/nc_test/CMakeLists.txt +++ b/nc_test/CMakeLists.txt @@ -15,22 +15,21 @@ add_definitions(-D"TOPBINDIR=${CMAKE_BINARY_DIR}") INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) -SET (nc_test_m4_SOURCES test_get test_put test_read test_write) -FOREACH (F ${nc_test_m4_SOURCES}) - GEN_m4(${F}) -ENDFOREACH() - SET (nc_test_SRC nc_test.c error.c - test_get.c - test_put.c - test_read.c - test_write.c util.c ) + +SET (nc_test_m4_SOURCES test_get test_put test_read test_write) +FOREACH (F ${nc_test_m4_SOURCES}) + GEN_m4(${F} dest) + LIST(APPEND nc_test_SRC ${dest}) +ENDFOREACH() + ADD_EXECUTABLE(nc_test ${nc_test_SRC}) +TARGET_INCLUDE_DIRECTORIES(nc_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) TARGET_LINK_LIBRARIES(nc_test netcdf ${HAVE_LIBM} From a3f2c5847f4305b6946b19bccb5bf59224319bc6 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 12 Aug 2020 16:09:28 +0200 Subject: [PATCH 2/4] Configure netcdf_meta.h directly to BINARY_DIR --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ce05b168..688913c59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2100,10 +2100,7 @@ INSTALL(FILES "${netCDF_BINARY_DIR}/libnetcdf.settings" ##### configure_file( ${netCDF_SOURCE_DIR}/include/netcdf_meta.h.in - ${netCDF_SOURCE_DIR}/include/netcdf_meta.h @ONLY) - -FILE(COPY ${netCDF_SOURCE_DIR}/include/netcdf_meta.h - DESTINATION ${netCDF_BINARY_DIR}/include/) + ${netCDF_BINARY_DIR}/include/netcdf_meta.h @ONLY) ##### # Build test_common.sh From 9d10e605c2d59f5499ceafbdc6dc6f7784b2762b Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 12 Aug 2020 16:38:00 +0200 Subject: [PATCH 3/4] Move generated file to BINARY_DIR --- CMakeLists.txt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 688913c59..2c119a2af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1597,7 +1597,12 @@ ENDMACRO() # Build a binary used by a script, but don't make a test out of it. MACRO(build_bin_test F) - ADD_EXECUTABLE(${F} ${F}.c) + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${F}.c") + ADD_EXECUTABLE(${F} "${CMAKE_CURRENT_SOURCE_DIR}/${F}.c") + else() + # File should have been copied to the binary directory + ADD_EXECUTABLE(${F} "${CMAKE_CURRENT_BINARY_DIR}/${F}.c") + endif() TARGET_LINK_LIBRARIES(${F} netcdf ${ALL_TLL_LIBS}) IF(MSVC) SET_TARGET_PROPERTIES(${F} @@ -2121,16 +2126,18 @@ IF(ENABLE_EXAMPLES) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nc_test4/findplugin.in ${CMAKE_CURRENT_BINARY_DIR}/examples/C/findplugin.sh @ONLY NEWLINE_STYLE LF) ENDIF() -##### -# Build ncdap_test|dap4_test/findtestserver[4].c -##### -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/findtestserver.c.in ${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/findtestserver.c @ONLY NEWLINE_STYLE LF) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/findtestserver.c.in ${CMAKE_CURRENT_SOURCE_DIR}/dap4_test/findtestserver4.c @ONLY NEWLINE_STYLE LF) +IF(ENABLE_TESTS) + ##### + # Build ncdap_test|dap4_test/findtestserver[4].c + ##### + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/findtestserver.c.in ${CMAKE_CURRENT_BINARY_DIR}/ncdap_test/findtestserver.c @ONLY NEWLINE_STYLE LF) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/findtestserver.c.in ${CMAKE_CURRENT_BINARY_DIR}/dap4_test/findtestserver4.c @ONLY NEWLINE_STYLE LF) -##### -# Build dap4_test/pingurl4.c -##### -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/pingurl.c ${CMAKE_CURRENT_SOURCE_DIR}/dap4_test/pingurl4.c @ONLY NEWLINE_STYLE LF) + ##### + # Build dap4_test/pingurl4.c + ##### + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/pingurl.c ${CMAKE_CURRENT_BINARY_DIR}/dap4_test/pingurl4.c @ONLY NEWLINE_STYLE LF) +ENDIF() #### # Export files From 12d86675efba82275399be2d81ce0dfcbcd7c58b Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 12 Aug 2020 17:03:33 +0200 Subject: [PATCH 4/4] H5Znoop1.c copied to BINARY_DIR instead of SOURCE_DIR --- CMakeLists.txt | 1 - plugins/CMakeLists.txt | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c119a2af..2714b067f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1858,7 +1858,6 @@ ENDIF() add_subdirectory(liblib) IF(ENABLE_FILTER_TESTING) - CONFIGURE_FILE(plugins/H5Znoop.c ${CMAKE_SOURCE_DIR}/plugins/H5Znoop1.c COPYONLY) add_subdirectory(plugins) ENDIF() diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 1ef40280d..78c379439 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -6,12 +6,14 @@ # See netcdf-c/COPYRIGHT file for more info. SET(CMAKE_BUILD_TYPE "") +CONFIGURE_FILE(H5Znoop.c ${CMAKE_CURRENT_BINARY_DIR}/H5Znoop1.c COPYONLY) + SET(libh5bzip2_SOURCES blocksort.c huffman.c crctable.c randtable.c compress.c decompress.c bzlib.c H5Zbzip2.c) SET(libmisc_SOURCES H5Zmisc.c H5Zutil.c h5misc.h) SET(libnoop_SOURCES H5Znoop.c H5Zutil.c h5noop.h) -SET(libnoop1_SOURCES H5Znoop1.c H5Zutil.c h5noop.h) +SET(libnoop1_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/H5Znoop1.c H5Zutil.c h5noop.h) IF(ENABLE_FILTER_TESTING) IF(BUILD_UTILITIES) @@ -46,7 +48,7 @@ SET_TARGET_PROPERTIES(noop PROPERTIES ARCHIVE_OUTPUT_NAME "noop") SET_TARGET_PROPERTIES(noop PROPERTIES RUNTIME_OUTPUT_NAME "noop") TARGET_LINK_LIBRARIES(noop ${ALL_TLL_LIBS}) -SET_SOURCE_FILES_PROPERTIES(H5Znoop1.c PROPERTIES COMPILE_OPTIONS -DNOOP_INSTANCE=1) +SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/H5Znoop1.c PROPERTIES COMPILE_OPTIONS -DNOOP_INSTANCE=1) ADD_LIBRARY(noop1 MODULE ${libnoop1_SOURCES}) SET_TARGET_PROPERTIES(noop1 PROPERTIES LIBRARY_OUTPUT_NAME "noop1") SET_TARGET_PROPERTIES(noop1 PROPERTIES ARCHIVE_OUTPUT_NAME "noop1")