Skip to content

Commit

Permalink
changed cmakelists to build lasambmi for running in the ngen and rela…
Browse files Browse the repository at this point in the history
…ted changes to the code (head needs to be initialized in the bmi_lgar.cxx instead in the main.cxx).
  • Loading branch information
ajkhattak committed Oct 18, 2022
1 parent 2479de9 commit a23cbb2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
67 changes: 58 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_COMPILER $ENV{CC})
set(CMAKE_CXX_COMPILER $ENV{CXX})

Expand All @@ -8,16 +11,28 @@ set(ColourReset "${Esc}[m")
set(Red "${Esc}[31m")
# module setup options

#option(BASE "BASE" ON)
option(NGEN "NGEN" OFF)
option(STANDALONE "STANDALONE" OFF)

if(NGEN)
message("ngen framework build!")
add_definitions(-DNGEN)
endif()

if(STANDALONE)
message("Standalone build!")
endif()

# set the project name
project(lgarc)
project(lasambmi VERSION 1.0.0 DESCRIPTION "OWP LASAM BMI Module Shared Library")
#project(lgarc)

set(CMAKE_BUILD_TYPE Debug)

IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build.")
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)

message(CMAKE_CXX_COMPILER " ${CMAKE_CXX_COMPILER}")
message(CMAKE_C_COMPILER " ${CMAKE_C_COMPILER}")
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
Expand All @@ -31,17 +46,51 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/X11/include")

# add the executable
message("CXXLIBS" ${CMAKE_CXX_FLAGS})
#message("CXXLIBS" ${CMAKE_CXX_FLAGS})


IF((NOT ${NGEN}) AND (NOT ${STANDALONE}))
message("Pseudo-framework build")
ENDIF((NOT ${NGEN}) AND (NOT ${STANDALONE}))

if(STANDALONE)
add_executable(lasam ./src/bmi_main_lgar.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.h ./giuh/giuh.c)
target_link_libraries(lasam PRIVATE m)
endif()




# ngen LASAM (add shared library)
set(LASAM_LIB_NAME_CMAKE lasambmi)
set(LASAM_LIB_DESC_CMAKE "OWP LASAM BMI Module Shared Library")

# Make sure these are compiled with this directive
add_compile_definitions(BMI_ACTIVE)

#add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
#target_include_directories(lasambmi PRIVATE include)

if(WIN32)
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
else()
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
endif()

target_include_directories(lasambmi PRIVATE include)

set_target_properties(lasambmi PROPERTIES VERSION ${PROJECT_VERSION})

#add_executable(xlgar ./src/main.c ./src/lgar.c ./src/soil_funcs.c ./src/linked_list.c ./src/mem_funcs.c ./src/util_funcs.c)
set_target_properties(lasambmi PROPERTIES PUBLIC_HEADER ./include/bmi_lgar.hxx)

#add_executable(xlgar ./src/main.cxx ./src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx)
include(GNUInstallDirs)

add_executable(xlgar ./src/bmi_main_lgar.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.h ./giuh/giuh.c)
install(TARGETS lasambmi
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

#add_library(cfelib ./smc_coupler/src/bmi_soil_moisture_profile.cxx ./smc_coupler/src/soil_moisture_profile.cxx ./smc_coupler/include/bmi_soil_moisture_profile.hxx ./smc_coupler/include/soil_moisture_profile.hxx)
configure_file(lasambmi.pc.in lasambmi.pc @ONLY)

install(FILES ${CMAKE_BINARY_DIR}/lasambmi.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

#target_link_libraries(xlgar LINK_PUBLIC xlgarlib)
target_link_libraries(xlgar PRIVATE m)

12 changes: 12 additions & 0 deletions lasambmi.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @LASAM_LIB_NAME_CMAKE@
Description: @LASAM_LIB_DESC_CMAKE@
Version: @PROJECT_VERSION@

Requires:
Libs: -L${libdir} -lmylib
Cflags: -I${includedir}
4 changes: 4 additions & 0 deletions src/bmi_lgar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@


string verbosity="none";
/* The `head` pointer stores the address in memory of the first member of the linked list containing all the wetting fronts. The contents of struct wetting_front are defined in "all.h" */

struct wetting_front *head = NULL;
struct wetting_front *state_previous = NULL;

void BmiLGAR::
Initialize (std::string config_file)
Expand Down
5 changes: 0 additions & 5 deletions src/bmi_main_lgar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ std::string GetForcingFile(std::string config_file);

void ReadForcingData(std::string config_file, std::vector<std::string>& time, std::vector<double>& precip, std::vector<double>& pet);

struct wetting_front *head = NULL; //<- this pointer stores the address in memory of the first member of the linked
// list containing all the wetting fronts. That address is called "head".
// The contents of struct wetting_front are defined in "all.h"

struct wetting_front *state_previous = NULL;

#define SUCCESS 0
int main(int argc, char *argv[])
Expand Down

0 comments on commit a23cbb2

Please sign in to comment.