From 6d0b9e809850870a3906635b261af7458abb4eb8 Mon Sep 17 00:00:00 2001 From: Subhasis Ray Date: Sat, 25 May 2024 16:32:00 +0530 Subject: [PATCH] Updates for Windows MSVC build In setup.py and CMakeLists.txt for build - Added switches for compiler flags for Windows/MSVC - Removed possible override of version in CMakeLists.txt: setup.py should be the only source of version info - Archive format set to zip for windows - Using module name moose instead of _moose, the underscore is added as PREFIX - Platform dependent shared lib file name extension - Removed platform name CMAKE from cmake file - Updated setup.py to allow release build on windows In C++ code - Switched all new style logical opeartors (and, or, not)to C style (&&, ||, !) - these are not recognized by MSVC compiler - Added windows port of getopt in external - Removed SocketStreamer conditionally for Win32 build. Win32 does not have socket library. TODO: look at ports. - CylBase uses a constant PI which does not exist in win32 standard library. Replaced it with cmath's M_PI. Hope they are the same. - Corrected cnpy function for checking numpy file header - Minor correction on printf formatting to avoid warning for size_t build updates for windows - Undefine _DEBUG macro for release builds Added build instructions for windows --- CMakeLists.txt | 85 ++++++++++++++++++++---- CheckCXXCompiler.cmake | 64 ------------------ MANIFEST.in | 1 - basecode/CMakeLists.txt | 12 +++- basecode/Conv.h | 2 +- basecode/doubleEq.h | 4 +- basecode/main.cpp | 4 ++ biophysics/CMakeLists.txt | 1 - builtins/CMakeLists.txt | 23 ++++++- builtins/StreamerBase.cpp | 2 +- cmake/FindGSL.cmake | 116 --------------------------------- device/CMakeLists.txt | 2 +- diffusion/CMakeLists.txt | 2 +- examples/CMakeLists.txt | 2 +- external/CMakeLists.txt | 1 + external/getopt/CMakeLists.txt | 3 + external/getopt/getopt.c | 52 +++++++++++++++ external/getopt/getopt.h | 37 +++++++++++ external/getopt/unistd.h | 56 ++++++++++++++++ hsolve/CMakeLists.txt | 2 +- intfire/CMakeLists.txt | 2 +- kinetics/CMakeLists.txt | 2 +- kinetics/WriteKkit.cpp | 12 ++-- ksolve/CMakeLists.txt | 2 +- ksolve/SteadyStateGsl.cpp | 2 +- ksolve/Stoich.cpp | 2 +- mesh/CMakeLists.txt | 2 +- mesh/CylBase.cpp | 26 ++++---- mpi/CMakeLists.txt | 2 +- msg/CMakeLists.txt | 2 +- pybind11/CMakeLists.txt | 64 +++++++++++------- pybind11/Finfo.cpp | 2 +- pybind11/MooseVec.cpp | 2 +- pybind11/PyRun.cpp | 8 +++ pybind11/PyRun.h | 4 ++ pybind11/helper.cpp | 5 ++ pybind11/helper.h | 2 +- pymoose/CMakeLists.txt | 67 +++++++++---------- scheduling/CMakeLists.txt | 2 +- setup.py | 41 ++++++++---- shell/CMakeLists.txt | 1 - shell/Shell.cpp | 2 + signeur/CMakeLists.txt | 2 +- synapse/CMakeLists.txt | 2 +- utility/CMakeLists.txt | 12 +++- utility/cnpy.cpp | 32 +++++---- utility/print_function.hpp | 2 +- 47 files changed, 440 insertions(+), 335 deletions(-) delete mode 100644 CheckCXXCompiler.cmake delete mode 100644 cmake/FindGSL.cmake create mode 100644 external/getopt/CMakeLists.txt create mode 100644 external/getopt/getopt.c create mode 100644 external/getopt/getopt.h create mode 100644 external/getopt/unistd.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cb51595c2c..65c49d6ae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,33 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) +set( CMAKE_VERBOSE_MAKEFILE on ) + # Project to build MOOSE's python module. project(PyMOOSE) # cmake related macros. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(CheckCXXCompiler.cmake) -include(CheckIncludeFileCXX) +# include(CheckIncludeFileCXX) + # We find python executable here. Though mainly used inside pymoose. -find_package(Python3 COMPONENTS Interpreter Numpy) -set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) -find_package(PythonInterp 3.8) +find_package(Python COMPONENTS Interpreter Development NumPy) set(CMAKE_MACOSX_RPATH OFF) # NOTE: version should be changed in setup.py file. # If moose version is not given, use setup.py file to get the default version. -if(NOT VERSION_MOOSE) - execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py --version +# Note: Sun Jun 9 12:12:28 IST 2024 - somehow build does not get the version - it remains empty when creating packages and the process fails with file not found error: +# - MOOSE_VERSION is a preprocessor macro to keep the version number as part of the binary library (Shell.cpp uses it) whereas VERSION_MOOSE is the CMake variable passed for populating the preprocessor macro def as well as for adding version info in the package file name. +execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py --version WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE VERSION_MOOSE OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() + add_definitions(-DMOOSE_VERSION="${VERSION_MOOSE}") + + message(STATUS "MOOSE Version ${VERSION_MOOSE}") # This snippet is from LLVM project. @@ -65,6 +68,17 @@ option(WITH_LEGACY_BINDING "Use legacy python-bindings" OFF) # Default definitions. add_definitions(-DUSE_GENESIS_PARSER) + +# M_PI is undefined in MSVC unless _USE_MATH_DEFINES is defined before cmath import +# Also, MSVC throws this error +# "external\exprtk\exprtk.hpp(10183): fatal error C1128: number of sections exceeded object file format limit" +# and suggests "compile with /bigobj" +# - Subha +if(MSVC) + add_definitions(-D_USE_MATH_DEFINES) + set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} /bigobj) +endif() + if(DEBUG OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") message(STATUS "Building for Debug/Unit testing") add_definitions(-DDO_UNIT_TESTS -O) @@ -76,7 +90,9 @@ elseif(ENABLE_UNIT_TESTS) else() message(STATUS "Building for Release/No unit tests.") set(CMAKE_BUILD_TYPE Release) - add_definitions(-UDO_UNIT_TESTS -O3 -DDISABLE_DEBUG) + if(NOT MSVC) + add_definitions(-UDO_UNIT_TESTS -O3 -DDISABLE_DEBUG) + endif() endif() if(GPROF AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") @@ -94,6 +110,13 @@ if(WITH_ASAN AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address") endif() +if(MSVC) + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /FORCE:MULTIPLE") + set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /FORCE:MULTIPLE") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /FORCE:MULTIPLE") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE") +endif() + # Override default GSL solvers when BOOST is enabled. if(WITH_BOOST OR WITH_BOOST_ODE) set(WITH_BOOST_ODE ON) @@ -122,7 +145,7 @@ endif() ################################### TARGETS #################################### link_directories(${CMAKE_BINARY_DIR}) -add_library(libmoose SHARED basecode/main.cpp) +add_library(libmoose SHARED basecode/main.cpp external/getopt/getopt.c) set_target_properties(libmoose PROPERTIES PREFIX "") add_executable(moose.bin basecode/main.cpp) @@ -130,7 +153,7 @@ add_executable(moose.bin basecode/main.cpp) ################################### SETUP BUILD ################################ # Variable to collect all static libraries. -set(STATIC_LIBRARIES "" ) +set(STATIC_LIBRARIES "") # Collect all shared libraries here. set(SYSTEM_SHARED_LIBS "") @@ -218,6 +241,12 @@ if(WITH_MPI) endif() endif(WITH_MPI) + +# DEBUG compilation process +# get_target_property(compile_defs libmoose COMPILE_DEFINITIONS) +# message(STATUS "App compile definitions are ${compile_defs}") +# DEBUG compilation process + # Add subdirectroeis add_subdirectory(basecode) add_subdirectory(msg) @@ -241,6 +270,7 @@ add_subdirectory(external) # development related. add_subdirectory(devel) + ###################################### LINKING ################################# list(APPEND MOOSE_LIBRARIES @@ -265,6 +295,13 @@ list(APPEND MOOSE_LIBRARIES basecode ) +# If windows MSVC, include port of getopt +if(MSVC) + list(APPEND MOOSE_LIBRARIES getopt) + target_include_directories(moose.bin PRIVATE external/getopt) + target_include_directories(libmoose PRIVATE external/getopt) +endif() + # Make sure to remove duplicates. list(REMOVE_DUPLICATES STATIC_LIBRARIES) if(SYSTEM_SHARED_LIBS) @@ -293,6 +330,12 @@ if(APPLE) ${SYSTEM_SHARED_LIBS} ${CMAKE_DL_LIBS} ) +elseif(MSVC) + target_link_libraries(libmoose + ${MOOSE_LIBRARIES} + ${STATIC_LIBRARIES} + ${SYSTEM_SHARED_LIBS} + ) else(APPLE) target_link_libraries(libmoose "-Wl,--whole-archive" @@ -310,13 +353,16 @@ if( WITH_BOOST ) target_link_libraries( moose.bin ${Boost_LIBRARIES} ) endif( WITH_BOOST ) + ######################### BUILD PYMOOSE ######################################## # pybind11 should be installed as a dependency. # It can be easily done with `pip install pybind11` # See: https://pybind11.readthedocs.io/en/stable/installing.html # - Subha, Mon Apr 22 14:26:58 IST 2024 -execute_process(COMMAND ${CMAKE_COMMAND} -E pybind11-config --cmakedir OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + +# The execute_process fails on Windows with Mamba +# execute_process(COMMAND ${CMAKE_COMMAND} -E pybind11-config --cmakedir OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}") add_subdirectory(pybind11) @@ -364,9 +410,20 @@ include(CTest) add_subdirectory(tests) ########################### RELEASE ######################################### -set(PYMOOSE_SDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.tar.gz) +if(WIN32) + set(PYMOOSE_SDIST_FILE "${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.zip") + set(ARCHIVE_FORMAT zip) +else(WIN32) + set(PYMOOSE_SDIST_FILE "${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.tar.gz") + set(ARCHIVE_FORMAT gztar) +endif() + +# Tue Jun 11 08:11:00 IST 2024 +# NOTE: Calling setup.py directly for building packages is deprecated. +# Use python -m build --wheel instead +# - Subha add_custom_target(sdist - COMMAND ${PYTHON_EXECUTABLE} setup.py sdist --formats=gztar + COMMAND ${PYTHON_EXECUTABLE} setup.py sdist --formats=${ARCHIVE_FORMAT} -d ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Creating sdist ${PYMOOSE_SDIST_FILE}" diff --git a/CheckCXXCompiler.cmake b/CheckCXXCompiler.cmake deleted file mode 100644 index 1fbf9cd2e6..0000000000 --- a/CheckCXXCompiler.cmake +++ /dev/null @@ -1,64 +0,0 @@ -# Compiler check. -# Must support c++14 -# If python2 is supported then we can not use c++17. -if(COMPILER_IS_TESTED) - return() -endif() - -########################### COMPILER MACROS ##################################### -include(CheckCXXCompilerFlag) -if(WIN32) - CHECK_CXX_COMPILER_FLAG("/std:c++14" COMPILER_SUPPORTS_CXX14 ) -else(WIN32) - CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14 ) - CHECK_CXX_COMPILER_FLAG("-Wno-strict-aliasing" COMPILER_WARNS_STRICT_ALIASING ) -endif(WIN32) - -# Turn warning to error: Not all of the options may be supported on all -# versions of compilers. be careful here. -add_definitions(-Wall - #-Wno-return-type-c-linkage - -Wno-unused-variable - -Wno-unused-function - #-Wno-unused-private-field - ) - -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1") - message(FATAL_ERROR "Insufficient gcc version. Minimum requried 5.1") - endif() - add_definitions( -Wno-unused-local-typedefs ) - add_definitions( -fmax-errors=5 ) -elseif(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) - add_definitions( -Wno-unused-local-typedef ) -endif() - -add_definitions(-fPIC) -if(COMPILER_WARNS_STRICT_ALIASING) - add_definitions( -Wno-strict-aliasing ) -endif(COMPILER_WARNS_STRICT_ALIASING) - -# Disable some harmless warnings. -CHECK_CXX_COMPILER_FLAG( "-Wno-unused-but-set-variable" - COMPILER_SUPPORT_UNUSED_BUT_SET_VARIABLE_NO_WARN - ) -if(COMPILER_SUPPORT_UNUSED_BUT_SET_VARIABLE_NO_WARN) - add_definitions( "-Wno-unused-but-set-variable" ) -endif(COMPILER_SUPPORT_UNUSED_BUT_SET_VARIABLE_NO_WARN) - -if(COMPILER_SUPPORTS_CXX14) - if(WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14") - else(WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") - endif(WIN32) - if(APPLE) - add_definitions( -mllvm -inline-threshold=1000 ) - endif(APPLE) -else(COMPILER_SUPPORTS_CXX14) - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} is too old. \n" - "Please use a compiler which has full c++14 support." - ) -endif(COMPILER_SUPPORTS_CXX14) - -set(COMPILER_IS_TESTED ON) diff --git a/MANIFEST.in b/MANIFEST.in index d71333ee95..ba89aab576 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ include AUTHORS include CMakeLists.txt include CONTRIBUTING.md -include CheckCXXCompiler.cmake include INSTALL.md include LICENSE include MANIFEST.in diff --git a/basecode/CMakeLists.txt b/basecode/CMakeLists.txt index 7b0b9484fe..77d9c8ec76 100644 --- a/basecode/CMakeLists.txt +++ b/basecode/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake ) add_library(basecode Element.cpp DataElement.cpp @@ -26,8 +25,19 @@ add_library(basecode testAsync.cpp ) +# Workaround for getopt included via unistd.h on Unices +if(WIN32) +target_include_directories(basecode PRIVATE ../extern/getopt) +target_link_libraries(basecode PRIVATE getopt) +endif() + add_executable(test_globals testGlobals.cpp global.cpp) enable_testing() add_test(NAME cpp_test_globals COMMAND $) +# DEBUG compilation process +get_target_property(compile_defs basecode COMPILE_DEFINITIONS) +message(STATUS "App compile definitions are ${compile_defs}") +# DEBUG compilation process + diff --git a/basecode/Conv.h b/basecode/Conv.h index 0baf86a498..ea9cc8b0e8 100644 --- a/basecode/Conv.h +++ b/basecode/Conv.h @@ -478,7 +478,7 @@ template<> class Conv< bool > } static void val2str( string& s, bool val ) { - if ( val > 0.5 ) + if ( val ) s = "1"; else s = "0"; diff --git a/basecode/doubleEq.h b/basecode/doubleEq.h index 458d704bf2..5fb935a09a 100644 --- a/basecode/doubleEq.h +++ b/basecode/doubleEq.h @@ -7,5 +7,5 @@ ** See the file COPYING.LIB for the full notice. **********************************************************************/ -bool doubleEq( double x, double y ); -bool doubleApprox( double x, double y ); +extern bool doubleEq( double x, double y ); +extern bool doubleApprox( double x, double y ); diff --git a/basecode/main.cpp b/basecode/main.cpp index 162f57ea16..cc2d23dd7d 100644 --- a/basecode/main.cpp +++ b/basecode/main.cpp @@ -13,7 +13,11 @@ #include #include #include +#if defined(WIN32) +#include "getopt.h" +#else #include // for getopt +#endif #include "../scheduling/Clock.h" #include "../msg/DiagonalMsg.h" #include "../msg/SparseMsg.h" diff --git a/biophysics/CMakeLists.txt b/biophysics/CMakeLists.txt index 2bd733fbbd..935d32b224 100644 --- a/biophysics/CMakeLists.txt +++ b/biophysics/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.20) -include(${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) if(WITH_GSL) find_package(GSL 1.16) diff --git a/builtins/CMakeLists.txt b/builtins/CMakeLists.txt index 4794df7d4d..f51ad61d28 100644 --- a/builtins/CMakeLists.txt +++ b/builtins/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake ) + +if(MSVC) + add_compile_options("/bigobj") +endif() + # NSDF5 support. Disabled by default. if(WITH_NSDF) @@ -48,6 +52,7 @@ if(WITH_NSDF) endif( HDF5_FOUND ) endif(WITH_NSDF) +# SocketStreamer.cpp is not portable - so adding conditionally. - Subha set(SRCS Arith.cpp Group.cpp @@ -66,10 +71,15 @@ set(SRCS Interpol2D.cpp SpikeStats.cpp MooseParser.cpp - SocketStreamer.cpp testBuiltins.cpp ) +if(NOT WIN32) + set(SRCS ${SRCS} SocketStreamer.cpp) +else() # MSVC Build system throws unresolved external symbol error + list(APPEND SRCS ../utility/cnpy.cpp) +endif() + if(WITH_NSDF AND HDF5_FOUND) list(APPEND SRCS HDF5WriterBase.cpp @@ -82,7 +92,14 @@ if(WITH_NSDF AND HDF5_FOUND) ) endif() -add_library(moose_builtins ${SRCS} ) + +add_library(moose_builtins ${SRCS}) if(WITH_NSDF AND HDF5_FOUND) target_link_libraries(moose_builtins ${HDF5_CXX_LIBRARIES} ${HDF5_HL_LIBRARIES}) endif() + +# DEBUG compilation process +get_target_property(compile_defs moose_builtins COMPILE_DEFINITIONS) +message(STATUS "App compile definitions are ${compile_defs}") +# DEBUG compilation process + diff --git a/builtins/StreamerBase.cpp b/builtins/StreamerBase.cpp index e944ce8322..324ced06a4 100644 --- a/builtins/StreamerBase.cpp +++ b/builtins/StreamerBase.cpp @@ -70,7 +70,7 @@ void StreamerBase::writeToOutFile( const string& filepath OpenMode m = (openmode == WRITE)?WRITE_BIN:APPEND_BIN; writeToNPYFile( filepath, m, data, columns ); } - else if( "csv" == outputFormat or "dat" == outputFormat ) + else if( "csv" == outputFormat || "dat" == outputFormat ) { OpenMode m = (openmode == WRITE)?WRITE_STR:APPEND_STR; writeToCSVFile( filepath, m, data, columns ); diff --git a/cmake/FindGSL.cmake b/cmake/FindGSL.cmake deleted file mode 100644 index e07c063b19..0000000000 --- a/cmake/FindGSL.cmake +++ /dev/null @@ -1,116 +0,0 @@ -# Try to find gnu scientific library GSL -# (see http://www.gnu.org/software/gsl/) -# Once run this will define: -# -# GSL_FOUND = system has GSL lib -# -# GSL_VERSION = gsl version -# -# GSL_LIBRARIES = name of the libraries. -# -# GSL_INCLUDE_DIRS = where to find headers -# -# GSL_USE_STATIC_LIBRARIES = Set it ON if you want to search for static -# libraries. -# -# Felix Woelk 07/2004 -# minor corrections Jan Woetzel -# -# www.mip.informatik.uni-kiel.de -# -------------------------------- -# -# Friday 18 November 2016 09:05:56 AM IST -# MODIFICATIONS: ## dilawars@ncbs.res.in, For the MOOSE project. -# This version does not use gsl-config file. -# - -# Set this envrionment variable to search in this path first. -SET(GSL_ROOT_DIR $ENV{GSL_ROOT_DIR}) -if(GSL_ROOT_DIR) - message( STATUS "Debug: GSL_ROOT_DIR = ${GSL_ROOT_DIR}") -endif(GSL_ROOT_DIR) - -IF(WIN32) - - SET(GSL_MINGW_PREFIX "c:/msys/local" ) - SET(GSL_MSVC_PREFIX "$ENV{LIB_DIR}") - FIND_LIBRARY(GSL_LIB gsl PATHS - ${GSL_MINGW_PREFIX}/lib - ${GSL_MSVC_PREFIX}/lib - ) - #MSVC version of the lib is just called 'cblas' - FIND_LIBRARY(GSLCBLAS_LIB gslcblas cblas PATHS - ${GSL_MINGW_PREFIX}/lib - ${GSL_MSVC_PREFIX}/lib - ) - - FIND_PATH(GSL_INCLUDE_DIRS gsl/gsl_blas.h - ${GSL_MINGW_PREFIX}/include - ${GSL_MSVC_PREFIX}/include - ) - - IF (GSL_LIB AND GSLCBLAS_LIB) - SET (GSL_LIBRARIES ${GSL_LIB} ${GSLCBLAS_LIB}) - ENDIF (GSL_LIB AND GSLCBLAS_LIB) - -ELSE(WIN32) - # UNIX - if((GSL_USE_STATIC_LIBRARIES) OR ($ENV{GSL_USE_STATIC_LIBRARIES})) - SET(GSL_LIB_NAMES libgsl.a) - SET(GSL_CBLAS_LIB_NAMES libgslcblas.a) - else() - SET(GSL_LIB_NAMES gsl) - SET(GSL_CBLAS_LIB_NAMES gslcblas) - endif( ) - - if(GSL_ROOT_DIR) - FIND_LIBRARY(GSL_LIB - NAMES ${GSL_LIB_NAMES} - PATHS ${GSL_ROOT_DIR}/lib NO_DEFAULT_PATH - ) - - FIND_LIBRARY(GSLCBLAS_LIB - NAMES ${GSL_CBLAS_LIB_NAMES} - PATHS ${GSL_ROOT_DIR}/lib NO_DEFAULT_PATH - ) - IF (GSL_LIB AND GSLCBLAS_LIB) - SET (GSL_LIBRARIES ${GSL_LIB} ${GSLCBLAS_LIB}) - ENDIF (GSL_LIB AND GSLCBLAS_LIB) - - FIND_PATH(GSL_INCLUDE_DIRS NAMES gsl/gsl_blas.h - PATHS ${GSL_ROOT_DIR}/include NO_DEFAULT_PATH - ) - else(GSL_ROOT_DIR) - FIND_LIBRARY(GSL_LIB NAMES ${GSL_LIB_NAMES} ) - FIND_LIBRARY(GSLCBLAS_LIB NAMES ${GSL_CBLAS_LIB_NAMES}) - - IF (GSL_LIB AND GSLCBLAS_LIB) - SET (GSL_LIBRARIES ${GSL_LIB} ${GSLCBLAS_LIB}) - ENDIF (GSL_LIB AND GSLCBLAS_LIB) - - FIND_PATH(GSL_INCLUDE_DIRS NAMES gsl/gsl_blas.h - PATHS ${GSL_ROOT_DIR}/include /opt/include - ) - endif( ) - -ENDIF(WIN32) - -# FIND version -# message(STATUS "Searching in ${GSL_INCLUDE_DIRS}") -if(GSL_INCLUDE_DIRS) - file(READ "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" GSL_VERSION_TEXT) - string(REGEX REPLACE ".*define[ ]+GSL_MAJOR_VERSION[ ]*([0-9]+).*" "\\1" - GSL_MAJOR_VERSION "${GSL_VERSION_TEXT}") - string(REGEX REPLACE ".*define[ ]+GSL_MINOR_VERSION[ ]*([0-9]+).*" "\\1" - GSL_MINOR_VERSION "${GSL_VERSION_TEXT}") - set(GSL_VERSION "${GSL_MAJOR_VERSION}.${GSL_MINOR_VERSION}") - message(STATUS "GSL version : ${GSL_VERSION}") -endif(GSL_INCLUDE_DIRS) - -IF(GSL_LIBRARIES AND GSL_VERSION) - IF(GSL_INCLUDE_DIRS) - MESSAGE(STATUS "Found GSL ${GSL_LIBRARIES}") - SET(GSL_FOUND 1) - ENDIF(GSL_INCLUDE_DIRS) -ENDIF() - diff --git a/device/CMakeLists.txt b/device/CMakeLists.txt index 2797c6752e..598e33fdee 100644 --- a/device/CMakeLists.txt +++ b/device/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(device PulseGen.cpp DiffAmp.cpp diff --git a/diffusion/CMakeLists.txt b/diffusion/CMakeLists.txt index e65eb97a18..c44b520b55 100644 --- a/diffusion/CMakeLists.txt +++ b/diffusion/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + if(WITH_GSL) include_directories(${GSL_INCLUDE_DIRS}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 00ede5e17c..ec60088f46 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + ADD_LIBRARY(examples Example.cpp Ex.cpp diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 9854288e33..3ea3bce6a6 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(libsoda) add_subdirectory(fmt) +add_subdirectory(getopt) diff --git a/external/getopt/CMakeLists.txt b/external/getopt/CMakeLists.txt new file mode 100644 index 0000000000..81cfeced0a --- /dev/null +++ b/external/getopt/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.20) + +add_library(getopt ${CMAKE_CURRENT_SOURCE_DIR}/getopt.c) diff --git a/external/getopt/getopt.c b/external/getopt/getopt.c new file mode 100644 index 0000000000..7868ca180d --- /dev/null +++ b/external/getopt/getopt.c @@ -0,0 +1,52 @@ +/* ***************************************************************** +* +* Copyright 2016 Microsoft +* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************/ + +#include "getopt.h" +#include + +char* optarg = NULL; +int optind = 1; + +int getopt(int argc, char *const argv[], const char *optstring) +{ + if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0)) + { + return -1; + } + + int opt = argv[optind][1]; + const char *p = strchr(optstring, opt); + + if (p == NULL) + { + return '?'; + } + if (p[1] == ':') + { + optind++; + if (optind >= argc) + { + return '?'; + } + optarg = argv[optind]; + optind++; + } + return opt; +} + diff --git a/external/getopt/getopt.h b/external/getopt/getopt.h new file mode 100644 index 0000000000..a48f5adf66 --- /dev/null +++ b/external/getopt/getopt.h @@ -0,0 +1,37 @@ +/* ***************************************************************** +* +* Copyright 2016 Microsoft +* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************/ + +#ifndef GETOPT_H__ +#define GETOPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +extern char *optarg; +extern int optind; + +int getopt(int argc, char *const argv[], const char *optstring); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/external/getopt/unistd.h b/external/getopt/unistd.h new file mode 100644 index 0000000000..8cf3b10ee5 --- /dev/null +++ b/external/getopt/unistd.h @@ -0,0 +1,56 @@ +#ifndef _UNISTD_H +#define _UNISTD_H 1 + +/* This is intended as a drop-in replacement for unistd.h on Windows. + * Please add functionality as neeeded. + * https://stackoverflow.com/a/826027/1202830 + */ + +#include +#include +#include "getopt.h" /* getopt at: https://gist.github.com/ashelly/7776712 */ +#include /* for getpid() and the exec..() family */ +#include /* for _getcwd() and _chdir() */ + +#define srandom srand +#define random rand + +/* Values for the second argument to access. + These may be OR'd together. */ +#define R_OK 4 /* Test for read permission. */ +#define W_OK 2 /* Test for write permission. */ +//#define X_OK 1 /* execute permission - unsupported in windows*/ +#define F_OK 0 /* Test for existence. */ + +#define access _access +#define dup2 _dup2 +#define execve _execve +#define ftruncate _chsize +#define unlink _unlink +#define fileno _fileno +#define getcwd _getcwd +#define chdir _chdir +#define isatty _isatty +#define lseek _lseek +/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ + +#ifdef _WIN64 +#define ssize_t __int64 +#else +#define ssize_t long +#endif + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +/* should be in some equivalent to */ +//typedef __int8 int8_t; +//typedef __int16 int16_t; +//typedef __int32 int32_t; +//typedef __int64 int64_t; +//typedef unsigned __int8 uint8_t; +//typedef unsigned __int16 uint16_t; +//typedef unsigned __int32 uint32_t; +//typedef unsigned __int64 uint64_t; + +#endif /* unistd.h */ \ No newline at end of file diff --git a/hsolve/CMakeLists.txt b/hsolve/CMakeLists.txt index 1a463e95c8..d8a7e78dc1 100644 --- a/hsolve/CMakeLists.txt +++ b/hsolve/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(hsolve HSolveStruct.cpp HinesMatrix.cpp diff --git a/intfire/CMakeLists.txt b/intfire/CMakeLists.txt index a712c1e28f..64e3e33e00 100644 --- a/intfire/CMakeLists.txt +++ b/intfire/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + file(GLOB SRC *.cpp) add_library(intfire ${SRC}) diff --git a/kinetics/CMakeLists.txt b/kinetics/CMakeLists.txt index 714d2a5826..222ca114c7 100644 --- a/kinetics/CMakeLists.txt +++ b/kinetics/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(kinetics PoolBase.cpp Reac.cpp diff --git a/kinetics/WriteKkit.cpp b/kinetics/WriteKkit.cpp index 2c061561c1..d24baf9c09 100644 --- a/kinetics/WriteKkit.cpp +++ b/kinetics/WriteKkit.cpp @@ -147,7 +147,7 @@ void writeEnz( ofstream& fout, Id id, double vol = Field< double >::get( enzMol, "volume" ) * NA * 1e-3; unsigned int isMichaelisMenten = 0; string enzClass = Field < string > :: get(id,"className"); - if (enzClass == "ZombieMMenz" or enzClass == "MMenz") + if (enzClass == "ZombieMMenz" || enzClass == "MMenz") { k1 = Field < double > :: get (id,"numKm"); k3 = Field < double > :: get (id,"kcat"); @@ -155,7 +155,7 @@ void writeEnz( ofstream& fout, Id id, k1 = (k2 + k3) / k1; isMichaelisMenten = 1; } - else if (enzClass == "ZombieEnz" or enzClass == "Enz") + else if (enzClass == "ZombieEnz" || enzClass == "Enz") { k1 = Field< double >::get( id, "k1" ); k2 = Field< double >::get( id, "k2" ); @@ -248,7 +248,7 @@ void writePool( ofstream& fout, Id id, string geometry; stringstream geometryTemp ; unsigned int slave_enable = 0; - if (pooltype == "BufPool" or pooltype == "ZombieBufPool") + if (pooltype == "BufPool" || pooltype == "ZombieBufPool") { vector< Id > children = Field< vector< Id > >::get( id, "children" ); if (children.size() == 0) @@ -257,7 +257,7 @@ void writePool( ofstream& fout, Id id, { string funcpath = Field :: get(*i,"path"); string clsname = Field :: get(*i,"className"); - if (clsname == "Function" or clsname == "ZombieFunction") + if (clsname == "Function" || clsname == "ZombieFunction") slave_enable = 0; else slave_enable = 4; @@ -379,7 +379,7 @@ void storeCplxEnzMsgs( Id enz, vector< string >& msgs, Id comptid ) void storeEnzMsgs( Id enz, vector< string >& msgs, Id comptid ) { string enzClass = Field < string > :: get(enz,"className"); - if (enzClass == "ZombieMMenz" or enzClass == "MMenz") + if (enzClass == "ZombieMMenz" || enzClass == "MMenz") storeMMenzMsgs(enz, msgs, comptid); else storeCplxEnzMsgs( enz, msgs, comptid ); @@ -585,7 +585,7 @@ void writeKkit( Id model, const string& fname ) string path = Field :: get (*itrp,"path"); Id enzPoolparent = Field :: get(*itrp,"parent"); string enzpoolClass = Field :: get(enzPoolparent,"className"); - if (enzpoolClass != "ZombieEnz" or enzpoolClass != "Enz") + if (enzpoolClass != "ZombieEnz" || enzpoolClass != "Enz") { Id annotaId( path+"/info"); if ( annotaId != Id() ) diff --git a/ksolve/CMakeLists.txt b/ksolve/CMakeLists.txt index 35809ad362..216415a168 100644 --- a/ksolve/CMakeLists.txt +++ b/ksolve/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(CheckIncludeFileCXX) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + if(WITH_BOOST) find_package(Boost 1.53 REQUIRED COMPONENTS thread) diff --git a/ksolve/SteadyStateGsl.cpp b/ksolve/SteadyStateGsl.cpp index 7fc2332ffe..872865d895 100644 --- a/ksolve/SteadyStateGsl.cpp +++ b/ksolve/SteadyStateGsl.cpp @@ -525,7 +525,7 @@ void SteadyState::assignY( double* S ) void print_gsl_mat( gsl_matrix* m, const char* name ) { size_t i, j; - printf( "%s[%lu, %lu] = \n", name, m->size1, m->size2 ); + printf( "%s[%zu, %zu] = \n", name, m->size1, m->size2 ); for (i = 0; i < m->size1; i++) { for (j = 0; j < m->size2; j++) diff --git a/ksolve/Stoich.cpp b/ksolve/Stoich.cpp index 00ebd1ebd4..ae6b5bad90 100644 --- a/ksolve/Stoich.cpp +++ b/ksolve/Stoich.cpp @@ -425,7 +425,7 @@ void Stoich::setDsolve(Id dsolve) { dsolve_ = Id(); dinterface_ = 0; - if(not(dsolve.element()->cinfo()->isA("Dsolve"))) { + if(!(dsolve.element()->cinfo()->isA("Dsolve"))) { cout << "Error: Stoich::setDsolve: invalid class assigned," " should be Dsolve\n"; return; diff --git a/mesh/CMakeLists.txt b/mesh/CMakeLists.txt index be1359e624..0e95a7918a 100644 --- a/mesh/CMakeLists.txt +++ b/mesh/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(mesh ChemCompt.cpp MeshCompt.cpp diff --git a/mesh/CylBase.cpp b/mesh/CylBase.cpp index 209977db25..4acddd3a4d 100644 --- a/mesh/CylBase.cpp +++ b/mesh/CylBase.cpp @@ -18,7 +18,7 @@ #include "CylBase.h" #include "../utility/Vec.h" -extern const double PI; // defined in consts.cpp +// extern const double PI; // defined in consts.cpp CylBase::CylBase( double x, double y, double z, double dia, double length, unsigned int numDivs ) @@ -132,10 +132,10 @@ bool CylBase::getIsCylinder() const double CylBase::volume( const CylBase& parent ) const { if ( isCylinder_ ) - return length_ * dia_ * dia_ * PI / 4.0; + return length_ * dia_ * dia_ * M_PI / 4.0; double r0 = parent.dia_/2.0; double r1 = dia_/2.0; - return length_ * ( r0*r0 + r0 *r1 + r1 * r1 ) * PI / 3.0; + return length_ * ( r0*r0 + r0 *r1 + r1 * r1 ) * M_PI / 3.0; } /** @@ -150,7 +150,7 @@ double CylBase::voxelVolume( const CylBase& parent, unsigned int fid ) const { assert( numDivs_ > fid ); if ( isCylinder_ ) - return length_ * dia_ * dia_ * PI / ( 4.0 * numDivs_ ); + return length_ * dia_ * dia_ * M_PI / ( 4.0 * numDivs_ ); double frac0 = ( static_cast< double >( fid ) ) / static_cast< double >( numDivs_ ); @@ -161,7 +161,7 @@ double CylBase::voxelVolume( const CylBase& parent, unsigned int fid ) const double s0 = length_ * frac0; double s1 = length_ * frac1; - return (s1 - s0) * ( r0*r0 + r0 *r1 + r1 * r1 ) * PI / 3.0; + return (s1 - s0) * ( r0*r0 + r0 *r1 + r1 * r1 ) * M_PI / 3.0; } /// Virtual function to return coords of mesh Entry. @@ -209,11 +209,11 @@ double CylBase::getDiffusionArea( { assert( fid < numDivs_ + 1 ); if ( isCylinder_ ) - return PI * dia_ * dia_ / 4.0; + return M_PI * dia_ * dia_ / 4.0; double frac0 = ( static_cast< double >( fid ) ) / static_cast< double >( numDivs_ ); double r0 = 0.5 * ( parent.dia_ * ( 1.0 - frac0 ) + dia_ * frac0 ); - return PI * r0 * r0; + return M_PI * r0 * r0; } /// Return the cross section area of the middle of the specified voxel. @@ -222,11 +222,11 @@ double CylBase::getMiddleArea( { assert( fid < numDivs_ ); if ( isCylinder_ ) - return PI * dia_ * dia_ / 4.0; + return M_PI * dia_ * dia_ / 4.0; double frac0 = ( 0.5 + static_cast< double >( fid ) ) / static_cast< double >( numDivs_ ); double r0 = 0.5 * ( parent.dia_ * ( 1.0 - frac0 ) + dia_ * frac0 ); - return PI * r0 * r0; + return M_PI * r0 * r0; } double CylBase::getVoxelLength() const @@ -267,9 +267,9 @@ static void fillPointsOnCircle( // This will cause small errors in area estimate but they will // be anisotropic. The alternative will have large errors toward // 360 degrees, but not elsewhere. - unsigned int numAngle = floor( 2.0 * PI * r / h + 0.5 ); + unsigned int numAngle = floor( 2.0 * M_PI * r / h + 0.5 ); assert( numAngle > 0 ); - double dtheta = 2.0 * PI / numAngle; + double dtheta = 2.0 * M_PI / numAngle; double dArea = h * dtheta * r; // March along points on surface of circle centred at q. for ( unsigned int j = 0; j < numAngle; ++j ) { @@ -295,10 +295,10 @@ static void fillPointsOnDisc( double dRadial = r / numRadial; for ( unsigned int i = 0; i < numRadial; ++i ) { double a = ( i + 0.5 ) * dRadial; - unsigned int numAngle = floor( 2.0 * PI * a / h + 0.5 ); + unsigned int numAngle = floor( 2.0 * M_PI * a / h + 0.5 ); if ( i == 0 ) numAngle = 1; - double dtheta = 2.0 * PI / numAngle; + double dtheta = 2.0 * M_PI / numAngle; double dArea = dRadial * dtheta * a; for ( unsigned int j = 0; j < numAngle; ++j ) { double theta = j * dtheta; diff --git a/mpi/CMakeLists.txt b/mpi/CMakeLists.txt index d7fd2a9103..a92b44e202 100644 --- a/mpi/CMakeLists.txt +++ b/mpi/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + IF(USE_MPI) find_package(MPI REQUIRED) include_directories(MPI_INCLUDE_PATH) diff --git a/msg/CMakeLists.txt b/msg/CMakeLists.txt index edf1592938..e715551e92 100644 --- a/msg/CMakeLists.txt +++ b/msg/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(msg Msg.cpp DiagonalMsg.cpp diff --git a/pybind11/CMakeLists.txt b/pybind11/CMakeLists.txt index c8fa0405b6..1f99586f65 100644 --- a/pybind11/CMakeLists.txt +++ b/pybind11/CMakeLists.txt @@ -1,50 +1,58 @@ # Add pybind11 module. -execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version - OUTPUT_VARIABLE COMPILER_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE) +# execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version +# OUTPUT_VARIABLE COMPILER_STRING +# OUTPUT_STRIP_TRAILING_WHITESPACE) -pybind11_add_module(_moose +pybind11_add_module(moose pymoose.cpp helper.cpp Finfo.cpp MooseVec.cpp PyRun.cpp) -add_dependencies(_moose libmoose) +add_dependencies(moose libmoose) # Use in version_info dict. -target_compile_definitions(_moose PRIVATE +target_compile_definitions(moose PRIVATE COMPILER_STRING="${CMAKE_CXX_COMPILER_ID},${CMAKE_CXX_COMPILER},${CMAKE_CXX_COMPILER_VERSION}") -set_target_properties(_moose PROPERTIES +if(WIN32) +set_target_properties(moose PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/python/moose - PREFIX "" + PREFIX "_" + SUFFIX ".pyd") +else() +set_target_properties(moose PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/python/moose + PREFIX "_" SUFFIX ".so") +endif() if(APPLE) set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup") message(STATUS "ADDING some linker flags ${CMAKE_EXE_LINKER_FLAGS}") # cmake --help-policy CMP0042 - set_target_properties(_moose PROPERTIES MACOSX_RPATH OFF) -endif(APPLE) - -if(APPLE) - # OSX - target_link_libraries(_moose PRIVATE + set_target_properties(moose PROPERTIES MACOSX_RPATH OFF) + target_link_libraries(moose PRIVATE "-Wl,-all_load" ${MOOSE_LIBRARIES} ${STATIC_LIBRARIES}) - target_link_libraries(_moose PRIVATE ${SYSTEM_SHARED_LIBS}) -else(APPLE) + target_link_libraries(moose PRIVATE ${SYSTEM_SHARED_LIBS}) +elseif(MSVC) + target_link_libraries(moose PRIVATE + ${MOOSE_LIBRARIES} + ${STATIC_LIBRARIES} + ${SYSTEM_SHARED_LIBS}) +else(MSVC) # Linux - target_link_libraries(_moose PRIVATE + target_link_libraries(moose PRIVATE "-Wl,--whole-archive" ${MOOSE_LIBRARIES} ${STATIC_LIBRARIES} "-Wl,--no-whole-archive" ${SYSTEM_SHARED_LIBS}) -endif() +endif(APPLE) # Copy python tree to BUILD directory. User can set PYTHONPATH to @@ -55,28 +63,36 @@ add_custom_target(copy_python_tree ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/python/ ${PYMOOSE_BUILD_DIR} COMMENT "pybind11: Copying Python src ${CMAKE_SOURCE_DIR}/python → ${PYMOOSE_BUILD_DIR}" - DEPENDS _moose + DEPENDS moose VERBATIM) # Create a binary distribution inside a directory. Installation will copy that # directory. -set(_platform "CMAKE") -set(PYMOOSE_BDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.${_platform}.tar.gz) +# set(_platform "CMAKE") +if(WIN32) + set(ARCHIVE_EXT zip) + set(ARCHIVE_CMD unzip) +else(WIN32) + set(ARCHIVE_EXT tar.gz) + set(ARCHIVE_CMD tar xf) +endif() + +set(PYMOOSE_BDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.${PLATFORM}.${ARCHIVE_EXT}) set(PYMOOSE_INSTALL_DIR ${CMAKE_BINARY_DIR}/_pymoose_temp_install) file(MAKE_DIRECTORY ${PYMOOSE_INSTALL_DIR}) add_custom_command(OUTPUT ${PYMOOSE_BDIST_FILE} COMMAND ${PYTHON_EXECUTABLE} setup.py build_py COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_dumb - --skip-build -p "${_platform}" -d ${CMAKE_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_INSTALL_DIR} tar xf ${PYMOOSE_BDIST_FILE} + --skip-build -p "${PLATFORM}" -d ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_INSTALL_DIR} ${ARCHIVE_CMD} ${PYMOOSE_BDIST_FILE} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "python's binary distribution is saved to ${CMAKE_BINARY_DIR}" VERBATIM) add_custom_target(pymoose_sdist ALL - DEPENDS ${PYMOOSE_BDIST_FILE} _moose + DEPENDS ${PYMOOSE_BDIST_FILE} moose COMMENT "Building pymoose source distribution.") install(DIRECTORY ${PYMOOSE_INSTALL_DIR}/usr/local/ diff --git a/pybind11/Finfo.cpp b/pybind11/Finfo.cpp index 4d24179964..e4d8ddc559 100644 --- a/pybind11/Finfo.cpp +++ b/pybind11/Finfo.cpp @@ -270,7 +270,7 @@ py::object __Finfo__::getFieldValue(const ObjId& oid, const Finfo* f) auto fname = f->name(); py::object r = py::none(); - if(rttType == "double" or rttType == "float") + if(rttType == "double" || rttType == "float") r = pybind11::float_(getField(oid, fname)); else if(rttType == "vector") { r = getFieldNumpy(oid, fname); diff --git a/pybind11/MooseVec.cpp b/pybind11/MooseVec.cpp index 19fbd78730..d205fc4526 100644 --- a/pybind11/MooseVec.cpp +++ b/pybind11/MooseVec.cpp @@ -182,7 +182,7 @@ bool MooseVec::setAttribute(const string& name, const py::object& val) auto rttType = finfo->rttiType(); bool isVector = false; - if(py::isinstance(val) and(not py::isinstance(val))) + if(py::isinstance(val) && (! py::isinstance(val))) isVector = true; if(isVector) { diff --git a/pybind11/PyRun.cpp b/pybind11/PyRun.cpp index e5aeca8639..50fdcf70ad 100644 --- a/pybind11/PyRun.cpp +++ b/pybind11/PyRun.cpp @@ -5,7 +5,15 @@ // Author: subha // Created: Sat Oct 11 14:47:22 2014 (+0530) +// avoid linker error on Win32 - tries to link against python311_d.lib +#ifdef _DEBUG +#undef _DEBUG #include "Python.h" +#define _DEBUG +#else +#include +#endif + #include "../basecode/header.h" #include "PyRun.h" diff --git a/pybind11/PyRun.h b/pybind11/PyRun.h index 601e2e1e7d..38e6b9c895 100644 --- a/pybind11/PyRun.h +++ b/pybind11/PyRun.h @@ -8,6 +8,10 @@ #include +#if defined(_WIN32) +#define PATH_MAX 260 // this is win32 path limit +#endif + #if PY_MAJOR_VERSION >= 3 #define PYCODEOBJECT PyObject diff --git a/pybind11/helper.cpp b/pybind11/helper.cpp index f22c01061c..0b8d855c8e 100644 --- a/pybind11/helper.cpp +++ b/pybind11/helper.cpp @@ -359,11 +359,16 @@ void mooseReinit() /* ----------------------------------------------------------------------------*/ void mooseStart(double runtime, bool notify = false) { + // TODO: handle keyboard interrupt on _WIN32 +#if !defined(_WIN32) + // Credit: + // http://stackoverflow.com/questions/1641182/how-can-i-catch-a-ctrl-c-event-c struct sigaction sigHandler; sigHandler.sa_handler = handleKeyboardInterrupts; sigemptyset(&sigHandler.sa_mask); sigHandler.sa_flags = 0; sigaction(SIGINT, &sigHandler, NULL); +#endif getShellPtr()->doStart(runtime, notify); } diff --git a/pybind11/helper.h b/pybind11/helper.h index 72ebf4a1f3..fbaac7205d 100644 --- a/pybind11/helper.h +++ b/pybind11/helper.h @@ -123,7 +123,7 @@ inline ObjId mooseCreateFromPath(const string type, const string& p, // If path exists and user is asking for the same type then return the // underlying object else raise an exception. auto oid = ObjId(path); - if(not oid.bad()) { + if(! oid.bad()) { if(oid.element()->cinfo()->name() == type) return oid; else diff --git a/pymoose/CMakeLists.txt b/pymoose/CMakeLists.txt index 6f5da2b32a..a650a445f9 100644 --- a/pymoose/CMakeLists.txt +++ b/pymoose/CMakeLists.txt @@ -1,23 +1,27 @@ -include(${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) - set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/") -execute_process(COMMAND - ${PYTHON_EXECUTABLE} -c "import numpy;print(numpy.get_include())" - OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE) - -if("${NUMPY_INCLUDE_DIRS}" STREQUAL "") - message(FATAL_ERROR "Could not find numpy: ${NUMPY_INCLUDE_DIRS}") -else() - message(STATUS "Numpy is found at ${NUMPY_INCLUDE_DIRS}") -endif() +# execute_process(COMMAND +# ${PYTHON_EXECUTABLE} -c "import numpy;print(numpy.get_include())" +# OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS +# OUTPUT_STRIP_TRAILING_WHITESPACE) +# if("${NUMPY_INCLUDE_DIRS}" STREQUAL "") +# message(FATAL_ERROR "Could not find numpy: ${NUMPY_INCLUDE_DIRS}") +# else() +# message(STATUS "Numpy is found at ${NUMPY_INCLUDE_DIRS}") +# endif() include_directories(${NUMPY_INCLUDE_DIRS}) add_definitions(-std=c++14) add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) -set(PYTHON_SO_EXTENSION ".so") + +if(WIN32) +# DLL extension does not work when importing module on Win32 + set(PYTHON_SO_EXTENSION ".pyd") +else() + set(PYTHON_SO_EXTENSION ".so") +endif() + message(STATUS "Python so extension ${PYTHON_SO_EXTENSION}" ) # TARGET @@ -37,25 +41,11 @@ add_library( _moose MODULE ${PYMOOSE_SRCS} ) set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../python/moose") message(STATUS "Python module will be saved to ${PYMOOSE_OUTPUT_DIRECTORY}" ) -# make sure the Python.h is found. -# Use python executable to find include paths. -# FIXME: cmake > 3.12 has great support for python but it is not available -# everywhere YET. When it is available on centos, we can use FindPython. -message(STATUS "Using ${PYTHON_EXECUTABLE}-config to find Python.h" ) -execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --includes - OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS - OUTPUT_STRIP_TRAILING_WHITESPACE) - -if("${PYTHON_INCLUDE_FLAGS}" STREQUAL "") - message(FATAL_ERROR "Could not determine path of Python.h.") -else() - message(STATUS "Python.h is found at ${PYTHON_INCLUDE_FLAGS}") -endif() - -execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --libs - OUTPUT_VARIABLE PYTHON_LIBRARIES - OUTPUT_STRIP_TRAILING_WHITESPACE) - +find_package (Python COMPONENTS Interpreter Development Numpy) +target_compile_options(_moose_compiler_flags INTERFACE + "$<${gcc_like_cxx}:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>" + "$<${msvc_cxx}:-W3>" +) set_target_properties(_moose PROPERTIES COMPILE_DEFINITIONS "PYMOOSE" COMPILE_FLAGS "${COMPILE_FLAGS} ${PYTHON_INCLUDE_FLAGS}") @@ -105,11 +95,16 @@ endif() # message(STATUS "Python module wheel is not found. Please wait while I install it..") # execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install wheel --user) #endif(NOT PY_WHEEL) - + + # Create a binary distribution inside a directory. Installation is copying that # directory to ${CMAKE_INSTALL_PREFIX} -set(_platform "CMAKE") -set(PYMOOSE_BDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.${_platform}.tar.gz) +#set(_platform "CMAKE") +if(WIN32) + set(PYMOOSE_BDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.${PLATFORM}.zip) +else() + set(PYMOOSE_BDIST_FILE ${CMAKE_BINARY_DIR}/pymoose-${VERSION_MOOSE}.${PLATFORM}.tar.gz) +endif() set(PYMOOSE_INSTALL_DIR ${CMAKE_BINARY_DIR}/_pymoose_temp_install) file(MAKE_DIRECTORY ${PYMOOSE_INSTALL_DIR}) @@ -121,7 +116,7 @@ add_custom_command(OUTPUT ${PYMOOSE_BDIST_FILE} COMMAND ${PYTHON_EXECUTABLE} setup.py build_py COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_dumb --skip-build -p "${_platform}" -d ${CMAKE_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_INSTALL_DIR} tar xf ${PYMOOSE_BDIST_FILE} + COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_INSTALL_DIR} ${ZIP_CMD} ${PYMOOSE_BDIST_FILE} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "python's binary distribution is saved to ${CMAKE_BINARY_DIR}" VERBATIM) diff --git a/scheduling/CMakeLists.txt b/scheduling/CMakeLists.txt index a4cf3fc654..c8f7c6c225 100644 --- a/scheduling/CMakeLists.txt +++ b/scheduling/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.20) -include(${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(scheduling Clock.cpp testScheduling.cpp) diff --git a/setup.py b/setup.py index e680a6ebb4..0642670f98 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ import multiprocessing import subprocess import datetime +import platform try: cmakeVersion = subprocess.call(["cmake", "--version"], stdout=subprocess.PIPE) @@ -34,7 +35,7 @@ # Global variables. sdir_ = os.path.dirname(os.path.realpath(__file__)) -stamp = datetime.datetime.now().strftime('%Y%m%d') +tstamp = datetime.datetime.now().strftime('%Y%m%d') builddir_ = os.path.join(sdir_, '_temp__build') if not os.path.exists(builddir_): @@ -43,7 +44,8 @@ numCores_ = multiprocessing.cpu_count() -version_ = '4.1.0.dev%s' % stamp +version_ = f'4.1.0.dev{tstamp}' +# version_ = '4.1.0.dev' # importlib is available only for python3. Since we build wheels, prefer .so # extension. This way a wheel built by any python3.x will work with any python3. @@ -86,9 +88,15 @@ def initialize_options(self): self.with_boost = 0 self.with_gsl = 1 self.with_gsl_static = 0 - self.debug = 0 + self.debug = None self.no_build = 0 - self.cmake_options = {} + if platform.system() == 'Windows': + # TODO: match build instructions + # vcpkg provides gsl, hdf5 etc dev libs + # MSVC by default puts output in Release or Debug folder + self.cmake_options = {'CMAKE_TOOLCHAIN_FILE': r'..\vcpkg\scripts\buildsystems\vcpkg.cmake'} + else: + self.cmake_options = {} # super().initialize_options() build_ext.initialize_options(self) @@ -98,17 +106,20 @@ def finalize_options(self): build_ext.finalize_options(self) self.cmake_options['PYTHON_EXECUTABLE'] = os.path.realpath(sys.executable) self.cmake_options['VERSION_MOOSE'] = version_ + self.cmake_options['PLATFORM'] = f'{platform.system()[:3].lower()}-{platform.machine().lower()}' + if self.with_boost: self.cmake_options['WITH_BOOST'] = 'ON' self.cmake_options['WITH_GSL'] = 'OFF' else: if self.with_gsl_static: self.cmake_options['GSL_USE_STATIC_LIBRARIES'] = 'ON' - if self.debug: - self.cmake_options['CMAKE_BUILD_TYPE'] = 'Debug' + if self.debug is not None: + self.cmake_options['CMAKE_BUILD_TYPE'] = 'Debug' else: + self.debug = 0 self.cmake_options['CMAKE_BUILD_TYPE'] = 'Release' - + def run(self): if self.no_build: return @@ -124,11 +135,16 @@ def build_cmake(self, ext): print("[INFO ] Building pymoose in %s ..." % builddir_) cmake_args = [] for k, v in self.cmake_options.items(): - cmake_args.append('-D%s=%s' % (k, v)) + cmake_args.append(f'-D{k}={v}') os.chdir(str(builddir_)) self.spawn(['cmake', str(sdir_)] + cmake_args) - if not self.dry_run: - self.spawn(['make', '-j%d' % numCores_]) + if not self.dry_run and platform.system() != 'Windows': + self.spawn(['make', f'-j{numCores_:d}']) + else: + cmd = ['cmake', '--build', '.'] + if not self.debug: + cmd += ['--config', self.cmake_options['CMAKE_BUILD_TYPE']] + self.spawn(cmd) os.chdir(str(sdir_)) @@ -167,8 +183,9 @@ def build_cmake(self, ext): os.path.join('chemUtil', 'rainbow2.pkl'), ] }, - install_requires=['numpy', 'matplotlib', 'vpython', 'pybind11'], - extra_require={'dev': ['coverage', 'pytest', 'pytest-cov']}, + build_requires=['numpy', 'pybind11[global]'], + install_requires=['numpy', 'matplotlib', 'vpython', 'pybind11[global]'], + extras_require={'dev': ['coverage', 'pytest', 'pytest-cov']}, ext_modules=[CMakeExtension('_moose', optional=True)], cmdclass={'build_ext': cmake_build_ext, 'test': TestCommand}, ) diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index e3a6a9af86..757216d74b 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) if(LIBSBML_FOUND) add_definitions(-DUSE_SBML) diff --git a/shell/Shell.cpp b/shell/Shell.cpp index b26a0a7ffd..4440ab5782 100644 --- a/shell/Shell.cpp +++ b/shell/Shell.cpp @@ -21,7 +21,9 @@ #include "../msg/OneToOneMsg.h" #include "../msg/OneToAllMsg.h" #include "../msg/SparseMsg.h" +#if !defined(WIN32) #include "../builtins/SocketStreamer.h" +#endif #include "../builtins/Streamer.h" #include "Shell.h" diff --git a/signeur/CMakeLists.txt b/signeur/CMakeLists.txt index 246c298ca7..efca2ca0b4 100644 --- a/signeur/CMakeLists.txt +++ b/signeur/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + add_library(signeur Adaptor.cpp testSigNeur.cpp diff --git a/synapse/CMakeLists.txt b/synapse/CMakeLists.txt index 8701400a4e..73b350bd11 100644 --- a/synapse/CMakeLists.txt +++ b/synapse/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) + set( SYNAPSE_SRCS GraupnerBrunel2012CaPlasticitySynHandler.cpp diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 6f55e6da1d..8f4f2dacf3 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.20) -include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake) add_library(utility strutil.cpp @@ -9,11 +8,16 @@ add_library(utility Annotator.cpp Vec.cpp cnpy.cpp - fileutils.cpp - utility.cpp + # fileutils.cpp + # utility.cpp ) target_link_libraries(utility PRIVATE fmt) +# DEBUG compilation process +get_target_property(compile_defs utility COMPILE_DEFINITIONS) +message(STATUS "App compile definitions are $compile_defs") +# DEBUG compilation process + add_executable(test_cnpy test_cnpy.cpp) target_link_libraries(test_cnpy utility) @@ -29,3 +33,5 @@ target_link_libraries(test_util utility) enable_testing() add_test(NAME cpp_test_util COMMAND $) + + diff --git a/utility/cnpy.cpp b/utility/cnpy.cpp index 05fea0a385..a1bd33eb6f 100644 --- a/utility/cnpy.cpp +++ b/utility/cnpy.cpp @@ -79,24 +79,22 @@ string shapeToString(const vector& shape) * * @return true if file is sane, else false. */ -bool isValidNumpyFile( FILE* fp ) +bool isValidNumpyFile(string npy_file) { - assert( fp ); - char buffer[__pre__.size()]; - size_t nr = fread( buffer, sizeof(char), __pre__.size(), fp ); - - if( 0 == nr ) - return false; - - bool equal = true; - // Check for equality - for(size_t i = 0; i < __pre__.size(); i++ ) - if( buffer[i] != __pre__[i] ) - { - equal = false; - break; - } - return equal; + char c; + istream_iterator istream_iterator; + ifstream file(npy_file); + for(auto ¤t : __pre__) + { + file.get(c); + if((c != current) || (c == EOF)) + { + file.close(); + return false; + } + } + file.close(); + return true; } /** diff --git a/utility/print_function.hpp b/utility/print_function.hpp index 761009616e..02ed8536e5 100644 --- a/utility/print_function.hpp +++ b/utility/print_function.hpp @@ -192,7 +192,7 @@ namespace moose { { if('`' == msg[i]) { - if(!set and reset) + if(!set && reset) { set = true; reset = false;