Skip to content

Commit

Permalink
Added code and cmake rules to allow source to compile into shared lib…
Browse files Browse the repository at this point in the history
…rary

 - This built successfully on Linux.
 - There are CMake rules added that should be cleaned.
 - The library wont compile on Linux because I added a unistd.h; need to figure out how to best chdir on Windows
[#80310170]
  • Loading branch information
Myoldmopar committed Oct 9, 2014
1 parent 27b6d52 commit b83cf8f
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(CPACK_PACKAGE_CONTACT "Kyle Benne <[email protected]>")
option( BUILD_PACKAGE "Build package" OFF )
option( BUILD_TESTING "Build testing targets" OFF )
option( BUILD_FORTRAN "Build Fortran stuff" OFF )
option( MAKE_ENERGYPLUS_LIBRARY "Make EnergyPlus into a shared library instead of an executable" OFF )

if( BUILD_TESTING )
option( ENABLE_REGRESSION_TESTING "Enable Regression Tests" OFF )
Expand Down Expand Up @@ -122,6 +123,11 @@ if( BUILD_FORTRAN )
cmake_add_fortran_subdirectory(src/ConvertESOMTR PROJECT ConvertESOMTR NO_EXTERNAL_INSTALL )
endif()

if ( MAKE_ENERGYPLUS_LIBRARY )
ADD_DEFINITIONS( " -DMAKE_ENERGYPLUS_LIBRARY " )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()

configure_file( idd/Energy+.idd.in "${CMAKE_BINARY_DIR}/Energy+.idd" )

if( BUILD_PACKAGE )
Expand Down
9 changes: 7 additions & 2 deletions src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,14 @@ SET( SRC
)

ADD_LIBRARY(EnergyPlusLib STATIC ${SRC})
ADD_EXECUTABLE(EnergyPlus main.cc main.hh)
if ( MAKE_ENERGYPLUS_LIBRARY )
ADD_LIBRARY(EnergyPlus SHARED main.cc main.hh)
ADD_DEFINITIONS( " -DMAKE_ENERGYPLUS_LIBRARY " )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
else()
ADD_EXECUTABLE(EnergyPlus main.cc main.hh)
endif()

#TARGET_LINK_LIBRARIES( EnergyPlus DElight )
TARGET_LINK_LIBRARIES( EnergyPlus EnergyPlusLib objexx sqlite bcvtb epexpat epfmiimport )

if(CMAKE_HOST_UNIX)
Expand Down
10 changes: 10 additions & 0 deletions src/EnergyPlus/DataGlobals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <DataGlobals.hh>
#include <DataPrecisionGlobals.hh>

#include <string>

namespace EnergyPlus {

namespace DataGlobals {
Expand Down Expand Up @@ -172,6 +174,14 @@ namespace DataGlobals {
bool ShowDecayCurvesInEIO( false ); // true if the Radiant to Convective Decay Curves should appear in the EIO file
bool AnySlabsInModel ( false ); // true if there are any zone-coupled ground domains in the input file

bool IsDLL( false ); // set to true if running as a DLL
bool IsProgressCallback( false ); // set to true if a progress callback function is to be called (only if running as a DLL)
bool IsMessageCallback( false ); // set to true if a message callback function is to be called (only if running as a DLL)
bool IsProgramFatalCallback( false ); // set to true if a program fatal callback function is to be called (only if running as a DLL)
int Progress( 0 ); // current progress (0-100)
void ( *fProgressPtr )( int );
void ( *fMessagePtr )( std::string );

// NOTICE
// Copyright © 1996-2014 The Board of Trustees of the University of Illinois
// and The Regents of the University of California through Ernest Orlando Lawrence
Expand Down
8 changes: 8 additions & 0 deletions src/EnergyPlus/DataGlobals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ namespace DataGlobals {
extern bool ShowDecayCurvesInEIO; // true if the Radiant to Convective Decay Curves should appear in the EIO file
extern bool AnySlabsInModel; // true if there are any zone-coupled ground domains in the input file

extern bool IsDLL;
extern bool IsProgressCallback;
extern bool IsMessageCallback;
extern bool IsProgramFatalCallback;
extern int Progress;
extern void ( *fProgressPtr )( int );
extern void ( *fMessagePtr )( std::string );

} // DataGlobals

} // EnergyPlus
Expand Down
30 changes: 28 additions & 2 deletions src/EnergyPlus/DisplayRoutines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <DisplayRoutines.hh>
#include <DataGlobals.hh>
#include <DataSystemVariables.hh>
#include <sstream>

namespace EnergyPlus {

Expand All @@ -32,6 +33,9 @@ DisplayString( std::string const & String ) // String to be displayed

// Using/Aliasing
using DataGlobals::KickOffSimulation;
using DataGlobals::IsDLL;
using DataGlobals::IsMessageCallback;
using DataGlobals::fMessagePtr;
using DataSystemVariables::DeveloperFlag;

// Locals
Expand All @@ -48,6 +52,11 @@ DisplayString( std::string const & String ) // String to be displayed
// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
// na

if (IsDLL && IsMessageCallback)
{
fMessagePtr(String);
}

if ( KickOffSimulation && ! DeveloperFlag ) return;
std::cout << String << '\n';

Expand Down Expand Up @@ -79,7 +88,10 @@ DisplayNumberAndString(
// Using/Aliasing
using DataGlobals::KickOffSimulation;
using DataSystemVariables::DeveloperFlag;

using DataGlobals::IsDLL;
using DataGlobals::IsMessageCallback;
using DataGlobals::fMessagePtr;

// Locals
// SUBROUTINE ARGUMENT DEFINITIONS:

Expand All @@ -92,7 +104,13 @@ DisplayNumberAndString(
// na

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:

if (IsDLL && IsMessageCallback)
{
std::stringstream sstm;
sstm << String << " " << Number;
fMessagePtr( sstm.str() );
}

if ( KickOffSimulation && ! DeveloperFlag ) return;
std::cout << String << ' ' << Number << '\n';
}
Expand Down Expand Up @@ -122,6 +140,9 @@ DisplaySimDaysProgress( // This doesn't do anything!

// Using/Aliasing
using DataGlobals::KickOffSimulation;
using DataGlobals::IsDLL;
using DataGlobals::IsProgressCallback;
using DataGlobals::fProgressPtr;
using DataSystemVariables::DeveloperFlag;

// Locals
Expand All @@ -139,6 +160,11 @@ DisplaySimDaysProgress( // This doesn't do anything!
// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
static int percent( 0 ); // Current percent progress

if (IsDLL && IsProgressCallback)
{
fProgressPtr( percent );
}

if ( KickOffSimulation && ! DeveloperFlag ) return;
if ( TotalSimDays > 0 ) {
percent = nint( ( CurrentSimDay / TotalSimDays ) * 100.0 );
Expand Down
39 changes: 39 additions & 0 deletions src/EnergyPlus/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@
#include <SimulationManager.hh>
#include <UtilityRoutines.hh>

#ifdef __unix__
#include <unistd.h>
#endif

#ifdef MAKE_ENERGYPLUS_LIBRARY
void
EnergyPlusPgm( std::string filepath )
#else
int
main()
#endif
{
// Using/Aliasing
using namespace EnergyPlus;
Expand Down Expand Up @@ -241,6 +250,10 @@ main()
int iostatus;
bool FileExists;

#ifdef MAKE_ENERGYPLUS_LIBRARY
IsDLL = true;
#endif

// INITIALIZE VARIABLES
Time_Start = epElapsedTime();
#ifdef EP_Detailed_Timings
Expand Down Expand Up @@ -372,6 +385,12 @@ main()
gio::write( LFN, EPlusiniFormat ) << "program" << ProgramPath;
gio::close( LFN );
}

#ifdef MAKE_ENERGYPLUS_LIBRARY
int status = chdir(filepath.c_str());
ProgramPath = filepath + pathChar;
#endif

TestAllPaths = true;

DisplayString( "EnergyPlus Starting" );
Expand Down Expand Up @@ -403,6 +422,26 @@ main()
EndEnergyPlus();
}

#ifdef MAKE_ENERGYPLUS_LIBRARY
void StoreProgressCallback( void ( *f )( int ) )
{
using namespace EnergyPlus::DataGlobals;
//using DataGlobals::IsProgressCallback;
//using DataGlobals::fProgressPtr;
IsProgressCallback = true;
fProgressPtr = f;
}
void StoreMessageCallback( void ( *f )( std::string ) )
{
using namespace EnergyPlus::DataGlobals;
//using DataGlobals::IsMessageCallback;
//using DataGlobals::fMessagePtr;
IsMessageCallback = true;
fMessagePtr = f;
}
#endif


void
CreateCurrentDateTimeString( std::string & CurrentDateTimeString )
{
Expand Down
8 changes: 8 additions & 0 deletions src/EnergyPlus/main.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@
std::string & DataOut // Output from the retrieval
);

#ifdef MAKE_ENERGYPLUS_LIBRARY
void
StoreProgressCallback( void ( *f )( int ) );

void
StoreMessageCallback( void ( *f )( std::string ) );

#endif

#endif
4 changes: 4 additions & 0 deletions third_party/ObjexxFCL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if(MSVC)
ADD_DEFINITIONS("-Za") # Disables MS language extensions
endif()

if ( MAKE_ENERGYPLUS_LIBRARY )
ADD_DEFINITIONS( " -DMAKE_ENERGYPLUS_LIBRARY " )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()

set(src
src/ObjexxFCL/array.iterator.hh
Expand Down
5 changes: 5 additions & 0 deletions third_party/SQLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ SET(SRC
sqlite3.c
)

if ( MAKE_ENERGYPLUS_LIBRARY )
ADD_DEFINITIONS( " -DMAKE_ENERGYPLUS_LIBRARY -fPIC" )
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()

ADD_LIBRARY( sqlite ${SRC} )

4 comments on commit b83cf8f

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80310170-EnergyPlusLibrary (Myoldmopar) - x86_64-MacOS-10.9-clang: OK (939 of 956 tests passed)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80310170-EnergyPlusLibrary (Myoldmopar) - i386-Windows-7-VisualStudio-12: OK (955 of 956 tests passed)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80310170-EnergyPlusLibrary (Myoldmopar) - x86_64-MacOS-10.9-clang-Debug: OK (934 of 956 tests passed)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80310170-EnergyPlusLibrary (Myoldmopar) - Win64-Windows-7-VisualStudio-12: OK (955 of 956 tests passed)

Build Badge Test Badge

Please sign in to comment.