Skip to content

Commit 0be7b51

Browse files
Update Cmake min version and Mathcad build (#55)
* Update Cmake min version and Mathcad build * Fix code block formatting in README.md * Update CMakeLists.txt with NO_DEFAULT_ROOT finding Mathcad Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Refine README.md formatting and instructions Updated formatting and improved clarity in README instructions for Mathcad and Visual Studio versions. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 51a5a6f commit 0be7b51

5 files changed

Lines changed: 122 additions & 207 deletions

File tree

CMakeLists.txt

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0.0)
1+
cmake_minimum_required(VERSION 3.20)
22

33
#######################################
44
# PROJECT INFORMATION #
@@ -16,7 +16,7 @@ function(get_version file_name output)
1616
#message(STATUS "[${PROJECT_NAME}] - Found version number: ${FIRST_MATCH}")
1717
string(REGEX MATCH "[0-9]\\.[0-9]\\.[0-9]" SECOND_MATCH "${FIRST_MATCH}")
1818
if(SECOND_MATCH)
19-
message(STATUS "[${PROJECT_NAME}] - Found version number: ${SECOND_MATCH}")
19+
message(STATUS "[IF97] - Found version number: ${SECOND_MATCH}")
2020
set(${output} ${SECOND_MATCH} PARENT_SCOPE)
2121
else()
2222
message(FATAL_ERROR "Data were not found for the required build specification.")
@@ -25,11 +25,11 @@ endfunction()
2525

2626
get_version("${CMAKE_CURRENT_LIST_DIR}/IF97.h" VERSION)
2727

28-
2928
# Project name
3029
project("IF97" LANGUAGES CXX VERSION ${VERSION})
3130

3231
message(STATUS "[${PROJECT_NAME}] - Building v${PROJECT_VERSION} of ${PROJECT_NAME}")
32+
string(REPLACE "." "," IF97_VERSION "${VERSION}")
3333

3434
option(IF97_PRIME_MODULE "Build MathCAD Prime wrapper" OFF)
3535
option(IF97_MATHCAD15_MODULE "Build MathCAD 15 wrapper" OFF)
@@ -75,17 +75,76 @@ endif()
7575
# MATHCAD PRIME MODULE #
7676
#########################
7777
if(IF97_PRIME_MODULE)
78+
# Make sure we're on Winows - the only platform on which Mathad Prime runs
7879
if(NOT WIN32)
7980
message(FATAL_ERROR "[${PROJECT_NAME}] - IF97_PRIME_MODULE can only be used on windows host")
8081
endif()
82+
# Check for valid Mathacd Prime Root directory provided by user. If not provided, try to find it on our own.
8183
if( "${IF97_PRIME_ROOT}" STREQUAL "")
82-
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\"")
84+
# PTC/Mathcad convention is a directory labeled "C:\Program Files\PTC\Mathad Prime X.X.X.X"
85+
# Find all of these directories on the system and try to set IF97_PRIME_ROOT dynamically
86+
file(GLOB PTC_CONTENTS
87+
LIST_DIRECTORIES true
88+
"C:/Program Files/PTC/Mathcad Prime*"
89+
)
90+
# Add them to a list, sorted by most recent Marhcad Prime release first
91+
set(MATHCAD_SEARCH_PATHS "")
92+
foreach(ITEM ${PTC_CONTENTS})
93+
if(IS_DIRECTORY "${ITEM}")
94+
list(APPEND MATHCAD_SEARCH_PATHS "${ITEM}")
95+
endif()
96+
endforeach()
97+
list(SORT MATHCAD_SEARCH_PATHS COMPARE NATURAL ORDER DESCENDING)
98+
# Now make sure the executable is in one of these directories (newest first)
99+
# Now make sure the executable is in one of these directories (newest first)
100+
unset(MATHCAD_EXE CACHE)
101+
find_program(MATHCAD_EXE
102+
NAMES MathcadPrime.exe
103+
PATHS ${MATHCAD_SEARCH_PATHS}
104+
NO_DEFAULT_PATH)
105+
# Strip off program name, and set IF97_PRIME_ROOT to parent path
106+
#get_filename_comopnent(PARENT_DIR "$MATHCAD_EXE" MATHCAD_ROOT)
107+
if(MATHCAD_EXE)
108+
cmake_path(GET MATHCAD_EXE PARENT_PATH IF97_PRIME_ROOT)
109+
message(STATUS "[${PROJECT_NAME}] - Dynamically Found Mathcad @ \"${IF97_PRIME_ROOT}\"")
110+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$" MATHCAD_VERSION "${IF97_PRIME_ROOT}")
111+
message(STATUS "[${PROJECT_NAME}] - Linking with Mathcad Prime Library v${MATHCAD_VERSION}\"")
112+
else()
113+
message(STATUS "[${PROJECT_NAME}] - Could not Dynamically Locate Mathcad Prime on this System")
114+
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\"")
115+
endif()
83116
else()
84-
message(STATUS "[${PROJECT_NAME}] - IF97_PRIME_ROOT: ${IF97_PRIME_ROOT}")
117+
# Mathcad Root directory specified. Make sure it's a valid Mathcad Prime installation directory
118+
find_program(MATHCAD_EXE
119+
NAMES MathcadPrime.exe
120+
PATHS ${IF97_PRIME_ROOT})
121+
if(MATHCAD_EXE)
122+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$" MATHCAD_VERSION "${IF97_PRIME_ROOT}")
123+
message(STATUS "[${PROJECT_NAME}] - Linking with Mathcad Prime Library v${MATHCAD_VERSION}\"")
124+
else()
125+
message(STATUS "[${PROJECT_NAME}] - Could not find Mathcad Prime at ${IF97_PRIME_ROOT}")
126+
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\"")
127+
endif()
128+
endif()
129+
# Embed Windows VERSIONINFO so IF97.dll's Properties dialog shows
130+
# FileVersion/ProductVersion fields a la CoolProp(#2863). The .rc
131+
# is configured from VERSION above and added to the source
132+
# list only on MSVC and MSYS2(MinGW), where rc.exe is available.
133+
set(IF97_RESOURCE "")
134+
if(MSVC)
135+
configure_file(
136+
"${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/dev/IF97.rc.in"
137+
"${CMAKE_CURRENT_BINARY_DIR}/IF97.rc"
138+
@ONLY)
139+
list(APPEND IF97_RESOURCE "${CMAKE_CURRENT_BINARY_DIR}/IF97.rc")
85140
endif()
86141
file(GLOB_RECURSE IF97_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/includes/*.h")
87142
include_directories("${IF97_PRIME_ROOT}/Custom Functions" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/Mathcad/includes")
88-
add_library(IF97 SHARED ${IF97_HEADERS} "${CMAKE_CURRENT_SOURCE_DIR}/IF97.h" "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MathCAD/IF97.cpp")
143+
add_library(IF97 SHARED
144+
${IF97_HEADERS}
145+
"${CMAKE_CURRENT_SOURCE_DIR}/IF97.h"
146+
"${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MathCAD/IF97.cpp"
147+
${IF97_RESOURCE})
89148
target_link_libraries(IF97 "${IF97_PRIME_ROOT}/Custom Functions/mcaduser.lib")
90149
set_target_properties(IF97 PROPERTIES LINK_FLAGS "/ENTRY:\"DllEntryPoint\"")
91150
set_target_properties(IF97 PROPERTIES SUFFIX ".dll" PREFIX "")

wrapper/Mathcad/IF97.sln

Lines changed: 0 additions & 20 deletions
This file was deleted.

wrapper/Mathcad/IF97.vcxproj

Lines changed: 0 additions & 171 deletions
This file was deleted.

wrapper/Mathcad/README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,51 @@ Make the Build for Mathcad Prime (any version above 3.0)
5454

5555
* Go to the top level IF97 directory and make a build directory (something like \build or \buildPrime):
5656

57+
```bash
5758
mkdir buildPrime
5859
cd buildPrime
60+
```
5961

6062
* Build the makefile using CMake (Note: Mathcad Prime is 64-bit):
6163

64+
```cmake
6265
cmake .. -DIF97_PRIME_MODULE=ON
6366
-DIF97_PRIME_ROOT="C:/Program Files/PTC/Mathcad Prime 10.0.0.0"
6467
-G "Visual Studio 17 2022" -A x64
65-
-DCMAKE_VERBOSE_MAKEFILE=ON
68+
-DCMAKE_VERBOSE_MAKEFILE=ON
69+
```
6670

67-
> Insert your version of Mathcad Prime in place of "10.0.0.0".
68-
> Insert your version of Visual Studio for the -G option.
69-
> Note that Mathcad Prime is 64-bit and requires the `-A x64` switch on this command.
70-
> Prior to VS 2017, use something like: `-G "Visual Studio 14 2015 Win64`
71+
- Insert your version of Mathcad Prime in place of "10.0.0.0" (or omit).
72+
- Insert your version of Visual Studio for the `-G` option.
73+
- Note that Mathcad Prime is 64-bit and requires the `-A x64` switch on this command.
74+
- Prior to VS 2017, use something like: `-G "Visual Studio 14 2015 Win64"`.
75+
.
76+
77+
> **NOTE:**
78+
> 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.
7179

7280
Make the Build for Legacy Mathcad 15 (Discontinued by PTC)
7381
----------------------------------------------------------
7482

7583
* Go to the top level IF97 directory and make a build directory (something like \build15):
7684

85+
```bash
7786
mkdir build15
7887
cd build15
88+
```
7989

8090
* Build the makefile using CMake (Note: Mathcad 15 is 32-bit)::
8191

92+
```cmake
8293
cmake .. -DIF97_MATHCAD15_MODULE=ON
8394
-DIF97_MATHCAD15_ROOT="C:/Program Files (x86)/Mathcad/Mathcad 15"
8495
-G "Visual Studio 17 2022" -A Win32
8596
-DCMAKE_VERBOSE_MAKEFILE=ON
86-
87-
> Insert your version of Visual Studio for the -G option.
88-
> Legacy Mathcad was 32-bit and requires a 32-bit add-in DLL.
89-
> Prior to VS2017, use something like `-G "Visual Studio 14 2015` as 32-bit was the default.
97+
```
98+
99+
- Insert your version of Visual Studio for the -G option.
100+
- Legacy Mathcad was 32-bit and requires a 32-bit add-in DLL.
101+
- Prior to VS2017, use something like `-G "Visual Studio 14 2015` as 32-bit was the default.
90102
91103
Build the Project
92104
-----------------
@@ -131,4 +143,4 @@ Compiler Flags
131143
==============
132144
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.
133145
134-
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.
146+
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.

0 commit comments

Comments
 (0)