Skip to content
Snippets Groups Projects
Commit 0fb50987 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

CMakeLists updated, removed scatted defines

parent 83a201ca
No related branches found
No related tags found
1 merge request!121M300433/cmake improvements and define cleanups
cmake_minimum_required( VERSION 3.27 FATAL_ERROR )
message(VERBOSE "Entering libcdi")
project(libcdi VERSION 2.5.1 LANGUAGES C )
project(cdilib VERSION 2.5.1 LANGUAGES C )
set(CMAKE_C_STANDARD 11)
include(CTest)
include(CheckIncludeFile)
# enable default internal libs
add_compile_definitions(HAVE_LIBGRIB=1)
add_compile_definitions(HAVE_LIBCGRIBEX=1)
add_compile_definitions(HAVE_LIBEXTRA=1)
add_compile_definitions(HAVE_LIBSERVICE=1)
add_compile_definitions(HAVE_LIBIEG=1)
list(APPEND cdi_compile_defs
HAVE_LIBGRIB=1
HAVE_LIBCGRIBEX=1
HAVE_LIBEXTRA=1
HAVE_LIBSERVICE=1
HAVE_LIBIEG=1
)
# ecCodes
find_package(eccodes)
if (${eccodes_FOUND})
add_compile_definitions(HAVE_LIBGRIB_API=${eccodes_FOUND})
list(APPEND cdi_compile_defs HAVE_LIBGRIB_API=${eccodes_FOUND})
message(VERBOSE "added compile definition HAVE_LIBGRIB_API=${eccodes_FOUND}")
else()
message(WARNING "netcdf not found, compiling without netcdf")
message(WARNING "eccodes not found, compiling without eccodes")
endif ()
# NetCDF
find_package(netCDF COMPONENTS C REQUIRED)
check_include_file("netcdf.h" ${netcdf_flag} C)
if (${netCDF_FOUND})
message(VERBOSE "added compile definition HAVE_LIBNETCDF=${netCDF_FOUND}")
message(VERBOSE "added compile definition HAVE_NETCDF4=${netCDF_FOUND}")
add_compile_definitions(HAVE_LIBNETCDF=${netCDF_FOUND})
add_compile_definitions(HAVE_NETCDF4=${netCDF_FOUND})
if (TARGET netCDF::netcdf)
list(APPEND cdi_compile_defs
HAVE_LIBNETCDF=${netCDF_FOUND}
HAVE_LIBNC_DAP=${netCDF_FOUND}
HAVE_NETCDF4=${netCDF_FOUND}
HAVE_LIBGRIB_API=${netCDF_FOUND}
HAVE_LIBGRIB=${netCDF_FOUND}
)
message(VERBOSE "added to list of definitions: ${cdi_compile_defs} ")
else()
message(WARNING "netcdf not found, compiling without netcdf")
endif ()
message(VERBOSE "looking for config.h in: ${PROJECT_BINARY_DIR}/src")
include_directories( "${PROJECT_BINARY_DIR}/src/config.h")
#adding subdirectories
## lib and general files
list(APPEND cdi_compile_defs CDI=1 CDI_SIZE_TYPE=size_t PACKAGE_NAME="${PROJECT_NAME}" VERSION="${CMAKE_PROJECT_VERSION}")
add_subdirectory(src)
## cdi executable
add_subdirectory(app)
#tests
add_subdirectory( tests )
add_subdirectory(app)
add_subdirectory(tests)
......@@ -2,8 +2,11 @@ add_executable(cdi
cdi.c printinfo.c
)
target_include_directories(cdi PUBLIC
target_include_directories(cdi PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include
)
target_link_libraries(cdi PUBLIC cdilib netCDF::netcdf pthread)
target_link_libraries(cdi PRIVATE cdilib netCDF::netcdf pthread)
target_include_directories(cdi PRIVATE "${PROJECT_BINARY_DIR}/src/config.h")
target_compile_definitions(cdi PRIVATE ${cdi_netcdf_definitions})
......@@ -195,7 +195,9 @@ add_library(cdilib
# INSTALL_HEADERS_LIST cdi.h
)
target_link_libraries(cdilib eccodes ${netCDF_LIBRARIES})
target_compile_definitions(cdilib PRIVATE CDI=1)
target_compile_definitions(cdilib PRIVATE PACKAGE_NAME="cdilib")
target_compile_definitions(cdilib PRIVATE VERSION="${CMAKE_PROJECT_VERSION}")
target_include_directories(cdilib PRIVATE "${PROJECT_BINARY_DIR}/src/config.h")
target_link_libraries(cdilib eccodes netCDF::netcdf)
target_compile_definitions(cdilib PRIVATE PACKAGE_NAME="${PROJECT_NAME}" VERSION="${CMAKE_PROJECT_VERSION}" ${cdi_compile_defs})
add_library(cdilib::cdilib ALIAS cdilib)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment