diff --git a/CMakeLists.txt b/CMakeLists.txt index 78acf73..4522104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.20) ####################################### # PROJECT INFORMATION # @@ -16,7 +16,7 @@ function(get_version file_name output) #message(STATUS "[${PROJECT_NAME}] - Found version number: ${FIRST_MATCH}") string(REGEX MATCH "[0-9]\\.[0-9]\\.[0-9]" SECOND_MATCH "${FIRST_MATCH}") if(SECOND_MATCH) - message(STATUS "[${PROJECT_NAME}] - Found version number: ${SECOND_MATCH}") + message(STATUS "[IF97] - Found version number: ${SECOND_MATCH}") set(${output} ${SECOND_MATCH} PARENT_SCOPE) else() message(FATAL_ERROR "Data were not found for the required build specification.") @@ -25,11 +25,11 @@ endfunction() get_version("${CMAKE_CURRENT_LIST_DIR}/IF97.h" VERSION) - # Project name project("IF97" LANGUAGES CXX VERSION ${VERSION}) message(STATUS "[${PROJECT_NAME}] - Building v${PROJECT_VERSION} of ${PROJECT_NAME}") +string(REPLACE "." "," IF97_VERSION "${VERSION}") option(IF97_PRIME_MODULE "Build MathCAD Prime wrapper" OFF) option(IF97_MATHCAD15_MODULE "Build MathCAD 15 wrapper" OFF) @@ -75,17 +75,76 @@ endif() # MATHCAD PRIME MODULE # ######################### if(IF97_PRIME_MODULE) + # Make sure we're on Winows - the only platform on which Mathad Prime runs if(NOT WIN32) message(FATAL_ERROR "[${PROJECT_NAME}] - IF97_PRIME_MODULE can only be used on windows host") endif() + # Check for valid Mathacd Prime Root directory provided by user. If not provided, try to find it on our own. if( "${IF97_PRIME_ROOT}" STREQUAL "") - message(FATAL_ERROR "[${PROJECT_NAME}] - You must provide the path to MathCAD Prime Root directory using something like -DIF97_PRIME_ROOT=\"C:/Program Files/PTC/Mathcad Prime 3.1\"") + # PTC/Mathcad convention is a directory labeled "C:\Program Files\PTC\Mathad Prime X.X.X.X" + # Find all of these directories on the system and try to set IF97_PRIME_ROOT dynamically + file(GLOB PTC_CONTENTS + LIST_DIRECTORIES true + "C:/Program Files/PTC/Mathcad Prime*" + ) + # Add them to a list, sorted by most recent Marhcad Prime release first + set(MATHCAD_SEARCH_PATHS "") + foreach(ITEM ${PTC_CONTENTS}) + if(IS_DIRECTORY "${ITEM}") + list(APPEND MATHCAD_SEARCH_PATHS "${ITEM}") + endif() + endforeach() + list(SORT MATHCAD_SEARCH_PATHS COMPARE NATURAL ORDER DESCENDING) + # Now make sure the executable is in one of these directories (newest first) + # Now make sure the executable is in one of these directories (newest first) + unset(MATHCAD_EXE CACHE) + find_program(MATHCAD_EXE + NAMES MathcadPrime.exe + PATHS ${MATHCAD_SEARCH_PATHS} + NO_DEFAULT_PATH) + # Strip off program name, and set IF97_PRIME_ROOT to parent path + #get_filename_comopnent(PARENT_DIR "$MATHCAD_EXE" MATHCAD_ROOT) + if(MATHCAD_EXE) + cmake_path(GET MATHCAD_EXE PARENT_PATH IF97_PRIME_ROOT) + message(STATUS "[${PROJECT_NAME}] - Dynamically Found Mathcad @ \"${IF97_PRIME_ROOT}\"") + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$" MATHCAD_VERSION "${IF97_PRIME_ROOT}") + message(STATUS "[${PROJECT_NAME}] - Linking with Mathcad Prime Library v${MATHCAD_VERSION}\"") + else() + message(STATUS "[${PROJECT_NAME}] - Could not Dynamically Locate Mathcad Prime on this System") + message(FATAL_ERROR "[${PROJECT_NAME}] - You must provide the path to MathCAD Prime Root directory using something like -DIF97_PRIME_ROOT=\"C:/Program Files/PTC/Mathcad Prime 11.0.0.0\"") + endif() else() - message(STATUS "[${PROJECT_NAME}] - IF97_PRIME_ROOT: ${IF97_PRIME_ROOT}") + # Mathcad Root directory specified. Make sure it's a valid Mathcad Prime installation directory + find_program(MATHCAD_EXE + NAMES MathcadPrime.exe + PATHS ${IF97_PRIME_ROOT}) + if(MATHCAD_EXE) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$" MATHCAD_VERSION "${IF97_PRIME_ROOT}") + message(STATUS "[${PROJECT_NAME}] - Linking with Mathcad Prime Library v${MATHCAD_VERSION}\"") + else() + message(STATUS "[${PROJECT_NAME}] - Could not find Mathcad Prime at ${IF97_PRIME_ROOT}") + message(FATAL_ERROR "[${PROJECT_NAME}] - Check the path to the MathCAD Prime Root directory provided using something like -DIF97_PRIME_ROOT=\"C:/Program Files/PTC/Mathcad Prime 11.0.0.0\"") + endif() + endif() + # Embed Windows VERSIONINFO so IF97.dll's Properties dialog shows + # FileVersion/ProductVersion fields a la CoolProp(#2863). The .rc + # is configured from VERSION above and added to the source + # list only on MSVC and MSYS2(MinGW), where rc.exe is available. + set(IF97_RESOURCE "") + if(MSVC) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/dev/IF97.rc.in" + "${CMAKE_CURRENT_BINARY_DIR}/IF97.rc" + @ONLY) + list(APPEND IF97_RESOURCE "${CMAKE_CURRENT_BINARY_DIR}/IF97.rc") endif() file(GLOB_RECURSE IF97_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/includes/*.h") include_directories("${IF97_PRIME_ROOT}/Custom Functions" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/includes") - add_library(IF97 SHARED ${IF97_HEADERS} "${CMAKE_CURRENT_SOURCE_DIR}/IF97.h" "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MathCAD/IF97.cpp") + add_library(IF97 SHARED + ${IF97_HEADERS} + "${CMAKE_CURRENT_SOURCE_DIR}/IF97.h" + "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MathCAD/IF97.cpp" + ${IF97_RESOURCE}) target_link_libraries(IF97 "${IF97_PRIME_ROOT}/Custom Functions/mcaduser.lib") set_target_properties(IF97 PROPERTIES LINK_FLAGS "/ENTRY:\"DllEntryPoint\"") set_target_properties(IF97 PROPERTIES SUFFIX ".dll" PREFIX "") diff --git a/wrapper/Mathcad/IF97.sln b/wrapper/Mathcad/IF97.sln deleted file mode 100644 index 5db7663..0000000 --- a/wrapper/Mathcad/IF97.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IF97", "IF97.vcxproj", "{78EB3940-F42F-4A62-BCEF-8418FCAB79AF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {78EB3940-F42F-4A62-BCEF-8418FCAB79AF}.Debug|Win32.ActiveCfg = Debug|Win32 - {78EB3940-F42F-4A62-BCEF-8418FCAB79AF}.Debug|Win32.Build.0 = Debug|Win32 - {78EB3940-F42F-4A62-BCEF-8418FCAB79AF}.Release|Win32.ActiveCfg = Release|Win32 - {78EB3940-F42F-4A62-BCEF-8418FCAB79AF}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wrapper/Mathcad/IF97.vcxproj b/wrapper/Mathcad/IF97.vcxproj deleted file mode 100644 index f98a614..0000000 --- a/wrapper/Mathcad/IF97.vcxproj +++ /dev/null @@ -1,171 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {78EB3940-F42F-4A62-BCEF-8418FCAB79AF} - Win32Proj - IF97 - - - - DynamicLibrary - true - Unicode - - - DynamicLibrary - false - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;IF97_EXPORTS;%(PreprocessorDefinitions) - C:\Program Files %28x86%29\Mathcad\Mathcad 15\userefi\microsft\include;%(AdditionalIncludeDirectories) - - - Windows - true - C:\Program Files %28x86%29\Mathcad\Mathcad 15\userefi\microsft\lib;%(AdditionalLibraryDirectories) - mcaduser.lib;%(AdditionalDependencies) - - - xcopy "$(TargetPath)" ..\..\..\ /rqky - - - Copy release DLL - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;IF97_EXPORTS;%(PreprocessorDefinitions) - C:\Program Files %28x86%29\Mathcad\Mathcad 15\userefi\microsft\include;%(AdditionalIncludeDirectories) - - - Windows - true - true - true - 0.1 - C:\Program Files %28x86%29\Mathcad\Mathcad 15\userefi\microsft\lib;%(AdditionalLibraryDirectories) - DllEntryPoint - mcaduser.lib;%(AdditionalDependencies) - - - xcopy "$(TargetPath)" "C:\Program Files (x86)\Mathcad\Mathcad 15\userefi" /rqky - - - Copy the resulting DLL file to the Mathcad\userefi directory - - - xcopy "$(ProjectDir)if97_EN.xml" "C:\Program Files (x86)\Mathcad\Mathcad 15\doc\funcdoc" /rqky - - - Copy funcdoc XML file to appropriate installation directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wrapper/Mathcad/README.md b/wrapper/Mathcad/README.md index 81854f3..99fd0e9 100644 --- a/wrapper/Mathcad/README.md +++ b/wrapper/Mathcad/README.md @@ -54,39 +54,51 @@ Make the Build for Mathcad Prime (any version above 3.0) * Go to the top level IF97 directory and make a build directory (something like \build or \buildPrime): + ```bash mkdir buildPrime cd buildPrime + ``` * Build the makefile using CMake (Note: Mathcad Prime is 64-bit): + ```cmake cmake .. -DIF97_PRIME_MODULE=ON -DIF97_PRIME_ROOT="C:/Program Files/PTC/Mathcad Prime 10.0.0.0" -G "Visual Studio 17 2022" -A x64 - -DCMAKE_VERBOSE_MAKEFILE=ON + -DCMAKE_VERBOSE_MAKEFILE=ON + ``` - > Insert your version of Mathcad Prime in place of "10.0.0.0". - > Insert your version of Visual Studio for the -G option. - > Note that Mathcad Prime is 64-bit and requires the `-A x64` switch on this command. - > Prior to VS 2017, use something like: `-G "Visual Studio 14 2015 Win64` + - Insert your version of Mathcad Prime in place of "10.0.0.0" (or omit). + - Insert your version of Visual Studio for the `-G` option. + - Note that Mathcad Prime is 64-bit and requires the `-A x64` switch on this command. + - Prior to VS 2017, use something like: `-G "Visual Studio 14 2015 Win64"`. + . + + > **NOTE:** + > Specifying the Mathcad Prime root directory is optional. CMake will attempt to find the most recent version of Mathcad Prime on the system and use that one to link the Mathcad Prime library and header file. If a valid Mathcad Prime installation directory cannot be found, or you want to specify an older version on the system to link to, then supply the ``-DIF97_PRIME_ROOT`` flag as directed above. Make the Build for Legacy Mathcad 15 (Discontinued by PTC) ---------------------------------------------------------- * Go to the top level IF97 directory and make a build directory (something like \build15): + ```bash mkdir build15 cd build15 + ``` * Build the makefile using CMake (Note: Mathcad 15 is 32-bit):: + ```cmake cmake .. -DIF97_MATHCAD15_MODULE=ON -DIF97_MATHCAD15_ROOT="C:/Program Files (x86)/Mathcad/Mathcad 15" -G "Visual Studio 17 2022" -A Win32 -DCMAKE_VERBOSE_MAKEFILE=ON - - > Insert your version of Visual Studio for the -G option. - > Legacy Mathcad was 32-bit and requires a 32-bit add-in DLL. - > Prior to VS2017, use something like `-G "Visual Studio 14 2015` as 32-bit was the default. + ``` + + - Insert your version of Visual Studio for the -G option. + - Legacy Mathcad was 32-bit and requires a 32-bit add-in DLL. + - Prior to VS2017, use something like `-G "Visual Studio 14 2015` as 32-bit was the default. Build the Project ----------------- @@ -131,4 +143,4 @@ Compiler Flags ============== The Mathcad wrapper code uses the ``REGION3_ITERATE`` flag to provide more accurate (but slightly slower) calculation of density in Region 3 (mostly super-critical), but does **_not_** use the ``IAPWS_UNITS`` flag by default, leaving all input/output values in SI units. -The `IAPWS_UNITS` flag can be set (uncommented) in the top of the IF97.cpp file to input and output IAPWS units (Pressures in MPa and energy in kJ) for easy comparison with IAPWS release documents. \ No newline at end of file +The `IAPWS_UNITS` flag can be set (uncommented) in the top of the IF97.cpp file to input and output IAPWS units (Pressures in MPa and energy in kJ) for easy comparison with IAPWS release documents. diff --git a/wrapper/Mathcad/dev/IF97.rc.in b/wrapper/Mathcad/dev/IF97.rc.in new file mode 100644 index 0000000..c50b6db --- /dev/null +++ b/wrapper/Mathcad/dev/IF97.rc.in @@ -0,0 +1,35 @@ +// Windows version-info resource for the CoolProp shared library (#2863). +// Configured by CMake from IF97_VERSION. +// The numeric VERSION fields require integer literals (commas, not dots), +// so the VERSION string (dots) is converted to IF97_VERSION (commas). + +#include + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @IF97_VERSION@,0 + PRODUCTVERSION @IF97_VERSION@,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0x0L + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "CoolProp project" + VALUE "FileDescription", "IF97 Water Properties Library" + VALUE "FileVersion", "@VERSION@" + VALUE "InternalName", "IF97" + VALUE "LegalCopyright", "MIT License" + VALUE "OriginalFilename", "IF97.dll" + VALUE "ProductName", "IF97 Mathcad Prime Add-in" + VALUE "ProductVersion", "@VERSION@" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 0x04B0 + END +END