diff --git a/CMakeLists.txt b/CMakeLists.txt index daab7594..059e966a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,8 +63,8 @@ option (COOLPROP_EES_MODULE "Build the EES module" OFF) -option (COOLPROP_EXCEL_MODULE - "Build the Excel add-in installer" +option (COOLPROP_WINDOWS_PACKAGE + "Build the Windows installer" OFF) option (BUILD_TESTING @@ -487,137 +487,207 @@ if (COOLPROP_MATHCAD15_MODULE) install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/MathCAD/CoolProp_EN.xml" DESTINATION MathCAD15) endif() -# EES is only compiled for windows +# EES is only compiled for 32bit Windows if (COOLPROP_EES_MODULE) - list (APPEND APP_SOURCES "wrappers/EES/main.cpp") - list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CoolPropLib.cpp") + IF (NOT "${BITNESS}" STREQUAL "32") + MESSAGE(FATAL_ERROR "You cannot build the EES wrapper as a 64-bit library.") + ENDIF() + # Prepare the sources include_directories(${APP_INCLUDE_DIRS}) + list (APPEND APP_SOURCES "wrappers/EES/main.cpp") + list (APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_SOURCE}") add_library(COOLPROP_EES SHARED ${APP_SOURCES}) + # Modify the target and add dependencies + add_dependencies (COOLPROP_EES generate_headers) set_target_properties (COOLPROP_EES PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DCOOLPROP_LIB -DCONVENTION=__cdecl") - add_dependencies (COOLPROP_EES generate_headers) - set_target_properties(COOLPROP_EES PROPERTIES SUFFIX ".dlf" PREFIX "") - message(STATUS "Injecting the version COOLPROP_VERSION=${COOLPROP_VERSION}") - # Put the version into the InnoInstaller setup file - CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/wrappers/EES/BuildInnoInstaller.iss.in" "${CMAKE_CURRENT_BINARY_DIR}/BuildInnoInstaller.iss") - if (NOT MSVC) - set_target_properties(COOLPROP_EES PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") - endif() - - add_dependencies (COOLPROP_EES generate_headers) - - if ( MSVC ) - set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}) - set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties (COOLPROP_EES PROPERTIES SUFFIX ".dlf" PREFIX "") + # Creates "COOLPROP_EES.dlf" + if ( NOT MSVC ) + set_target_properties (COOLPROP_EES PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") + elseif ( MSVC ) + set_target_properties (COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) + set_target_properties (COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties (COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}) # etc for the other available configuration types (MinSizeRel, RelWithDebInfo) endif () # copy required files - set(REQUIRED_FILES - CoolProp.htm - CoolProp.LIB - CoolProp_EES_Sample.EES - ) - foreach (_FILE ${REQUIRED_FILES}) - add_custom_command(TARGET COOLPROP_EES - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/EES/${_FILE} ${CMAKE_CURRENT_BINARY_DIR}/.) - endforeach() - - # Run InnoSetup to make the installer (must be on your path) - add_custom_command(TARGET COOLPROP_EES - POST_BUILD - COMMAND iscc /cc BuildInnoInstaller.iss - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - # install the generated executable installer from InnoSetup - install( - CODE "file( INSTALL ${CMAKE_CURRENT_BINARY_DIR}/Output/SetupCOOLPROP_EES.exe DESTINATION ${CMAKE_INSTALL_PREFIX}/EES/${CMAKE_SYSTEM_NAME} )" + add_custom_command (TARGET COOLPROP_EES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/EES/CoolProp.htm" "${CMAKE_CURRENT_BINARY_DIR}/." + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/EES/CoolProp.LIB" "${CMAKE_CURRENT_BINARY_DIR}/." + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/EES/CoolProp_EES_Sample.EES" "${CMAKE_CURRENT_BINARY_DIR}/." + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Copying the EES files to the build directory" + VERBATIM ) + ## install the generated executable installer from InnoSetup + #install( + # CODE "file( INSTALL ${CMAKE_CURRENT_BINARY_DIR}/Output/SetupCOOLPROP_EES.exe DESTINATION ${CMAKE_INSTALL_PREFIX}/EES/${CMAKE_SYSTEM_NAME} )" + #) endif() -# Excel add-in -if (COOLPROP_EXCEL_MODULE) - message(STATUS "Creating Excel add-in for COOLPROP_VERSION=${COOLPROP_VERSION}") +# Windows package +if (COOLPROP_WINDOWS_PACKAGE) + + message(STATUS "Creating Windows installer for COOLPROP_VERSION=${COOLPROP_VERSION}") # Setting some basic build paths - set(COOLPROP_EXCEL_32B_DIR "${CMAKE_CURRENT_BINARY_DIR}/32bitDLL") - set(COOLPROP_EXCEL_32B_DIR_ALT "${CMAKE_CURRENT_BINARY_DIR}/32bitDLL_cdecl") - set(COOLPROP_EXCEL_64B_DIR "${CMAKE_CURRENT_BINARY_DIR}/64bitDLL") - set(COOLPROP_EXCEL_TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/InnoScript") + set(COOLPROP_WINDOWS_PACKAGE_32B_DIR "${CMAKE_CURRENT_BINARY_DIR}/32bitDLL") + set(COOLPROP_WINDOWS_PACKAGE_32B_DIR_STDCALL "${CMAKE_CURRENT_BINARY_DIR}/32bitDLL_stdcall") + set(COOLPROP_WINDOWS_PACKAGE_32B_DIR_CDECL "${CMAKE_CURRENT_BINARY_DIR}/32bitDLL_cdecl") + set(COOLPROP_WINDOWS_PACKAGE_64B_DIR "${CMAKE_CURRENT_BINARY_DIR}/64bitDLL") + set(COOLPROP_WINDOWS_PACKAGE_EES_DIR "${CMAKE_CURRENT_BINARY_DIR}/EES") + set(COOLPROP_WINDOWS_PACKAGE_TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/InnoScript") # Pointers to the sources - set(COOLPROP_EXCEL_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Excel") - set(COOLPROP_EXCEL_ISS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals/ExcelAddinInstaller") + set(COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Excel") + set(COOLPROP_WINDOWS_PACKAGE_ISS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals/ExcelAddinInstaller") # Generator for DLLs - set(COOLPROP_EXCEL_DLL_GEN "Visual Studio 10 2010") + set(COOLPROP_WINDOWS_PACKAGE_DLL_GEN "Visual Studio 10 2010") # Configure variables like version number and build year - CONFIGURE_FILE("${COOLPROP_EXCEL_ISS_DIR}/cmake-templates/config.iss" "${COOLPROP_EXCEL_ISS_DIR}/config.iss") + CONFIGURE_FILE("${COOLPROP_WINDOWS_PACKAGE_ISS_DIR}/cmake-templates/config.iss" "${COOLPROP_WINDOWS_PACKAGE_ISS_DIR}/config.iss") # Find the installer generator executable SET(BINDIR32_ENV_NAME "ProgramFiles(x86)") SET(BINDIR32 $ENV{${BINDIR32_ENV_NAME}}) SET(BINDIR64_ENV_NAME "ProgramFiles") SET(BINDIR64 $ENV{${BINDIR64_ENV_NAME}}) - find_program (COOLPROP_EXCEL_ISS_EXE + find_program (COOLPROP_WINDOWS_PACKAGE_ISS_EXE NAMES iscc.exe HINTS "${BINDIR32}/Inno Setup 5" "${BINDIR64}/Inno Setup 5" ) - #message(STATUS "COOLPROP_EXCEL_ISS_EXE='${COOLPROP_EXCEL_ISS_EXE}'") - # ************************************************************* - # Add the target for Excel and populate it with custom commands - # ************************************************************* - add_custom_target(COOLPROP_EXCEL) + + # ****************************************************************** + # Add the targets that prepare the build directory for the subbuilds + # ****************************************************************** + add_custom_target(COOLPROP_WINDOWS_PACKAGE_PREPARE) # Prepare directories - add_custom_command(TARGET COOLPROP_EXCEL PRE_BUILD - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_32B_DIR}" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_32B_DIR_ALT}" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_64B_DIR}" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_TMP_DIR}" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_TMP_DIR}/source" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_EXCEL_TMP_DIR}/deploy" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_TMP_DIR}/deploy" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_EXCEL_TMP_DIR}/bin" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_EXCEL_TMP_DIR}/bin" + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_PREPARE PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR_STDCALL}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR_CDECL}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_64B_DIR}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_EES_DIR}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source" + #COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/deploy" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/deploy" + #COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Preparing the directories for the Excel installer" + COMMENT "Preparing the directories for the Windows installer" VERBATIM ) - # Build the 32bit DLLs - add_custom_command(TARGET COOLPROP_EXCEL PRE_BUILD - COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_EXCEL_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" "-DCOOLPROP_STDCALL_LIBRARY=ON" + + add_custom_target(COOLPROP_WINDOWS_PACKAGE_DELETE) + # Delete directories + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_DELETE PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/deploy" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/deploy" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "remove_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "make_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Removing the old build directories for the Windows installer" + VERBATIM ) + + # ************************************************************** + # Add the target for the shared libraries, 3x 32bit and 1x 64bit + # ************************************************************** + add_custom_target(COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES COOLPROP_WINDOWS_PACKAGE_PREPARE) + # Copy the header file + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/include/CoolPropLib.h" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolPropLib.h" + WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_32B_DIR} + COMMENT "Copy the header file for the CoolProp library" + VERBATIM ) + # # Build the 32bit DLLs + # add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES PRE_BUILD + # COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_WINDOWS_PACKAGE_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" + # COMMAND ${CMAKE_COMMAND} ARGS "--build" "." "--target" "CoolProp" "--config" "Release" + # COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_x86.dll" + # WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_32B_DIR} + # COMMENT "Building the 32bit shared library with default settings" + # VERBATIM ) + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_WINDOWS_PACKAGE_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" "-DCOOLPROP_STDCALL_LIBRARY=ON" COMMAND ${CMAKE_COMMAND} ARGS "--build" "." "--target" "CoolProp" "--config" "Release" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_32B_DIR}/Release/CoolProp.dll" "${COOLPROP_EXCEL_TMP_DIR}/source/CoolProp_xls_std.dll" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_32B_DIR}/Release/CoolProp.dll" "${COOLPROP_EXCEL_TMP_DIR}/source/CoolProp_stdcall.dll" - WORKING_DIRECTORY ${COOLPROP_EXCEL_32B_DIR} + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_xls_std.dll" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR_STDCALL}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_stdcall.dll" + WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_32B_DIR_STDCALL} COMMENT "Building the 32bit shared library with stdcall" VERBATIM ) - add_custom_command(TARGET COOLPROP_EXCEL PRE_BUILD - COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_EXCEL_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" "-DCOOLPROP_CDECL_LIBRARY=ON" + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_WINDOWS_PACKAGE_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" "-DCOOLPROP_CDECL_LIBRARY=ON" COMMAND ${CMAKE_COMMAND} ARGS "--build" "." "--target" "CoolProp" "--config" "Release" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_32B_DIR_ALT}/Release/CoolProp.dll" "${COOLPROP_EXCEL_TMP_DIR}/source/CoolProp_cdecl.dll" - WORKING_DIRECTORY ${COOLPROP_EXCEL_32B_DIR_ALT} + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_32B_DIR_CDECL}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_cdecl.dll" + WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_32B_DIR_CDECL} COMMENT "Building the 32bit shared library with cdecl" VERBATIM ) # Build the 64bit DLL - add_custom_command(TARGET COOLPROP_EXCEL PRE_BUILD - COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_EXCEL_DLL_GEN} Win64" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_WINDOWS_PACKAGE_DLL_GEN} Win64" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_SHARED_LIBRARY=ON" COMMAND ${CMAKE_COMMAND} ARGS "--build" "." "--target" "CoolProp" "--config" "Release" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_64B_DIR}/Release/CoolProp.dll" "${COOLPROP_EXCEL_TMP_DIR}/source/CoolProp_xls_x64.dll" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_64B_DIR}/Release/CoolProp.dll" "${COOLPROP_EXCEL_TMP_DIR}/source/CoolProp_x64.dll" - WORKING_DIRECTORY ${COOLPROP_EXCEL_64B_DIR} + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_64B_DIR}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_xls_x64.dll" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_64B_DIR}/Release/CoolProp.dll" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/CoolProp_x64.dll" + WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_64B_DIR} COMMENT "Building the 64bit shared library" VERBATIM ) - # Copy the files - add_custom_command(TARGET COOLPROP_EXCEL PRE_BUILD - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_SRC_DIR}/CoolProp.xla" "${COOLPROP_EXCEL_TMP_DIR}/source/" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_SRC_DIR}/CoolProp.xlam" "${COOLPROP_EXCEL_TMP_DIR}/source/" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_EXCEL_SRC_DIR}/TestExcel.xlsx" "${COOLPROP_EXCEL_TMP_DIR}/source/" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_EXCEL_ISS_DIR}" "${COOLPROP_EXCEL_TMP_DIR}" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Copying the Excel and Inno Script files for the installer" + + # ************************************************************* + # Add the target for EES and populate it with custom commands + # ************************************************************* + add_custom_target(COOLPROP_WINDOWS_PACKAGE_EES) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_EES COOLPROP_WINDOWS_PACKAGE_PREPARE) + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_EES PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-G${COOLPROP_WINDOWS_PACKAGE_DLL_GEN}" "${CMAKE_CURRENT_SOURCE_DIR}" "-DCOOLPROP_EES_MODULE=ON" + COMMAND ${CMAKE_COMMAND} ARGS "--build" "." "--target" "COOLPROP_EES" "--config" "Release" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_WINDOWS_PACKAGE_EES_DIR}" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/EES" + WORKING_DIRECTORY ${COOLPROP_WINDOWS_PACKAGE_EES_DIR} + COMMENT "Building the 32bit library for EES" VERBATIM ) + + # ************************************************************* + # Add the target for Excel and populate it with custom commands + # ************************************************************* + add_custom_target(COOLPROP_WINDOWS_PACKAGE_EXCEL) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_EXCEL COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES COOLPROP_WINDOWS_PACKAGE_PREPARE) + # Copy the Excel files + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_EXCEL PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/CoolProp.xla" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/CoolProp.xlam" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/TestExcel.xlsx" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/source/" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/CoolProp.xla" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin/MicrosoftExcel/" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/CoolProp.xlam" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin/MicrosoftExcel/" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy" "${COOLPROP_WINDOWS_PACKAGE_EXCEL_DIR}/TestExcel.xlsx" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin/MicrosoftExcel/" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Copying the Excel files for the installer" + VERBATIM ) + + # ******************************************************************* + # Add the target for Inno Script and populate it with custom commands + # ******************************************************************* + add_custom_target(COOLPROP_WINDOWS_PACKAGE_ISS) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_ISS COOLPROP_WINDOWS_PACKAGE_EXCEL COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES COOLPROP_WINDOWS_PACKAGE_PREPARE) + # Copy the ISS files + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_ISS PRE_BUILD + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_WINDOWS_PACKAGE_ISS_DIR}" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Copying the Inno Script files for the installer" + VERBATIM ) + + # ***************************************************************************** + # Add the target for the installer package and populate it with custom commands + # ***************************************************************************** + add_custom_target(COOLPROP_WINDOWS_PACKAGE_INSTALLER) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_DELETE) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_PREPARE) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_SHARED_LIBRARIES) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_EES) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_EXCEL) + add_dependencies (COOLPROP_WINDOWS_PACKAGE_INSTALLER COOLPROP_WINDOWS_PACKAGE_ISS) # Build the installer and copy it to the bin directory - add_custom_command(TARGET COOLPROP_EXCEL POST_BUILD - COMMAND ${COOLPROP_EXCEL_ISS_EXE} ARGS "addin-installer.iss" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_EXCEL_TMP_DIR}/deploy" "${COOLPROP_EXCEL_TMP_DIR}/bin/MicrosoftExcel" - COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_EXCEL_TMP_DIR}/deploy" "${COOLPROP_EXCEL_TMP_DIR}/bin/shared_library/Windows" - WORKING_DIRECTORY "${COOLPROP_EXCEL_TMP_DIR}" - COMMENT "The new installer is located in '${COOLPROP_EXCEL_TMP_DIR}/bin/MicrosoftExcel' and '${COOLPROP_EXCEL_TMP_DIR}/bin/shared_library/Windows'" + add_custom_command(TARGET COOLPROP_WINDOWS_PACKAGE_INSTALLER POST_BUILD + COMMAND ${COOLPROP_WINDOWS_PACKAGE_ISS_EXE} ARGS "addin-installer.iss" + COMMAND ${CMAKE_COMMAND} ARGS "-E" "copy_directory" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/deploy" "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin/installer/Windows" + WORKING_DIRECTORY "${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}" + COMMENT "The new installer is located in '${COOLPROP_WINDOWS_PACKAGE_TMP_DIR}/bin/installer/Windows'" VERBATIM ) endif() diff --git a/Web/coolprop/wrappers/Excel/index.rst b/Web/coolprop/wrappers/Excel/index.rst index 21e3d193..a8bd543c 100644 --- a/Web/coolprop/wrappers/Excel/index.rst +++ b/Web/coolprop/wrappers/Excel/index.rst @@ -7,38 +7,44 @@ Excel Wrapper Pre-compiled Binaries for windows ================================= -Pre-compiled release binaries can be downloaded from :sfdownloads:`MicrosoftExcel`. Development binaries coming from the buildbot server can be found at :sfnightly:`MicrosoftExcel`. -Download all the files. The basic protocol is: +Automated Installation +---------------------- +As of October 2016, the Excel wrapper for Microsoft Windows can installed from the Windows package as described on the :ref:`page on installation packages `. Please refer to the documentation there for issues related to the installation process on Windows. -Part 1: -------- -1. Copy the files CoolProp.dll and CoolProp_x64.dll to c:\\CoolProp folder. Technically you only need the DLL that matches your system architecture (CoolProp.dll = 32-bit, CoolProp_x64.dll = 64-bit), but it can't hurt to copy both if you don't know which system architecture version you have. +Manual Installation +------------------- +For a manual installation, -Part 2: -------- -1. Open Excel -2. Determine the trusted directory for addins by going to File->Options...->Trust Center->Trust Center Settings...->Trusted Locations . Note the add-ins directory. Put your CoolProp.xlam in that directory -3. Go to the menu File-->Options-->Add-Ins -4. At the bottom, select Manage: Excel Add-ins, then click the Go.. button -5. Click the browse button -6. Browse to the file CoolProp.xlam you downloaded, select it (if necessary, CoolProp might already be visible) -7. Make sure the CoolProp Add-in is selected. -8. Open the file TestExcel.xlsx and try to re-evaluate one of the cells - they should work now +1. Get the shared libraries at :sfdownloads:`shared_library/Windows/32bit__stdcall` and :sfdownloads:`shared_library/Windows/64bit`, put the DLLs into a folder of your choice and rename them to `CoolProp_stdcall.dll` and `CoolProp_x64.dll`. Make sure to add that folder to your path. Technically you only need the DLL that matches your system architecture (`CoolProp_stdcall.dll` = 32-bit, `CoolProp_x64.dll` = 64-bit), but it can’t hurt to copy both if you don’t know which system architecture version you have. The Excel macro will select the correct one and use it. +2. Download the xla and xlam files from :sfdownloads:`MicrosoftExcel` and activate the add-in from Excel as described below. and copy the files to a convenient accessible location. +3. The **TestExcel.xlsx** from :sfdownloads:`MicrosoftExcel` can be copied to a working directory in ``My Documents``. -If you are trying to over-write the CoolProp xlam, you should: -a) In Excel, determine the location of the CoolProp xlam that it wants to load by going to Addins menu -b) Move the xlam somewhere else temporarily -c) In Excel, uncheck the CoolProp add-in - it might have already warned about the addin not being in the right place -d) Restart Excel. Check that the addin has been removed, or at least the path is not the old path to CoolProp -e) Determine the trusted directory for addins by going to File->Options...->Trust Center->Trust Center Settings...->Trusted Locations . Note the add-ins directory. Put your CoolProp.xlam in that directory -f) In Excel, add the add-in for CoolProp again by checking it and browsing to the correct location -g) Restart Excel, add-in should still be there. +1. Open Excel +2. Go to the menu ``File–>Options–>Add-Ins`` +3. At the bottom, select ``Manage: Excel Add-ins``, then click the ``Go...`` button +4. Click the ``Browse`` button on the Add-in Manager panel +5. Browse to the file **CoolProp.xlam** you downloaded and select it +6. Make sure the CoolProp Add-in is selected (box checked) and close the Add-in Manager. +7. Open the file **TestExcel.xlsx** and try to re-evaluate one of the cells; the CoolProp formulas should all be working now. (To recalculate the entire worksheet, press ``Ctrl``-``Alt``-``Shift``-``F9`` ) [#]_ -.. note:: +.. [#] **Alertnate DLL Location** - Some environments, lock down the folders included in the binary search path for normal users for security reasons. If this is the case, you will need to put the DLL files in an alternate location (possibly on a shared network location for all users). Follow the instructions below: + + 1. Place the CoolProp DLL files in the alternate location + 2. Place the CoolProp xlam file in a writable location and open it. + 3. You will get an Excel error, ``File not found - CoolProp_stdcall.dll``. Clicking **Ok** on the error will only clear the first of many. Press and hold the **``Enter``** key until all of the errors clear. + 4. Make sure that the Developer ribbon is visible on the main menu. If not + + - Go to **File | Options** on the main menu and select Cusomize Ribbon + - Make sure that the Developer main tab is checked (ON) + + 5. Open the Visual Basic editor and use **Edit | Replace** to replace all occurances of **CoolProp_stdcall.dll** with the full path to the alternate location for your DLL files, making sure to press the save button (disk image) or **File | Save** before exiting the VBA editor. + 6. Save the CoolProp.xlam file. + + +.. [#] If you are having problems with the path to the XLAM in your worksheet appearing as the complete path to the xlam (but not the correct path), you might need to go into ``Data->Update Links`` in Excel, select CoolProp.xlam, and select ``Change Source...`` and select the location of your xlam file. That should update all the links. - If you are having problems with the path to the XLAM in your worksheet appearing as the complete path to the xlam (but not the correct path), you might need to go into ``Data->Update Links`` in Excel, select CoolProp.xlam, and select "Change Source..." and select the location of your xlam file. That should update all the links. Pre-compiled Binaries for OSX ============================= diff --git a/Web/coolprop/wrappers/index.rst b/Web/coolprop/wrappers/index.rst index d737da67..a11195ec 100644 --- a/Web/coolprop/wrappers/index.rst +++ b/Web/coolprop/wrappers/index.rst @@ -6,6 +6,8 @@ Available Wrappers CoolProp at its core is a C++ library, but it can be of interest to use this code base from other programming environments. For that reason, wrappers have been constructed for most of the programming languages of technical interest to allow users to seamlessly interface CoolProp and existing codebases. +There are also installer packages availbale on the :ref:`page on installation packages `. + Downloads and instructions for each wrapper are included in the page for the wrapper given in the table below. ======================================================= =========================== ======================================= diff --git a/dev/buildbot/master/master.cfg b/dev/buildbot/master/master.cfg index 713937c2..e23b7be4 100644 --- a/dev/buildbot/master/master.cfg +++ b/dev/buildbot/master/master.cfg @@ -680,23 +680,23 @@ def python_manylinux_builder(bitness="64"): # # return factory -def excel_slave(): +def windows_installer_slave(): """ """ working_folder = "build/build" output_folder = "build/build/InnoScript/deploy" - # Create the factory to add the actions to build the Excel add-in installer + # Create the factory to add the actions to build the Windows installer factory = getBaseFactory() factory.addStep(MakeDirectory(dir=working_folder, haltOnFailure = True)) factory.addStep(RemoveDirectory(dir=output_folder, haltOnFailure = False)) - factory.addStep(ShellCommand(command=["cmake", "..", "-DCOOLPROP_EXCEL_MODULE=ON","-G", "Visual Studio 10 Win64"], + factory.addStep(ShellCommand(command=["cmake", "..", "-DCOOLPROP_WINDOWS_PACKAGE=ON","-G", "Visual Studio 10 Win64"], workdir= working_folder, haltOnFailure = True)) - factory.addStep(ShellCommand(command=["cmake", "--build", ".", "--target", "COOLPROP_EXCEL"], + factory.addStep(ShellCommand(command=["cmake", "--build", ".", "--target", "COOLPROP_WINDOWS_PACKAGE_INSTALLER"], workdir = working_folder, haltOnFailure = True)) # Upload the files - factory.addStep(DirectoryUpload(slavesrc="build/InnoScript/bin",masterdest=master_loc_rel,url="MicrosoftExcel",compress="bz2")) + factory.addStep(DirectoryUpload(slavesrc="build/InnoScript/bin",masterdest=master_loc_rel,url="installer",compress="bz2")) fixPermissions(factory) return factory @@ -1030,9 +1030,9 @@ c['builders'] = [] # ) c['builders'].append( - BuilderConfig(name="Excel", + BuilderConfig(name="Windows installer", slavenames=["windows-DTU-slave"], - factory = excel_slave() ) ) + factory = windows_installer_slave() ) ) c['builders'].append( BuilderConfig(name="MathCAD", slavenames=["windows-slave"], diff --git a/externals/ExcelAddinInstaller b/externals/ExcelAddinInstaller index 338700e9..ba5d2562 160000 --- a/externals/ExcelAddinInstaller +++ b/externals/ExcelAddinInstaller @@ -1 +1 @@ -Subproject commit 338700e9c693f82f5152edcd73f1a9492e160fab +Subproject commit ba5d2562539ab744e35010f53eb6abcfcfdb358c diff --git a/wrappers/Excel/CoolProp.xla b/wrappers/Excel/CoolProp.xla index 9898601e..5f17554a 100644 Binary files a/wrappers/Excel/CoolProp.xla and b/wrappers/Excel/CoolProp.xla differ diff --git a/wrappers/Excel/CoolProp.xlam b/wrappers/Excel/CoolProp.xlam index b01ac55e..b91bc8bf 100644 Binary files a/wrappers/Excel/CoolProp.xlam and b/wrappers/Excel/CoolProp.xlam differ diff --git a/wrappers/Excel/README.rst b/wrappers/Excel/README.rst deleted file mode 100644 index 0eb6a157..00000000 --- a/wrappers/Excel/README.rst +++ /dev/null @@ -1,191 +0,0 @@ -Excel Wrapper -============= - -Pre-compiled Binaries for windows ---------------------------------- - -Pre-compiled release binaries can be downloaded from `MicrosoftExcel `_ . Development binaries coming from the buildbot server can be found at `MicrosoftExcel `_. - -Download all the files. The basic protocol is: - -**Part 1:** - -1. Copy the files **CoolProp.dll** and **CoolProp_x64.dll** to **C:\\CoolProp** [#]_ folder. Technically you only need the DLL that matches your system architecture (`CoolProp.dll` = 32-bit, `CoolProp_x64.dll` = 64-bit), but it can’t hurt to copy both if you don’t know which system architecture version you have. The excel macro will select the correct one and use it. -2. Copy the file **CoolProp.xlam** to a convenient accessible location (it could go in the C:\\CoolProp folder as well). -3. **CoolProp.xlsx** can be copied to a working directory in ``My Documents``. - -**Part 2:** - -1. Open Excel -2. Go to the menu ``File–>Options–>Add-Ins`` -3. At the bottom, select ``Manage: Excel Add-ins``, then click the ``Go...`` button -4. Click the ``Browse`` button on the Add-in Manager panel -5. Browse to the file **CoolProp.xlam** you downloaded and select it -6. Make sure the CoolProp Add-in is selected (box checked) and close the Add-in Manager. -7. Open the file **TestExcel.xlsx** and try to re-evaluate one of the cells; the CoolProp formulas should all be working now. (To recalculate the entire worksheet, press ``Ctrl``-``Alt``-``Shift``-``F9`` ) [#]_ - -.. [#] **Alertnate DLL Location** - Some environments, lock down the C:\\ drive from normal users for security reasons. If this is the case, you will need to put the DLL files in an alternate location (possibly on a shared network location for all users). Follow the instructions below: - - 1. Place the CoolProp DLL files in the alternate location - 2. Place the CoolProp xlam file in a writable location and open it. - 3. You will get an Excel error, ``File not found - C:\CoolProp\CoolProp.dll``. Clicking **Ok** on the error will only clear the first of many. Press and hold the **``Enter``** key until all of the errors clear. - 4. Make sure that the Developer ribbon is visible on the main menu. If not - - - Go to **File | Options** on the main menu and select Cusomize Ribbon - - Make sure that the Developer main tab is checked (ON) - - 5. Open the Visual Basic editor and use **Edit | Replace** to replace all occurances of **C:\\CoolProp** with the path to the alternate location for your CoolProp.dll files, making sure to press the save button (disk image) or **File | Save** before exiting the VBA editor. - 6. Save the CoolProp.xlam file. - - -.. [#] If you are having problems with the path to the XLAM in your worksheet appearing as the complete path to the xlam (but not the correct path), you might need to go into ``Data->Update Links`` in Excel, select CoolProp.xlam, and select ``Change Source...`` and select the location of your xlam file. That should update all the links. - - -Pre-compiled Binaries for OSX ------------------------------ - -**Part 1:** - -Download pre-compiled release binaries for OSX from `shared_library/Darwin/32bit/ `_. Development binaries coming from the buildbot server can be found at `shared_library/Darwin/32bit/ `_. Place the downloaded file called libCoolProp.dylib in the ${HOME}/lib folder (make this folder if needed). - -**Part 2:** - -Download the xlam from `MicrosoftExcel `_ or the development version from `MicrosoftExcel `_. - -1. Open Excel 2011 for Mac - -2. Go to the menu ``Tools–>Add-Ins`` - -3. Click the ``Select...`` button - -4. Browse to the file CoolProp.xlam you downloaded, select it - -5. Make sure the CoolProp Add-in is selected. - -6. Add this code to a cell - it should work: :: - - =PropsSI("T","P",101325,"Q",0,"Water") - - -If it doesn’t work and you get error number 53, it might be because you have a 64-bit .dylib file and you want a 32-bit .dylib file. For instance when you run the ``file`` command on your .dylib, you should see something like: :: - - $ file libCoolProp.dylib - libCoolProp.dylib: Mach-O dynamically linked shared library i386 - - -User-compiled Binaries ------------------------- - -**Common Requirements** - -Compilation of the Excel wrapper requires a few `common wrapper pre-requisites `_ - - -**Build (Windows)** - -MS Excel requires the CoolProp shared library, or Dynamic Link Library (DLL) on Windows, and will use either the 64-bit version or the 32-bit, ``__stdcall`` version. The instructions here are for a 64-bit windows system that will use Microsoft Visual Studio 2010 to compile *both* the 64-bit and 32-bit versions of the DLL. - -.. code-block:: bash - - # Check out the sources for CoolProp - git clone https://github.com/CoolProp/CoolProp --recursive - # Move into the folder you just created - cd CoolProp - # Make a build folder for the 32-bit DLL - mkdir build/32bit__stdcall && cd build/32bit__stdcall - # Build the MSVC project using CMake - cmake ../.. -G "Visual Studio 10" -DCOOLPROP_SHARED_LIBRARY=ON -DCOOLPROP_STDCALL_LIBRARY=ON - # Make the shared library - cmake --build . --config Release - cd ../.. - # Make a build folder for the 64-bit DLL - mkdir build/64bit && cd build/64bit - # Build the MSVC project using CMake - cmake ../.. -G "Visual Studio 10 Win64" -DCOOLPROP_SHARED_LIBRARY=ON - # Make the shared library - cmake --build . --config Release - cd ../.. - # Copy the generated DLL - copy build\32bit__stdcall\CoolProp.dll c:\CoolProp\CoolProp.dll - copy build\64bit\CoolProp.dll c:\CoolProp\CoolProp_x64.dll - -The above script should be adjusted for your specific compiler, replacing "Visual Studio 10" with your compiler name/release. - -**Build (OSX)** - -On OSX there is no calling convention to worry about, and only the 32-bit compilation is needed. You can force 32-bit compilation using -DFORCE_BITNESS_32=ON. These instructions will compile both the 32-bit library needed for Excel on OSX. - -.. code-block:: bash - - # Check out the sources for CoolProp - git clone https://github.com/CoolProp/CoolProp --recursive - # Move into the folder you just created - cd CoolProp - # Make a build folder - mkdir build && cd build - # Generate builder - cmake .. -DCOOLPROP_SHARED_LIBRARY=ON -DFORCE_BITNESS_32=ON -DCMAKE_BUILD_TYPE=Release - # Build - cmake --build . - cd .. - # Copy the generated DLL - cp build/libCoolProp.dylib ${HOME}/lib - -Usage ------------------------- - -The following CoolProp funcitons are implemented as Excel Functions (see CoolProp.xlsx for examples) - - -- **get_global_param_string("param")** -- **PropsSI("OutputName","Input1Name",Value1,"Input2Name",Value2,"FluidString")** -- **Props1SI("FluidString","OutputName")** -- **PhaseSI("Input1Name",Value1,"Input2Name",Value2,"FluidString")** -- **HAPropsSI("OutputName","Input1Name",Value1,"Input2Name",Value2,"Input3Name",Value3)** - - -and utility routine - - -- **MixtureString(Names,Fractions)** - - -where - - -"param" = - "version", "gitrevision", "fluids_list","parameter_list", or "predefined_mixtures" - -"OutputName" = - double quoted name of the fluid property to output - -"Input1Name" = - double quoted name of the first input state property - -Value1 = - the value, in SI units, of the first input state property - -"Input2Name" = - double quoted name of the second input state property - -Value2 = - the value, in SI units, of the second input state property - -"Input3Name" = - double quoted name of the third input state property; typically humidity ratio, "R" - -Value3 = - the value, in SI units, of the third input state property - -"FluidString" = - double quoted name of the fluid to evaluate - -Names = - range of cells containing fluid names (as text) - -Fractions = - range of cells containing mole fractions of the corresponding fluids in the **Names** range - - -| See `CoolProp.org `_ for more details on usage. -| See **TestExcel.xlsx** for examples of usage of these functions. diff --git a/wrappers/Excel/XLAM_module.bas b/wrappers/Excel/XLAM_module.bas new file mode 100644 index 00000000..04a2f13d --- /dev/null +++ b/wrappers/Excel/XLAM_module.bas @@ -0,0 +1,181 @@ +Attribute VB_Name = "Module1" +'Information on calling DLL from Excel: +'http://msdn.microsoft.com/en-us/library/office/bb687915.aspx +' +'Information on compiling DLL: +'http://msdn.microsoft.com/en-us/library/office/bb687850.aspx + +'Information on 32-bit/64-bit compatibility (64-bit only has one harmonized calling convention) +'http://msdn.microsoft.com/en-us/library/office/ff700513%28v=office.11%29.aspx +Option Explicit +#If Mac Then +' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name +Private Declare Function PropsSI_private Lib "libCoolProp.dylib" Alias "PropsSI" (ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double +Private Declare Function PhaseSI_private Lib "libCoolProp.dylib" Alias "PhaseSI" (ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function Props1SI_private Lib "libCoolProp.dylib" Alias "Props1SI" (ByVal Output As String, ByVal Ref As String) As Double +Private Declare Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function get_fluid_param_string_private Lib "libCoolProp.dylib" Alias "get_fluid_param_string" (ByVal fluid As String, ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function HAPropsSI_private Lib "libCoolProp.dylib" Alias "HAPropsSI" (ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double +'DEPRECATED +Private Declare Function Props_private Lib "libCoolProp.dylib" Alias "PropsS" (ByVal Output As String, ByVal Name1 As Long, ByVal Value1 As Double, ByVal Name2 As Long, ByVal Value2 As Double, ByVal Ref As String) As Double +#ElseIf Win64 Then +Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare PtrSafe Function get_fluid_param_string_private Lib "CoolProp_x64.dll" Alias "get_fluid_param_string" (ByVal fluid As String, ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare PtrSafe Function PropsSI_private Lib "CoolProp_x64.dll" Alias "PropsSI" (ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double +Private Declare PtrSafe Function PhaseSI_private Lib "CoolProp_x64.dll" Alias "PhaseSI" (ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare PtrSafe Function Props1SI_private Lib "CoolProp_x64.dll" Alias "Props1SI" (ByVal Output As String, ByVal Ref As String) As Double +Private Declare PtrSafe Function HAPropsSI_private Lib "CoolProp_x64.dll" Alias "HAPropsSI" (ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double +'DEPRECATED +Private Declare PtrSafe Function Props_private Lib "CoolProp_x64.dll" Alias "PropsS" (ByVal Output As String, ByVal Name1 As Long, ByVal Value1 As Double, ByVal Name2 As Long, ByVal Value2 As Double, ByVal Ref As String) As Double +#Else +Private Declare Function get_global_param_string_private Lib "CoolProp_stdcall.dll" Alias "_get_global_param_string@12" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function get_fluid_param_string_private Lib "CoolProp_stdcall.dll" Alias "_get_fluid_param_string@16" (ByVal param As String, ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function PropsSI_private Lib "CoolProp_stdcall.dll" Alias "_PropsSI@32" (ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double +Private Declare Function PhaseSI_private Lib "CoolProp_stdcall.dll" Alias "_PhaseSI@36" (ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String, ByVal Output As String, ByVal n As Integer) As Long +Private Declare Function Props1SI_private Lib "CoolProp_stdcall.dll" Alias "_Props1SI@8" (ByVal Output As String, ByVal Ref As String) As Double +Private Declare Function HAPropsSI_private Lib "CoolProp_stdcall.dll" Alias "_HAPropsSI@40" (ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double +'DEPRECATED +Private Declare Function Props_private Lib "CoolProp_stdcall.dll" Alias "_PropsS@32" (ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double +#End If + +Private Function get_error_message() As String + Dim errstring As String + 'Make a null-terminated string that is plenty big + errstring = String(2000, vbNullChar) + 'Get the error string + Call get_global_param_string_private("errstring", errstring, 2000) + get_error_message = errstring +End Function + +Public Function get_global_param_string(ByVal Output As String) As String + Dim strParam As String + 'Make a null-terminated string that is plenty big + strParam = String(2000, vbNullChar) + 'Get the version string + Call get_global_param_string_private(Output, strParam, 2000) + get_global_param_string = strParam +End Function + +Public Function PropsSI(ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String) + On Error GoTo ErrorHandler + Dim PropsSI_temp As Double + + PropsSI_temp = PropsSI_private(Output, Name1, Value1, Name2, Value2, fluid) + + If Abs(PropsSI_temp) > 1E+30 Then + 'Return error message + PropsSI = get_error_message() + Else + PropsSI = PropsSI_temp + End If + Exit Function + +ErrorHandler: + If Err = 13 Then + Exit Function + End If + + MsgBox "The most recent error number is " & Err & ". Its message text is: " & Error(Err) + Exit Function +End Function + +Public Function PhaseSI(ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String) + Dim strPhase As String + 'Make a null-terminated string that is plenty big + strPhase = String(2000, vbNullChar) + 'Call PhaseSI_private - any errors will return an empty phase string + Call PhaseSI_private(Name1, Value1, Name2, Value2, fluid, strPhase, 2000) + If Len(strPhase) = 0 Then + PhaseSI = get_error_message() + Else + PhaseSI = strPhase + End If + Exit Function +End Function + +Public Function Props1SI(ByVal fluid As String, ByVal Output As String) + On Error GoTo ErrorHandler + Dim Props1SI_temp As Double + + Props1SI_temp = Props1SI_private(Output, fluid) + + If Abs(Props1SI_temp) > 1E+30 Then + 'Display the error + Props1SI = get_error_message() + Else + Props1SI = Props1SI_temp + End If + Exit Function + +ErrorHandler: + If Err = 13 Then + Exit Function + End If + MsgBox "The most recent error number is " & Err & ". Its message text is: " & Error(Err) + Exit Function +End Function + +Public Function Props(ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String) + On Error GoTo ErrorHandler + Dim Props_temp As Double + Props_temp = Props_private(Output, Name1, Value1, Name2, Value2, fluid) + If Abs(Props_temp) > 1E+30 Then + Props = get_error_message() + Else + Props = Props_temp + End If + Exit Function +ErrorHandler: + If Err = 13 Then + Exit Function + End If + MsgBox "The most recent error number is " & Err & ". Its message text is: " & Error(Err) + Exit Function +End Function + +Public Function HAPropsSI(ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double + On Error GoTo ErrorHandler + Dim HAPropsSI_temp As Double + HAPropsSI_temp = HAPropsSI_private(Output, Input1Name, Value1, Input2Name, Value2, Input3name, Value3) + If Abs(HAPropsSI_temp) > 1E+30 Then + HAPropsSI = get_error_message() + Else + HAPropsSI = HAPropsSI_temp + End If + Exit Function +ErrorHandler: + If Err = 13 Then + Exit Function + End If + MsgBox "The most recent error number is " & Err & ". Its message text is: " & Error(Err) + Exit Function +End Function + +Public Function MixtureString(names As Range, fractions As Range) As String + ' See http://www.functionx.com/vbaexcel/objects/Lesson6.htm + Dim my_names, my_fractions As Collection + Dim Cell, i As Variant + Dim chunk As String + MixtureString = "" + Set my_names = New Collection + Set my_fractions = New Collection + + ' Collect all the names + For Each Cell In names + my_names.Add Cell.Value + Next + ' Collect all the fractions + For Each Cell In fractions + my_fractions.Add Cell.Value + Next + ' Zip them back together + For i = 1 To my_fractions.Count + chunk = my_names.Item(i) & "[" & LTrim(Str(my_fractions.Item(i))) & "]" + If i = 1 Then + MixtureString = MixtureString & chunk + Else + MixtureString = MixtureString & "&" & chunk + End If + Next + +End Function diff --git a/wrappers/Excel/XLA_module.bas b/wrappers/Excel/XLA_module.bas new file mode 100644 index 00000000..80175c92 --- /dev/null +++ b/wrappers/Excel/XLA_module.bas @@ -0,0 +1,27 @@ +Attribute VB_Name = "Module1" +'Information on calling DLL from Excel: +'http://msdn.microsoft.com/en-us/library/office/bb687915.aspx +' +'Information on compiling DLL: +'http://msdn.microsoft.com/en-us/library/office/bb687850.aspx + +Private Declare Function Props_private Lib "CoolProp_stdcall.dll" Alias "_Props@32" (ByVal Output As String, ByVal Name1 As Long, ByVal Value1 As Double, ByVal Name2 As Long, ByVal Value2 As Double, ByVal Ref As String) As Double +Private Declare Function Props1_private Lib "CoolProp_stdcall.dll" Alias "_Props1@8" (ByVal Ref As String, ByVal Output As String) As Double +Private Declare Function HAProps_private Lib "CoolProp_stdcall.dll" Alias "_HAProps@40" (ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double + +Public Function Props(ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double + 'Get the single character forms + N1 = Asc(Left(Name1, 1)) + N2 = Asc(Left(Name2, 1)) + Props = Props_private(Output, N1, Value1, N2, Value2, Ref) +End Function + +Public Function Props1(ByVal Ref As String, ByVal Output As String) As Double + Props1 = Props1_private(Ref, Output) +End Function + +Public Function HAProps(ByVal Output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double) As Double + HAProps = HAProps_private(Output, Input1Name, Value1, Input2Name, Value2, Input3name, Value3) +End Function + +