mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Refactor CMakeLists.txt into modular structure
Restructure the monolithic 2,235-line CMakeLists.txt into a clean, modular architecture for better maintainability and clarity. Changes: - Main CMakeLists.txt reduced from 2,235 to 71 lines (96.8% reduction) - Extract build options to cmake/Options.cmake (73 lines) - Extract compiler configuration to cmake/Compiler.cmake (115 lines) - Extract version info to cmake/Version.cmake (20 lines) - Extract source discovery to cmake/Sources.cmake (88 lines) - Extract dependencies to cmake/Dependencies.cmake (76 lines) - Extract core library builds to cmake/CoreLibrary.cmake (348 lines) - Extract all language wrappers to cmake/Wrappers.cmake (1,198 lines) - Extract testing config to cmake/Testing.cmake (176 lines) - Add wrapper utilities to cmake/wrappers/Common.cmake (40 lines) Benefits: - Clear separation of concerns - Easier to maintain and modify individual components - Better readability with organized structure - Reduced merge conflicts for collaborative development - Main CMakeLists.txt now serves as clear table of contents Tested: CMake configuration runs successfully with no warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2228
CMakeLists.txt
2228
CMakeLists.txt
File diff suppressed because it is too large
Load Diff
115
cmake/Compiler.cmake
Normal file
115
cmake/Compiler.cmake
Normal file
@@ -0,0 +1,115 @@
|
||||
#######################################
|
||||
# COMPILER CONFIGURATION #
|
||||
#-------------------------------------#
|
||||
# Compiler flags, C++ standard, #
|
||||
# platform-specific settings #
|
||||
#######################################
|
||||
|
||||
# Force C++17 standard (lambdas are used in CPStrings.h, std::make_unique in DataStructures.cpp)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Address Sanitizer configuration for Clang
|
||||
if(COOLPROP_ASAN)
|
||||
# https://stackoverflow.com/a/64294837 (CC BY-SA 4.0)
|
||||
if(isMultiConfig)
|
||||
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
|
||||
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
|
||||
endif()
|
||||
else()
|
||||
set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel)
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
|
||||
|
||||
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
|
||||
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS_ASAN
|
||||
"${CMAKE_C_FLAGS_RelWithDebInfo} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
|
||||
"Flags used by the C compiler for Asan build type or configuration." FORCE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_ASAN
|
||||
"${CMAKE_CXX_FLAGS_RelWithDebInfo} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
|
||||
"Flags used by the C++ compiler for Asan build type or configuration." FORCE)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_ASAN
|
||||
"${CMAKE_EXE_LINKER_FLAGS_RelWithDebInfo} -fsanitize=address" CACHE STRING
|
||||
"Linker flags to be used to create executables for Asan build type." FORCE)
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
|
||||
"${CMAKE_SHARED_LINKER_FLAGS_RelWithDebInfo} -fsanitize=address" CACHE STRING
|
||||
"Linker lags to be used to create shared libraries for Asan build type." FORCE)
|
||||
endif()
|
||||
|
||||
# macOS libc++ vs libstdc++ configuration
|
||||
# See:
|
||||
# https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave
|
||||
# https://support.enthought.com/hc/en-us/articles/204469410-OS-X-GCC-Clang-and-Cython-in-10-9-Mavericks
|
||||
# https://github.com/pandas-dev/pandas/pull/24274/files
|
||||
# https://github.com/explosion/thinc/pull/84/files
|
||||
# https://github.com/jlfaucher/builder/commit/d144d3a695949f90c5e2acff4dfd94fdcf8dcdfa
|
||||
# https://github.com/CoolProp/CoolProp/issues/1778
|
||||
# https://gitlab.kitware.com/cmake/cmake/issues/18396
|
||||
if(DEFINED DARWIN_USE_LIBCPP)
|
||||
if(DARWIN_USE_LIBCPP)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
|
||||
set(OSX_COMPILE_FLAGS "${OSX_COMPILE_FLAGS} -stdlib=libc++")
|
||||
set(OSX_COMPILE_FLAGS "${OSX_COMPILE_FLAGS} -mmacosx-version-min=10.9")
|
||||
set(OSX_LINK_FLAGS "${OSX_LINK_FLAGS} -lc++")
|
||||
set(OSX_LINK_FLAGS "${OSX_LINK_FLAGS} -nodefaultlibs")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
else()
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "Minimum OS X deployment version")
|
||||
set(OSX_COMPILE_FLAGS "${OSX_COMPILE_FLAGS} -stdlib=libstdc++")
|
||||
set(OSX_COMPILE_FLAGS "${OSX_COMPILE_FLAGS} -mmacosx-version-min=10.5")
|
||||
set(OSX_LINK_FLAGS "${OSX_LINK_FLAGS} -lstdc++")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libstdc++")
|
||||
endif()
|
||||
message(STATUS "DARWIN_USE_LIBCPP was set added some flags:")
|
||||
message(STATUS " OSX_COMPILE_FLAGS: ${OSX_COMPILE_FLAGS}")
|
||||
message(STATUS " OSX_LINK_FLAGS: ${OSX_LINK_FLAGS}")
|
||||
else()
|
||||
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
|
||||
message(STATUS "OSX build detected:")
|
||||
message(STATUS " You might want to pass the -DDARWIN_USE_LIBCPP=ON/OFF parameter")
|
||||
message(STATUS " to enable or disable different C++ standard libraries.")
|
||||
message(STATUS " You can also specify the environment variable MACOSX_DEPLOYMENT_TARGET=10.9 to force clang builds.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add definitions to silence warnings in MSVC2017 related to shared ptr code
|
||||
if(MSVC AND MSVC_VERSION GREATER_EQUAL 1910)
|
||||
add_definitions(-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING)
|
||||
add_definitions(-D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING)
|
||||
endif()
|
||||
|
||||
# Handle MSVC release/debug configurations
|
||||
if(COOLPROP_RELEASE AND COOLPROP_DEBUG)
|
||||
message(FATAL_ERROR "You cannot set both COOLPROP_RELEASE and COOLPROP_DEBUG")
|
||||
endif()
|
||||
|
||||
if(COOLPROP_RELEASE)
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
else()
|
||||
# Multi-config generator (Visual Studio)
|
||||
# Can't set CMAKE_BUILD_TYPE, it's controlled by the IDE
|
||||
message(STATUS "Building in release mode with MSVC")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Handle MSVC static/dynamic runtime library linking
|
||||
if(COOLPROP_MSVC_STATIC)
|
||||
set(COOLPROP_MSVC_ALL "/MTd" "/MT" "/MDd" "/MD")
|
||||
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
foreach(TO_REPLACE ${COOLPROP_MSVC_ALL})
|
||||
string(REPLACE "${TO_REPLACE}" "" ${flag_var} "${${flag_var}}")
|
||||
endforeach()
|
||||
if(COOLPROP_MSVC_DEBUG)
|
||||
set(${flag_var} "${${flag_var}} /MTd")
|
||||
else()
|
||||
set(${flag_var} "${${flag_var}} /MT")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
348
cmake/CoreLibrary.cmake
Normal file
348
cmake/CoreLibrary.cmake
Normal file
@@ -0,0 +1,348 @@
|
||||
#######################################
|
||||
# CORE LIBRARY BUILD #
|
||||
#-------------------------------------#
|
||||
# Build the main CoolProp library in #
|
||||
# static, shared, or object form #
|
||||
#######################################
|
||||
|
||||
# Include needed CMake modules
|
||||
include(CheckIncludeFileCXX)
|
||||
|
||||
#######################################
|
||||
# BITNESS DETECTION #
|
||||
#######################################
|
||||
|
||||
if(WIN32)
|
||||
if(CMAKE_CL_64)
|
||||
set(BITNESS "64")
|
||||
else()
|
||||
set(BITNESS "32")
|
||||
endif()
|
||||
else()
|
||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(BITNESS "64")
|
||||
else()
|
||||
set(BITNESS "32")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC AND (FORCE_BITNESS_32 OR FORCE_BITNESS_64))
|
||||
message(STATUS "You cannot force a certain bitness for Visual Studio, use the generator settings for this purpose.")
|
||||
message(STATUS "Pass '-G \"Visual Studio 10 2010 Win64\"' to CMake to make a 64bit binary using VS2010.")
|
||||
message(STATUS "Pass '-G \"Visual Studio 10 2010\"' to CMake to make a 32bit binary using VS2010.")
|
||||
message(STATUS "Pass '-G \"Visual Studio 9 2008 Win64\"' to CMake to make a 64bit binary using VS2008.")
|
||||
message(STATUS "Pass '-G \"Visual Studio 9 2008\"' to CMake to make a 32bit binary using VS2008.")
|
||||
message(FATAL_ERROR "Fix that and try again...")
|
||||
endif()
|
||||
|
||||
if(FORCE_BITNESS_32)
|
||||
set(BITNESS "32")
|
||||
elseif(FORCE_BITNESS_64)
|
||||
set(BITNESS "64")
|
||||
elseif(FORCE_BITNESS_NATIVE)
|
||||
set(BITNESS "NATIVE")
|
||||
endif()
|
||||
|
||||
#######################################
|
||||
# SHARED POINTER #
|
||||
#######################################
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake/Modules/FindSharedPtr.cmake")
|
||||
find_shared_ptr()
|
||||
if(NOT SHARED_PTR_FOUND)
|
||||
message(FATAL_ERROR "Must be able to find shared_ptr")
|
||||
else()
|
||||
if(SHARED_PTR_TR1_MEMORY_HEADER)
|
||||
add_definitions("-DSHARED_PTR_TR1_MEMORY_HEADER")
|
||||
endif()
|
||||
if(SHARED_PTR_TR1_NAMESPACE)
|
||||
add_definitions("-DSHARED_PTR_TR1_NAMESPACE")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#######################################
|
||||
# CODE GENERATION TARGETS #
|
||||
#######################################
|
||||
|
||||
# Generate headers from fluid/mixture definitions
|
||||
add_custom_target(
|
||||
generate_headers
|
||||
COMMAND "${PYTHON_EXECUTABLE}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dev/generate_headers.py")
|
||||
|
||||
# Generate examples for various languages
|
||||
if(NOT COOLPROP_NO_EXAMPLES)
|
||||
add_custom_target(
|
||||
generate_examples
|
||||
COMMAND "${PYTHON_EXECUTABLE}" example_generator.py Python
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Example.py"
|
||||
COMMAND "${PYTHON_EXECUTABLE}" example_generator.py Octave
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Example.m"
|
||||
COMMAND "${PYTHON_EXECUTABLE}" example_generator.py R
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Example.R"
|
||||
COMMAND "${PYTHON_EXECUTABLE}" example_generator.py Java
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Example.java"
|
||||
COMMAND "${PYTHON_EXECUTABLE}" example_generator.py Csharp
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Example.cs"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dev/scripts/examples")
|
||||
else()
|
||||
add_custom_target(
|
||||
generate_examples
|
||||
COMMAND echo "Example generation has been disabled with the COOLPROP_NO_EXAMPLES option.")
|
||||
endif()
|
||||
|
||||
#######################################
|
||||
# LIBRARY CONFIGURATION #
|
||||
#######################################
|
||||
|
||||
set(COOLPROP_LIBRARY_SOURCE
|
||||
"src/CoolPropLib.cpp"
|
||||
CACHE STRING "The file that contains the exported functions")
|
||||
|
||||
set(COOLPROP_LIBRARY_HEADER
|
||||
"include/CoolPropLib.h"
|
||||
CACHE STRING "The file that contains the export header")
|
||||
|
||||
set(COOLPROP_LIBRARY_NAME
|
||||
"CoolProp"
|
||||
CACHE STRING "The name of the generated library")
|
||||
|
||||
set(COOLPROP_LIBRARY_EXPORTS
|
||||
""
|
||||
CACHE STRING "The file that contains the export alias list")
|
||||
|
||||
# Determine calling convention based on bitness
|
||||
if("${BITNESS}" STREQUAL "32")
|
||||
if(COOLPROP_CDECL_LIBRARY)
|
||||
set(CONVENTION "__cdecl")
|
||||
elseif(COOLPROP_STDCALL_LIBRARY)
|
||||
set(CONVENTION "__stdcall")
|
||||
else()
|
||||
set(CONVENTION "")
|
||||
endif()
|
||||
elseif("${BITNESS}" STREQUAL "64")
|
||||
if(COOLPROP_CDECL_LIBRARY)
|
||||
message(WARNING "You cannot use cdecl conventions in a 64-bit library.")
|
||||
elseif(COOLPROP_STDCALL_LIBRARY)
|
||||
message(WARNING "You cannot use stdcall conventions in a 64-bit library.")
|
||||
endif()
|
||||
set(CONVENTION "")
|
||||
elseif("${BITNESS}" STREQUAL "NATIVE")
|
||||
set(CONVENTION "")
|
||||
else()
|
||||
message(FATAL_ERROR "Bitness is not defined. Set it and run cmake again.")
|
||||
endif()
|
||||
|
||||
# Validate library type options
|
||||
if((COOLPROP_OBJECT_LIBRARY AND COOLPROP_STATIC_LIBRARY)
|
||||
OR (COOLPROP_OBJECT_LIBRARY AND COOLPROP_SHARED_LIBRARY)
|
||||
OR (COOLPROP_STATIC_LIBRARY AND COOLPROP_SHARED_LIBRARY))
|
||||
message(FATAL_ERROR "You can only use one of the library switches!")
|
||||
endif()
|
||||
|
||||
#######################################
|
||||
# BUILD LIBRARY TARGET #
|
||||
#######################################
|
||||
|
||||
if(COOLPROP_OBJECT_LIBRARY OR COOLPROP_STATIC_LIBRARY OR COOLPROP_SHARED_LIBRARY)
|
||||
set(LIB_NAME ${COOLPROP_LIBRARY_NAME})
|
||||
|
||||
# Create library target based on type
|
||||
if(COOLPROP_OBJECT_LIBRARY)
|
||||
add_library(${LIB_NAME} OBJECT ${APP_SOURCES})
|
||||
set(COOLPROP_LIBRARY_SOURCE "")
|
||||
set(COOLPROP_LIBRARY_HEADER "")
|
||||
|
||||
elseif(COOLPROP_STATIC_LIBRARY)
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_SOURCE}")
|
||||
add_library(${LIB_NAME} STATIC ${APP_SOURCES} ${COOLPROP_LIBRARY_EXPORTS})
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY DEBUG_POSTFIX d)
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY RELEASE_POSTFIX)
|
||||
modify_msvc_flags("/MD")
|
||||
endif()
|
||||
|
||||
install(TARGETS ${LIB_NAME}
|
||||
DESTINATION static_library/${CMAKE_SYSTEM_NAME}/${BITNESS}bit_${CMAKE_CXX_COMPILER_ID}_${CMAKE_CXX_COMPILER_VERSION})
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_HEADER}
|
||||
DESTINATION static_library)
|
||||
|
||||
elseif(COOLPROP_SHARED_LIBRARY)
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_SOURCE}")
|
||||
add_library(${LIB_NAME} SHARED ${APP_SOURCES} ${COOLPROP_LIBRARY_EXPORTS})
|
||||
|
||||
# Determine output folder (special handling for ARM64)
|
||||
if(MSVC AND ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64" OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "arm64"))
|
||||
set(OUTPUT_FOLDER "shared_library/${CMAKE_SYSTEM_NAME}/${BITNESS}bit__arm64")
|
||||
else()
|
||||
set(OUTPUT_FOLDER "shared_library/${CMAKE_SYSTEM_NAME}/${BITNESS}bit${CONVENTION}")
|
||||
endif()
|
||||
|
||||
install(TARGETS ${LIB_NAME} DESTINATION ${OUTPUT_FOLDER})
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_HEADER}
|
||||
DESTINATION shared_library)
|
||||
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -DCOOLPROP_LIB")
|
||||
|
||||
# MSVC-specific settings
|
||||
if(MSVC)
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY DEBUG_POSTFIX d)
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY RELEASE_POSTFIX)
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY PREFIX "")
|
||||
modify_msvc_flags("/MT")
|
||||
|
||||
# Generate exports and headers dumps
|
||||
add_custom_command(TARGET ${LIB_NAME} POST_BUILD
|
||||
COMMAND dumpbin /EXPORTS $<TARGET_FILE:${LIB_NAME}> >
|
||||
${CMAKE_CURRENT_BINARY_DIR}/exports.txt)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/exports.txt DESTINATION ${OUTPUT_FOLDER})
|
||||
|
||||
add_custom_command(TARGET ${LIB_NAME} POST_BUILD
|
||||
COMMAND dumpbin /HEADERS $<TARGET_FILE:${LIB_NAME}> >
|
||||
${CMAKE_CURRENT_BINARY_DIR}/headers.txt)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/headers.txt DESTINATION ${OUTPUT_FOLDER})
|
||||
endif()
|
||||
|
||||
# Linux-specific settings
|
||||
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY VERSION ${COOLPROP_VERSION})
|
||||
set_property(TARGET ${LIB_NAME} PROPERTY SOVERSION ${COOLPROP_VERSION_MAJOR})
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "You have to build a static or shared library.")
|
||||
endif()
|
||||
|
||||
# Link with dynamic loading libraries
|
||||
if(NOT COOLPROP_OBJECT_LIBRARY)
|
||||
target_link_libraries(${LIB_NAME} ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
|
||||
# Eigen workaround for MSVC 2008
|
||||
if(MSVC90)
|
||||
message(STATUS "EIGEN WORKAROUND ACTIVE!!")
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -DEIGEN_DONT_VECTORIZE")
|
||||
endif()
|
||||
|
||||
# macOS-specific settings
|
||||
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
|
||||
if(DEFINED OSX_COMPILE_FLAGS)
|
||||
set_target_properties(${LIB_NAME} PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "${OSX_COMPILE_FLAGS}")
|
||||
endif()
|
||||
if(DEFINED OSX_LINK_FLAGS)
|
||||
set_target_properties(${LIB_NAME} PROPERTIES APPEND_STRING PROPERTY LINK_FLAGS "${OSX_LINK_FLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Name mangling settings
|
||||
if(COOLPROP_EXTERNC_LIBRARY)
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXTERNC")
|
||||
endif()
|
||||
|
||||
# Dependencies
|
||||
add_dependencies(${LIB_NAME} generate_headers)
|
||||
|
||||
# Include directories
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.0)
|
||||
target_include_directories(${LIB_NAME} PUBLIC ${APP_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# Set bitness flags
|
||||
if(NOT MSVC)
|
||||
if(NOT "${BITNESS}" STREQUAL "NATIVE")
|
||||
message(STATUS "Setting bitness flag -m${BITNESS}")
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -m${BITNESS}")
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY LINK_FLAGS " -m${BITNESS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Position-independent code flag
|
||||
if(COOLPROP_FPIC)
|
||||
message(STATUS "Setting fPIC flag")
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -fPIC")
|
||||
endif()
|
||||
|
||||
# Calling conventions
|
||||
if(NOT ("${CONVENTION}" STREQUAL "NULL" OR "${CONVENTION}" STREQUAL ""))
|
||||
set_property(TARGET ${LIB_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -DCONVENTION=${CONVENTION}")
|
||||
endif()
|
||||
|
||||
# Status messages
|
||||
message(STATUS "Library compilation detected:")
|
||||
message(STATUS "Creating ${LIB_NAME}, a ${BITNESS}-bit library")
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "COOLPROP_STATIC_LIBRARY: ${COOLPROP_STATIC_LIBRARY}")
|
||||
message(STATUS "COOLPROP_SHARED_LIBRARY: ${COOLPROP_SHARED_LIBRARY}")
|
||||
message(STATUS "COOLPROP_OBJECT_LIBRARY: ${COOLPROP_OBJECT_LIBRARY}")
|
||||
message(STATUS "CONVENTION: ${CONVENTION}")
|
||||
message(STATUS "COOLPROP_LIBRARY_HEADER: ${COOLPROP_LIBRARY_HEADER}")
|
||||
message(STATUS "COOLPROP_LIBRARY_SOURCE: ${COOLPROP_LIBRARY_SOURCE}")
|
||||
|
||||
get_property(tmpVar TARGET ${LIB_NAME} PROPERTY COMPILE_FLAGS)
|
||||
message(STATUS "COMPILE_FLAGS: ${tmpVar}")
|
||||
get_property(tmpVar TARGET ${LIB_NAME} PROPERTY LINK_FLAGS)
|
||||
message(STATUS "LINK_FLAGS: ${tmpVar}")
|
||||
endif()
|
||||
|
||||
#######################################
|
||||
# PLATFORM-SPECIFIC BUILDS #
|
||||
#######################################
|
||||
|
||||
# iOS target
|
||||
if(COOLPROP_IOS_TARGET)
|
||||
set(SDKVER "9.2")
|
||||
set(DEVROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer")
|
||||
set(SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk")
|
||||
if(EXISTS ${SDKROOT})
|
||||
set(CMAKE_OSX_SYSROOT "${SDKROOT}")
|
||||
else()
|
||||
message("Warning, iOS Base SDK path not found: " ${SDKROOT})
|
||||
endif()
|
||||
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)")
|
||||
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# Debian package
|
||||
if(COOLPROP_DEBIAN_PACKAGE)
|
||||
if(NOT UNIX)
|
||||
message(FATAL_ERROR "COOLPROP_DEBIAN_PACKAGE can only be used on linux host")
|
||||
endif()
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CoolPropLib.cpp")
|
||||
add_library(CoolProp SHARED ${APP_SOURCES})
|
||||
set_target_properties(CoolProp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DCOOLPROP_LIB")
|
||||
set_target_properties(CoolProp PROPERTIES VERSION ${COOLPROP_VERSION}
|
||||
SOVERSION ${COOLPROP_VERSION_MAJOR})
|
||||
add_dependencies(CoolProp generate_headers)
|
||||
install(TARGETS CoolProp DESTINATION "${CMAKE_INSTALL_PREFIX}/usr/lib")
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/CoolPropLib.h
|
||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/usr/include")
|
||||
endif()
|
||||
|
||||
# VxWorks makefile generation
|
||||
if(COOLPROP_VXWORKS_MAKEFILE)
|
||||
set(INCLUDE_DIRECTORIES)
|
||||
foreach(_srcFile ${APP_INCLUDE_DIRS})
|
||||
string(CONCAT _el "-I\"" ${_srcFile} "\"")
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "$(COOLPROP_ROOT)" _el "${_el}")
|
||||
list(APPEND INCLUDE_DIRECTORIES ${_el})
|
||||
endforeach()
|
||||
string(REPLACE ";" " " INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}")
|
||||
set(OLD_ROOT /home/ian/.wine/drive_c/)
|
||||
set(NEW_ROOT c:/)
|
||||
string(REPLACE ${OLD_ROOT} ${NEW_ROOT} INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}")
|
||||
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
string(REPLACE ${OLD_ROOT} ${NEW_ROOT} SRC "${SRC}")
|
||||
file(RELATIVE_PATH COOLPROP_ROOT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Labview/vxWorks/Makefile.in" "vxWorksMakefile")
|
||||
endif()
|
||||
|
||||
# VxWorks library
|
||||
if(COOLPROP_VXWORKS_LIBRARY_MODULE OR COOLPROP_VXWORKS_LIBRARY)
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CoolPropLib.cpp")
|
||||
add_executable(CoolProp ${APP_SOURCES})
|
||||
set_target_properties(CoolProp PROPERTIES SUFFIX ".out"
|
||||
COMPILE_FLAGS "${COMPILE_FLAGS} -DEXTERNC")
|
||||
add_dependencies(CoolProp generate_headers)
|
||||
install(TARGETS CoolProp DESTINATION "${COOLPROP_INSTALL_PREFIX}/shared_library/VxWorks")
|
||||
endif()
|
||||
76
cmake/Dependencies.cmake
Normal file
76
cmake/Dependencies.cmake
Normal file
@@ -0,0 +1,76 @@
|
||||
#######################################
|
||||
# REQUIRED MODULES #
|
||||
#-------------------------------------#
|
||||
# CoolProp requires some standard OS #
|
||||
# features, these include: #
|
||||
# DL (CMAKE_DL_LIBS) for REFPROP #
|
||||
#######################################
|
||||
|
||||
# Add custom CMake module path
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake/Modules/")
|
||||
|
||||
# Find Python interpreter (needed for code generation)
|
||||
message(STATUS "Looking for Python")
|
||||
find_package(Python COMPONENTS Interpreter)
|
||||
if(Python_Interpreter_FOUND)
|
||||
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
|
||||
endif()
|
||||
if(NOT PYTHON_EXECUTABLE)
|
||||
message(WARNING "Could not find Python, be prepared for errors.")
|
||||
endif()
|
||||
|
||||
# Find dynamic loading libraries if needed
|
||||
if(CMAKE_DL_LIBS)
|
||||
find_package(${CMAKE_DL_LIBS} REQUIRED)
|
||||
endif()
|
||||
|
||||
# Include flag manipulation functions
|
||||
include(FlagFunctions) # Is found since it is in the module path.
|
||||
|
||||
# MSVC flag manipulation macros
|
||||
macro(modify_msvc_flag_release flag_new) # Use a macro to avoid a new scope
|
||||
foreach(flag_old IN LISTS COOLPROP_MSVC_ALL)
|
||||
remove_compiler_flag_release("${flag_old} ") # add a space
|
||||
remove_compiler_flag_release(" ${flag_old}") # add a space
|
||||
endforeach()
|
||||
add_compiler_flag_release("${flag_new}")
|
||||
endmacro()
|
||||
|
||||
macro(modify_msvc_flag_debug flag_new) # Use a macro to avoid a new scope
|
||||
foreach(flag_old IN LISTS COOLPROP_MSVC_ALL)
|
||||
remove_compiler_flag_debug("${flag_old} ") # add a space
|
||||
remove_compiler_flag_debug(" ${flag_old}") # add a space
|
||||
endforeach()
|
||||
add_compiler_flag_debug("${flag_new}")
|
||||
endmacro()
|
||||
|
||||
macro(modify_msvc_flags flag_default) # Use a macro to avoid a new scope
|
||||
if(NOT "${COOLPROP_MSVC_REL}" STREQUAL "IGNORE")
|
||||
modify_msvc_flag_release("${COOLPROP_MSVC_REL}")
|
||||
else()
|
||||
modify_msvc_flag_release("${flag_default}")
|
||||
endif()
|
||||
if(NOT "${COOLPROP_MSVC_DBG}" STREQUAL "IGNORE")
|
||||
modify_msvc_flag_debug("${COOLPROP_MSVC_DBG}")
|
||||
else()
|
||||
modify_msvc_flag_debug("${flag_default}d")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Define COOLPROP_MSVC_ALL for the macros
|
||||
set(COOLPROP_MSVC_ALL "/MTd" "/MT" "/MDd" "/MD"
|
||||
CACHE STRING "List of all MSVC runtime flags")
|
||||
|
||||
# Extract and decompress boost if needed
|
||||
set(ZIPFN "${CMAKE_CURRENT_SOURCE_DIR}/dev/docker/boost_bcp_docker/boost_CoolProp.tar.xz")
|
||||
set(OUTFN "${CMAKE_CURRENT_SOURCE_DIR}/boost_CoolProp/boost/version.hpp")
|
||||
if(EXISTS ${ZIPFN})
|
||||
if(NOT EXISTS ${OUTFN})
|
||||
message(STATUS "Extracting boost...")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${ZIPFN}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
else()
|
||||
message(STATUS "Boost already extracted")
|
||||
endif()
|
||||
endif()
|
||||
73
cmake/Options.cmake
Normal file
73
cmake/Options.cmake
Normal file
@@ -0,0 +1,73 @@
|
||||
#######################################
|
||||
# BUILD OPTIONS #
|
||||
#-------------------------------------#
|
||||
# These options are available to be #
|
||||
# modified in the build process. #
|
||||
# packages may want to modify these #
|
||||
# to suit, or just leave as defaults. #
|
||||
#######################################
|
||||
|
||||
# Library build types
|
||||
option(COOLPROP_STATIC_LIBRARY "Build CoolProp as a static library (.lib, .a)" OFF)
|
||||
option(COOLPROP_SHARED_LIBRARY "Build CoolProp as a shared library (.dll, .so)" OFF)
|
||||
option(COOLPROP_OBJECT_LIBRARY "Build CoolProp objects, but do not link them (.obj, .o)" OFF)
|
||||
|
||||
# Platform-specific packages
|
||||
option(COOLPROP_WINDOWS_PACKAGE "Build the Windows installer" OFF)
|
||||
option(COOLPROP_DEBIAN_PACKAGE "Build Debian package" OFF)
|
||||
option(COOLPROP_IOS_TARGET "Build for iOS" OFF)
|
||||
|
||||
# Build configuration
|
||||
option(BUILD_TESTING "Enable testing for this given builder" OFF)
|
||||
option(COOLPROP_RELEASE "Optimize the builds with the release specs" OFF)
|
||||
option(COOLPROP_DEBUG "Make a debug build" OFF)
|
||||
option(COOLPROP_NO_EXAMPLES "Do not generate example code, does only apply to some wrappers." OFF)
|
||||
|
||||
# Bitness options
|
||||
option(FORCE_BITNESS_32 "Force a 32bit build regardless of the host" OFF)
|
||||
option(FORCE_BITNESS_64 "Force a 64bit build regardless of the host" OFF)
|
||||
option(FORCE_BITNESS_NATIVE "Force a native bitness build regardless of the host" OFF)
|
||||
|
||||
# MSVC-specific options
|
||||
option(COOLPROP_MSVC_STATIC "Statically link Microsoft Standard library removes dependency on MSVCRXXX.dll." OFF)
|
||||
option(COOLPROP_MSVC_DYNAMIC "Dynamically link Microsoft Standard library to integrate with other builds." OFF)
|
||||
option(COOLPROP_MSVC_DEBUG "Link the debug version of Microsoft Standard library to the debug builds." ON)
|
||||
|
||||
# Library calling conventions (32-bit only)
|
||||
option(COOLPROP_STDCALL_LIBRARY "Build CoolProp as a 32bit shared library with stdcall" OFF)
|
||||
option(COOLPROP_CDECL_LIBRARY "Build CoolProp as a 32bit shared library with cdecl" OFF)
|
||||
option(COOLPROP_EXTERNC_LIBRARY "Overwrite the export settings to force extern C" OFF)
|
||||
|
||||
# Language wrapper modules
|
||||
option(COOLPROP_EES_MODULE "Build the EES module" OFF)
|
||||
option(COOLPROP_PRIME_MODULE "Build Mathcad Prime module" OFF)
|
||||
option(COOLPROP_MATHCAD15_MODULE "Build Mathcad 15 module" OFF)
|
||||
option(COOLPROP_OCTAVE_MODULE "Build Octave module" OFF)
|
||||
option(COOLPROP_PYTHON_MODULE "Build Python module" OFF)
|
||||
option(COOLPROP_CSHARP_MODULE "Build C# module" OFF)
|
||||
option(COOLPROP_VBDOTNET_MODULE "Build VB.NET module" OFF)
|
||||
option(COOLPROP_R_MODULE "Build R module" OFF)
|
||||
option(COOLPROP_JAVA_MODULE "Build Java module" OFF)
|
||||
option(COOLPROP_ANDROID_MODULE "Build Android module" OFF)
|
||||
option(COOLPROP_PHP_MODULE "Build PHP module" OFF)
|
||||
option(COOLPROP_LIBREOFFICE_MODULE "Build LibreOffice extension" OFF)
|
||||
option(COOLPROP_JAVASCRIPT_MODULE "Build Javascript module" OFF)
|
||||
option(COOLPROP_MATHEMATICA_MODULE "Build Mathematica module" OFF)
|
||||
option(COOLPROP_SMATH_MODULE "Build SMath module" OFF)
|
||||
option(COOLPROP_SMATH_WORK_INPLACE "Build SMath wrapper in source directory" OFF)
|
||||
|
||||
# Example and test modules
|
||||
option(COOLPROP_MAIN_MODULE "Build main example" OFF)
|
||||
option(COOLPROP_CATCH_MODULE "Build Catch test runner" OFF)
|
||||
option(COOLPROP_CPP_EXAMPLE_TEST "Build C++ example test" OFF)
|
||||
option(COOLPROP_SNIPPETS "Build code snippets" OFF)
|
||||
|
||||
# Development options
|
||||
option(COOLPROP_VXWORKS_MAKEFILE "Generate VxWorks makefile" OFF)
|
||||
option(COOLPROP_VXWORKS_LIBRARY_MODULE "Build VxWorks library module" OFF)
|
||||
option(COOLPROP_VXWORKS_LIBRARY "Build VxWorks library" OFF)
|
||||
option(COOLPROP_FPIC "Add -fPIC flag" OFF)
|
||||
option(COOLPROP_IWYU "Enable include-what-you-use" OFF)
|
||||
option(COOLPROP_ASAN "Enable address sanitizer" OFF)
|
||||
option(COOLPROP_CLANG_ADDRESS_SANITIZER "Build with Clang address sanitizer" OFF)
|
||||
option(COOLPROP_LAZY_LOAD_SUPERANCILLARIES "Lazy load superancillaries" OFF)
|
||||
88
cmake/Sources.cmake
Normal file
88
cmake/Sources.cmake
Normal file
@@ -0,0 +1,88 @@
|
||||
#######################################
|
||||
# FIND ALL SOURCES #
|
||||
#-------------------------------------#
|
||||
# The project is organised with #
|
||||
# split includes and source folders #
|
||||
# this makes it easier for developers #
|
||||
# to quickly find relevant includes. #
|
||||
# This section finds all sources, #
|
||||
# headers and corresponding dirs. #
|
||||
#######################################
|
||||
|
||||
# These backends will be compiled in
|
||||
set(COOLPROP_ENABLED_BACKENDS
|
||||
Cubics
|
||||
IF97
|
||||
Helmholtz
|
||||
REFPROP
|
||||
Incompressible
|
||||
Tabular
|
||||
PCSAFT)
|
||||
|
||||
# Get everything in the src/ directory (always), but not recursive
|
||||
file(GLOB APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
||||
|
||||
# Add the miniz source file
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/externals/miniz-3.0.2/miniz.c")
|
||||
|
||||
# For each enabled backend, grab its files
|
||||
foreach(backend ${COOLPROP_ENABLED_BACKENDS})
|
||||
file(GLOB_RECURSE BACKEND_SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Backends/${backend}/*.cpp")
|
||||
list(APPEND APP_SOURCES ${BACKEND_SOURCES})
|
||||
endforeach()
|
||||
|
||||
## You can exclude this file, in case you want to run your own tests or use Catch
|
||||
list(REMOVE_ITEM APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/Tests.cpp")
|
||||
list(REMOVE_ITEM APP_SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/CoolProp-Tests.cpp")
|
||||
|
||||
## This file is only needed for the library, normal builds do not need it.
|
||||
list(REMOVE_ITEM APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CoolPropLib.cpp")
|
||||
|
||||
# Set up include directories
|
||||
set(APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/msgpack-c/include")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/miniz-3.0.2")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/nlohmann-json")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/incbin")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dev")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/boost_CoolProp")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/fmtlib/include")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/fmtlib") # should be deprecated
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
# MSVC-specific flags for fmtlib
|
||||
if(MSVC)
|
||||
# fmtlib requires that the utf-8 support be compiled in
|
||||
# TODO: add the fmt target from fmtlib directly which does this
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 -D_CRT_SECURE_NO_WARNINGS")
|
||||
endif()
|
||||
|
||||
## Set endianess for msgpack on ARM64 with MSVC
|
||||
#if(MSVC)
|
||||
# if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM64")
|
||||
# message(STATUS "Forcing msgpack-c to use little endian configuration")
|
||||
# add_compile_definitions(MSGPACK_ENDIAN_LITTLE_BYTE)
|
||||
# endif()
|
||||
#endif()
|
||||
|
||||
include_directories(${APP_INCLUDE_DIRS})
|
||||
|
||||
# SWIG dependencies for wrapper modules
|
||||
set(SWIG_DEPENDENCIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/DataStructures.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/CoolProp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/AbstractState.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/Configuration.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/PhaseEnvelope.h)
|
||||
|
||||
# Cache the sources and include dirs for use in other modules
|
||||
set(COOLPROP_APP_SOURCES
|
||||
"${APP_SOURCES}"
|
||||
CACHE STRING "List of CPP sources needed for CoolProp")
|
||||
set(COOLPROP_INCLUDE_DIRECTORIES
|
||||
"${APP_INCLUDE_DIRS}"
|
||||
CACHE STRING "List of include directories needed for CoolProp")
|
||||
176
cmake/Testing.cmake
Normal file
176
cmake/Testing.cmake
Normal file
@@ -0,0 +1,176 @@
|
||||
#######################################
|
||||
# TESTING MODULES #
|
||||
#-------------------------------------#
|
||||
# Test executables and development #
|
||||
# tools for CoolProp #
|
||||
#######################################
|
||||
|
||||
# Main executable module
|
||||
if(COOLPROP_MAIN_MODULE)
|
||||
# Allow you to independently add back the testing CPP files
|
||||
if(COOLPROP_TEST)
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/Tests.cpp")
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/CoolProp-Tests.cpp")
|
||||
endif()
|
||||
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cxx")
|
||||
add_executable(Main ${APP_SOURCES})
|
||||
add_dependencies(Main generate_headers)
|
||||
|
||||
if(COOLPROP_TEST)
|
||||
set_target_properties(Main PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DENABLE_CATCH")
|
||||
endif()
|
||||
|
||||
if(COOLPROP_IWYU)
|
||||
find_program(iwyu_path NAMES include-what-you-use iwyu)
|
||||
if(NOT iwyu_path)
|
||||
message(FATAL_ERROR "Could not find the program include-what-you-use")
|
||||
endif()
|
||||
set_property(TARGET Main PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(Main ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Catch2 test runner
|
||||
if(COOLPROP_CATCH_MODULE)
|
||||
add_subdirectory("externals/Catch2")
|
||||
enable_testing()
|
||||
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/CoolProp-Tests.cpp")
|
||||
|
||||
# CATCH TEST, compile everything with catch and set test entry point
|
||||
add_executable(CatchTestRunner ${APP_SOURCES})
|
||||
add_dependencies(CatchTestRunner generate_headers)
|
||||
|
||||
target_link_libraries(CatchTestRunner PRIVATE Catch2::Catch2WithMain)
|
||||
target_compile_definitions(CatchTestRunner PRIVATE ENABLE_CATCH)
|
||||
# Incbin is disabled for Catch2 because of a weird behavior where out-of-date zlib-compressed fluid information were being used.
|
||||
target_compile_definitions(CatchTestRunner PRIVATE COOLPROP_NO_INCBIN)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(CatchTestRunner PRIVATE ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
|
||||
target_include_directories(CatchTestRunner PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/externals/multicomplex/multicomplex/include")
|
||||
|
||||
include(CTest)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/externals/Catch2/extras/Catch.cmake)
|
||||
|
||||
if(NOT CMAKE_GENERATOR STREQUAL Xcode)
|
||||
# Test discovery doesn't work in Xcode, due to a signing bug in Xcode which causes discovery to fail: https://github.com/catchorg/Catch2/issues/2411
|
||||
catch_discover_tests(CatchTestRunner DISCOVERY_MODE PRE_TEST)
|
||||
endif()
|
||||
|
||||
if(COOLPROP_IWYU)
|
||||
find_program(iwyu_path NAMES include-what-you-use iwyu)
|
||||
if(NOT iwyu_path)
|
||||
message(FATAL_ERROR "Could not find the program include-what-you-use")
|
||||
endif()
|
||||
set_property(TARGET CatchTestRunner PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
|
||||
endif()
|
||||
|
||||
if(COOLPROP_LAZY_LOAD_SUPERANCILLARIES)
|
||||
target_compile_definitions(CatchTestRunner PRIVATE LAZY_LOAD_SUPERANCILLARIES)
|
||||
else()
|
||||
# lazy load superancillaries by default in debug mode
|
||||
target_compile_definitions(CatchTestRunner PUBLIC $<$<CONFIG:Debug>:LAZY_LOAD_SUPERANCILLARIES>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# C++ documentation example test
|
||||
if(COOLPROP_CPP_EXAMPLE_TEST)
|
||||
add_executable(docuTest.exe "Web/examples/C++/Example.cpp")
|
||||
add_dependencies(docuTest.exe CoolProp)
|
||||
target_link_libraries(docuTest.exe CoolProp)
|
||||
if(UNIX)
|
||||
target_link_libraries(docuTest.exe ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
add_test(DocumentationTest docuTest.exe)
|
||||
endif()
|
||||
|
||||
# Code snippets builder
|
||||
if(COOLPROP_SNIPPETS)
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${COOLPROP_LIBRARY_SOURCE}")
|
||||
|
||||
# Make the static library with which the snippets will be linked
|
||||
add_library(CoolProp STATIC ${APP_SOURCES})
|
||||
add_dependencies(CoolProp generate_headers)
|
||||
set_property(TARGET CoolProp APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXTERNC")
|
||||
|
||||
# Collect all the snippets
|
||||
file(GLOB_RECURSE snippets "${CMAKE_CURRENT_SOURCE_DIR}/Web/coolprop/snippets/*.cxx")
|
||||
|
||||
message(STATUS "snippets found = ${snippets}")
|
||||
foreach(snippet ${snippets})
|
||||
get_filename_component(snippet_name ${snippet} NAME)
|
||||
get_filename_component(snippet_exe ${snippet} NAME_WE)
|
||||
message(STATUS "snippet_name = ${snippet_name}")
|
||||
|
||||
add_executable(${snippet_exe} ${snippet})
|
||||
add_dependencies(${snippet_exe} CoolProp)
|
||||
target_link_libraries(${snippet_exe} CoolProp)
|
||||
if(UNIX)
|
||||
target_link_libraries(${snippet_exe} ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(${snippet_exe} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/bin
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set(BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
||||
else()
|
||||
set(BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${snippet_exe} APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXTERNC")
|
||||
|
||||
# Run it and save the output to a file with .output appended
|
||||
add_custom_command(TARGET ${snippet_exe} POST_BUILD
|
||||
COMMAND ${BIN_PATH}/${snippet_exe} >
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Web/coolprop/snippets/${snippet_name}.output)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Clang address sanitizer build
|
||||
if(COOLPROP_CLANG_ADDRESS_SANITIZER)
|
||||
set(CMAKE_CXX_FLAGS "-fsanitize=address -g")
|
||||
list(APPEND APP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/Tests/catch_always_return_success.cxx")
|
||||
|
||||
# CATCH TEST, compile everything with catch and set test entry point
|
||||
add_executable(CatchTestRunner ${APP_SOURCES})
|
||||
add_dependencies(CatchTestRunner generate_headers)
|
||||
set_target_properties(CatchTestRunner PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DENABLE_CATCH")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-O1")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address -fno-omit-frame-pointer -lstdc++")
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(CatchTestRunner ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
|
||||
add_custom_command(TARGET CatchTestRunner POST_BUILD
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/CatchTestRunner)
|
||||
endif()
|
||||
|
||||
# Profiling support
|
||||
if(COOLPROP_PROFILE)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "-g -O2")
|
||||
set(CMAKE_C_FLAGS "-g -O2")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Code coverage support
|
||||
if(COOLPROP_COVERAGE)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
# See also http://stackoverflow.com/a/16536401 (detailed guide on using gcov with cmake)
|
||||
include(CodeCoverage)
|
||||
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||
setup_target_for_coverage(CoolProp_coverage Main coverage)
|
||||
endif()
|
||||
endif()
|
||||
20
cmake/Version.cmake
Normal file
20
cmake/Version.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
#######################################
|
||||
# PROJECT INFORMATION #
|
||||
#-------------------------------------#
|
||||
# Version information and project #
|
||||
# metadata for CoolProp #
|
||||
#######################################
|
||||
|
||||
# Project version
|
||||
set(COOLPROP_VERSION_MAJOR 7)
|
||||
set(COOLPROP_VERSION_MINOR 1)
|
||||
set(COOLPROP_VERSION_PATCH 0)
|
||||
set(COOLPROP_VERSION_REVISION )
|
||||
set(COOLPROP_VERSION
|
||||
"${COOLPROP_VERSION_MAJOR}.${COOLPROP_VERSION_MINOR}.${COOLPROP_VERSION_PATCH}${COOLPROP_VERSION_REVISION}"
|
||||
)
|
||||
message(STATUS "CoolProp version: ${COOLPROP_VERSION}")
|
||||
|
||||
# Project metadata
|
||||
string(TIMESTAMP COOLPROP_YEAR 2010-%Y)
|
||||
set(COOLPROP_PUBLISHER "The CoolProp developers")
|
||||
1198
cmake/Wrappers.cmake
Normal file
1198
cmake/Wrappers.cmake
Normal file
File diff suppressed because it is too large
Load Diff
40
cmake/wrappers/Common.cmake
Normal file
40
cmake/wrappers/Common.cmake
Normal file
@@ -0,0 +1,40 @@
|
||||
#######################################
|
||||
# COMMON WRAPPER UTILITIES #
|
||||
#-------------------------------------#
|
||||
# Shared configuration and utilities #
|
||||
# for SWIG-based language wrappers #
|
||||
#######################################
|
||||
|
||||
# Common SWIG interface file
|
||||
set(COOLPROP_SWIG_INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/CoolProp.i")
|
||||
|
||||
# Common SWIG dependencies (headers that trigger SWIG regeneration)
|
||||
# Already set in Sources.cmake, but repeated here for clarity
|
||||
set(SWIG_DEPENDENCIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/DataStructures.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/CoolProp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/AbstractState.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/Configuration.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/PhaseEnvelope.h)
|
||||
|
||||
# Disable internal error catching for SWIG wrappers (let language handle errors)
|
||||
macro(disable_error_catching)
|
||||
add_definitions(-DNO_ERROR_CATCHING)
|
||||
endmacro()
|
||||
|
||||
# Helper macro to set up SWIG module with common configuration
|
||||
macro(setup_swig_module MODULE_NAME LANGUAGE EXTRA_FLAGS)
|
||||
find_package(SWIG REQUIRED)
|
||||
include(${SWIG_USE_FILE})
|
||||
|
||||
set(I_FILE "${COOLPROP_SWIG_INTERFACE}")
|
||||
set(SWIG_MODULE_${MODULE_NAME}_EXTRA_DEPS ${SWIG_DEPENDENCIES})
|
||||
|
||||
# Combine COOLPROP_SWIG_OPTIONS (from command line) with wrapper-specific flags
|
||||
set(SWIG_OPTIONS "${COOLPROP_SWIG_OPTIONS}" "${EXTRA_FLAGS}")
|
||||
string(REPLACE " " ";" SWIG_OPTIONS "${SWIG_OPTIONS}")
|
||||
|
||||
set_source_files_properties(${I_FILE} PROPERTIES
|
||||
SWIG_FLAGS "${SWIG_OPTIONS}"
|
||||
CPLUSPLUS ON)
|
||||
endmacro()
|
||||
Reference in New Issue
Block a user