Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 64 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
include(CheckCXXCompiler.cmake)
include(CheckIncludeFileCXX)

if(UNIX)
add_definitions(-DUNIX)
else()
add_definitions(-DNOT_UNIX)
endif()

# getgit revision number
find_program( GIT_EXEC git )
if(GIT_EXEC)
Expand All @@ -18,16 +24,18 @@ else(GIT_EXEC)
message(STATUS "Couldn't fetch version from git repo" )
endif()


# If from command line, version info is not passed, use the git to generate a
# version file. If GIT fails, use the previous known version.
if(NOT VERSION_MOOSE)
set(VERSION_MOOSE "3.2.0-${GIT_HEAD}")
string(TIMESTAMP TODAY "%Y%m%d")
set(VERSION_MOOSE "3.2.dev${TODAY}")
endif()

add_definitions( -DMOOSE_VERSION="${VERSION_MOOSE}")
message( STATUS "MOOSE Version ${VERSION_MOOSE}" )

# Write VERSION to a file VERSION so that setup.cmake.py can use it.
# Write VERSION to a file VERSION so that setup.py can use it.
set(VERSION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/python/VERSION)
file(WRITE ${VERSION_FILE} ${VERSION_MOOSE} )
message(STATUS "| Writing ${VERSION_MOOSE} to ${VERSION_FILE}" )
Expand Down Expand Up @@ -265,11 +273,13 @@ add_subdirectory(synapse)
add_subdirectory(intfire)

###################################### LINKING #################################
# WARN: If library A depends on library B, then library A must appear before
# library B in the following list.
list(APPEND MOOSE_LIBRARIES
moose_builtins
msg
benchmarks
shell
moose_builtins
msg
randnum
scheduling
moose_mpi
Expand Down Expand Up @@ -326,10 +336,8 @@ else(APPLE)
endif(APPLE)

add_dependencies(moose.bin libmoose)
target_link_libraries(moose.bin moose ${CMAKE_DL_LIBS})
if( WITH_BOOST )
target_link_libraries( moose.bin ${Boost_LIBRARIES} )
endif( WITH_BOOST )
target_link_libraries(moose.bin ${MOOSE_LIBRARIES} ${STATIC_LIBRARIES} ${CMAKE_DL_LIBS})
target_link_libraries(moose.bin ${SYSTEM_SHARED_LIBS} )


######################### BUILD PYMOOSE ########################################
Expand Down Expand Up @@ -361,49 +369,58 @@ endif()
# Target for creating bdist. This is handy for creating bdist for packaging.
# Save the binary distribution (tar.gz) to PYMOOSE_BDIST_DIR.
find_package(PythonInterp REQUIRED)
if(NOT PYMOOSE_BDIST_DIR)
set(PYMOOSE_BDIST_DIR ${CMAKE_BINARY_DIR}/bdist)
endif( )

# If no one hsa set the PYMOOSE bdist installation directory, use default.
if(NOT PYMOOSE_BDIST_INSTALL_DIR)
set(PYMOOSE_BDIST_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/pymoose_bdist_install)
endif()
file(MAKE_DIRECTORY ${PYMOOSE_BDIST_INSTALL_DIR})

# We need a custom name for bdist; same on all platform.
set(_platform "CMAKE" )
set(PYMOOSE_BDIST_FILE ${PYMOOSE_BDIST_DIR}/pymoose-${VERSION_MOOSE}.${_platform}.tar.gz)
message(STATUS "binary distribution file ${PYMOOSE_BDIST_FILE}")
add_custom_target(bdist ALL DEPENDS ${PYMOOSE_BDIST_FILE} )

# Any command using setup.cmake.py must run in the same directory. Use option
# `--relative` to prefix is aways fixed.
add_custom_command( OUTPUT ${PYMOOSE_BDIST_FILE}
COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py bdist_dumb -p ${_platform}
if(UNIX)

if(NOT PYMOOSE_BDIST_DIR)
set(PYMOOSE_BDIST_DIR ${CMAKE_CURRENT_BINARY_DIR}/bdist)
endif( )

# If no one hsa set the PYMOOSE bdist installation directory, use default.
if(NOT PYMOOSE_BDIST_INSTALL_DIR)
set(PYMOOSE_BDIST_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/pymoose_bdist_install)
endif()
file(MAKE_DIRECTORY ${PYMOOSE_BDIST_INSTALL_DIR})

# We need a custom name for bdist; same on all platform.
set(_platform "CMAKE" )
set(PYMOOSE_BDIST_FILE ${PYMOOSE_BDIST_DIR}/pymoose-${VERSION_MOOSE}.${_platform}.tar.gz)
message(STATUS "binary distribution file ${PYMOOSE_BDIST_FILE}")
add_custom_target(bdist ALL DEPENDS ${PYMOOSE_BDIST_FILE} )

# Any command using setup.py must run in the same directory. Use option
# `--relative` to prefix is aways fixed.
add_custom_command( OUTPUT ${PYMOOSE_BDIST_FILE}
COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_dumb -p ${_platform}
-d ${PYMOOSE_BDIST_DIR} --relative
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
COMMENT "bdist is saved to ${PYMOOSE_BDIST_DIR}"
VERBATIM
)
add_custom_command(TARGET bdist POST_BUILD
COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_BDIST_INSTALL_DIR} tar xf ${PYMOOSE_BDIST_FILE}
COMMENT "Unarchiving bdist file ${PYMOOSE_BDIST_FILE} to ${PYMOOSE_BDIST_INSTALL_DIR}"
VERBATIM
)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
COMMENT "bdist is saved to ${PYMOOSE_BDIST_DIR}"
VERBATIM
)

# Copy python files from source to current binary directory. Make sure to call
# this before building bdist.
file(GLOB_RECURSE PYTHON_SRCS "${CMAKE_SOURCE_DIR}/python/*")
add_custom_target(copy_pymoose DEPENDS ${PYTHON_SRCS}
COMMAND ${CMAKE_COMMAND} -E copy_directory
add_custom_command(TARGET bdist POST_BUILD
COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_BDIST_INSTALL_DIR} tar xf ${PYMOOSE_BDIST_FILE}
COMMENT "Unarchiving bdist file ${PYMOOSE_BDIST_FILE} to ${PYMOOSE_BDIST_INSTALL_DIR}"
VERBATIM
)

# Copy python files from source to current binary directory. Make sure to call
# this before building bdist.
file(GLOB_RECURSE PYTHON_SRCS "${CMAKE_SOURCE_DIR}/python/*")
add_custom_target(copy_pymoose DEPENDS ${PYTHON_SRCS}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/python ${CMAKE_CURRENT_BINARY_DIR}/python
COMMENT "Copying required python files and other files to build directory"
VERBATIM
)
COMMENT "Copying required python files and other files to build directory"
VERBATIM
)

add_dependencies( bdist copy_pymoose )
add_dependencies( copy_pymoose _moose )
add_dependencies( bdist copy_pymoose )
add_dependencies( copy_pymoose moose )

else(MSYS)
message(STATUS "Warn: I won't generate install target under MSYS but I'll create a wheel")
# see the pymoose/CMakeLists.txt file.
endif()

######################### INSTALL ##############################################

Expand All @@ -421,7 +438,7 @@ if(${CMAKE_BUILD_TOOL} MATCHES "make")
message(
"=======================================\n"
"If cmake did not report any error, run \n"
" 'make' to build MOOSE \n"
" 'make' to build MOOSE \n"
"=======================================\n"
)
endif()
Expand Down
1 change: 1 addition & 0 deletions biophysics/DifShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**********************************************************************/

#include "../basecode/header.h"
#include "../utility/numutil.h"
#include "DifShellBase.h"
#include "DifShell.h"

Expand Down
1 change: 1 addition & 0 deletions biophysics/ReadCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../shell/Shell.h"
#include "ReadCell.h"
#include "../utility/utility.h"
#include "../utility/numutil.h"
#include "CompartmentBase.h"
#include "Compartment.h"
#include "SymCompartment.h"
Expand Down
6 changes: 5 additions & 1 deletion builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ set(SRCS
Stats.cpp
Interpol2D.cpp
SpikeStats.cpp
SocketStreamer.cpp
testBuiltins.cpp
)

if(UNIX)
list(APPEND SRCS SocketStreamer.cpp)
endif()


if(WITH_NSDF AND HDF5_FOUND)
list(APPEND SRCS
HDF5WriterBase.cpp
Expand Down
3 changes: 3 additions & 0 deletions builtins/SocketStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include "../scheduling/Clock.h"
#include "../utility/utility.h"
#include "../shell/Shell.h"

#ifdef POSIX_PLATFORM
#include "SocketStreamer.h"
#endif

const Cinfo* SocketStreamer::initCinfo()
{
Expand Down
4 changes: 4 additions & 0 deletions builtins/SocketStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
#define _XOPEN_SOURCE_EXTENDED 1

// cmake should set include path.
#ifdef WINDOWS
#include <winsock.h>
#else
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif

// MSG_MORE is not defined in OSX. So stupid!
#ifndef MSG_MORE
Expand Down
46 changes: 31 additions & 15 deletions pymoose/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ find_package(PythonInterp REQUIRED)
# Find Numpy
find_package(NumPy REQUIRED)
include_directories(${NUMPY_INCLUDE_DIRS})
add_definitions( -std=c++11 )
add_definitions(-std=c++11)
add_definitions(-DUSE_NUMPY)
add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)

Expand Down Expand Up @@ -39,7 +39,7 @@ set(PYMOOSE_SRCS

# Build python module in source directory and them copy everything to
# current binary directory using cmake.
add_library( _moose MODULE ${PYMOOSE_SRCS} )
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}" )

Expand All @@ -60,7 +60,7 @@ else()
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message( STATUS "Python include flags: ${PYTHON_INCLUDE_FLAGS}" )
set_target_properties(_moose PROPERTIES
set_target_properties(moose PROPERTIES
COMPILE_DEFINITIONS "PYMOOSE"
COMPILE_FLAGS "${PYTHON_INCLUDE_FLAGS}"
)
Expand All @@ -69,17 +69,17 @@ endif()

# Remove prefix lib from python module.
if(NOT(PYTHON_SO_EXTENSION STREQUAL ""))
set_target_properties(_moose PROPERTIES SUFFIX ${PYTHON_SO_EXTENSION})
set_target_properties(moose PROPERTIES SUFFIX ${PYTHON_SO_EXTENSION})
endif()
set_target_properties(_moose PROPERTIES
set_target_properties(moose PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PYMOOSE_OUTPUT_DIRECTORY}
PREFIX ""
SUFFIX ${PYTHON_SO_EXTENSION}
)

# see issue #80
if(HDF5_FOUND AND WITH_NSDF)
set_target_properties( _moose PROPERTIES LINK_FLAGS "-L${HDF5_LIBRARY_DIRS}" )
set_target_properties(moose PROPERTIES LINK_FLAGS "-L${HDF5_LIBRARY_DIRS}" )
endif()

if(APPLE)
Expand All @@ -89,33 +89,49 @@ endif(APPLE)

# cmake --help-policy CMP0042
if(APPLE)
set_target_properties( _moose PROPERTIES MACOSX_RPATH OFF)
set_target_properties(moose PROPERTIES MACOSX_RPATH OFF)
endif(APPLE)

if(APPLE)
target_link_libraries( _moose
target_link_libraries(moose
"-Wl,-all_load"
${MOOSE_LIBRARIES}
${STATIC_LIBRARIES}
)
target_link_libraries(_moose
target_link_libraries(moose
${SYSTEM_SHARED_LIBS}
)
else(APPLE)
target_link_libraries(_moose
target_link_libraries(moose
"-Wl,--whole-archive"
${MOOSE_LIBRARIES}
${STATIC_LIBRARIES}
"-Wl,--no-whole-archive"
${SYSTEM_SHARED_LIBS}
)
endif(APPLE)
add_custom_command(TARGET _moose POST_BUILD
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan

if(MSYS)
message(STATUS "Building under MSYS")
find_package(PythonLibs REQUIRED)
target_link_libraries(moose ${PYTHON_LIBRARIES})
endif()

if(UNIX)
add_custom_command(TARGET moose POST_BUILD
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
"MOOSE python extention is successfully built. Now "
" Run 'sudo make install' to install it. "
" "
"NOTE: Run 'pip uninstall moose' to uninstall moose."
VERBATIM
)

VERBATIM
)
elseif(MSYS)
add_custom_command(TARGET moose POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_wheel
-p win_amd64 -d ${CMAKE_BINARY_DIR} -q
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/python
COMMENT "Generating wheel"
VERBATIM
)
endif()
5 changes: 4 additions & 1 deletion pymoose/moosemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,12 +1738,15 @@ PyObject * moose_start(PyObject * dummy, PyObject * args )
return NULL;
}

#ifdef UNIX
// This is from http://stackoverflow.com/questions/1641182/how-can-i-catch-a-ctrl-c-event-c
struct sigaction sigHandler;
sigHandler.sa_handler = handle_keyboard_interrupts;
sigemptyset(&sigHandler.sa_mask);
sigHandler.sa_flags = 0;
sigaction(SIGINT, &sigHandler, NULL);
#endif

SHELLPTR->doStart( runtime, notify );
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -3121,7 +3124,7 @@ static struct PyModuleDef MooseModuleDef =
#define MODINIT(name) init##name()
#endif

PyMODINIT_FUNC MODINIT(_moose)
PyMODINIT_FUNC MODINIT(moose)
{
clock_t modinit_start = clock();

Expand Down
Loading