Skip to content

Commit

Permalink
More extensive cmake options (#123)
Browse files Browse the repository at this point in the history
* More extensive cmake options.

* Better warning message.

* Removed custom test target

Older cmake versions complain about this usage.
  • Loading branch information
william-dawson authored Apr 30, 2019
1 parent 2f1f05a commit 2bacdc9
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 66 deletions.
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ endif()
find_package(SWIG 3.0)

################################################################################
## Testing
## Options
option(FORTRAN_ONLY "Build only the Fortran bindings." OFF)
if (NOT FORTRAN_ONLY)
option(NOSWIG "Don't build the swig bindings." OFF)
option(USE_MPIH "Use mpi.h for systems that don't have the mpi module" OFF)
option(NOIALLGATHER
"A (slower) alternative communication strategy if iallgather not implemented"
OFF)

## Process these options
if (NOT SWIG_FOUND OR FORTRAN_ONLY)
set(NOSWIG TRUE)
endif()

################################################################################
## Testing
if (NOT NOSWIG)
enable_testing()
else()
message(WARNING "Fortran only! No local testing will be generated.")
message(WARNING
"Swig disabled. No python bindings or testing will be generated.")
endif()

################################################################################
Expand Down Expand Up @@ -55,14 +69,10 @@ endif()

################################################################################
## Check MPI Features
option(USE_MPIH "Use mpi.h for systems that don't have the mpi module" OFF)
if (USE_MPIH OR NOT ${MPI_Fortran_HAVE_F90_MODULE})
add_definitions(-DUSE_MPIH)
endif()

option(NOIALLGATHER
"A (slower) alternative communication strategy if iallgather not implemented"
OFF)
if (NOIALLGATHER)
add_definitions(-DNOIALLGATHER)
message(STATUS "IAllgather replacement activated.")
Expand All @@ -74,6 +84,6 @@ endif()
subdirs(Documentation)
subdirs(Source)

if (NOT FORTRAN_ONLY)
if (NOT NOSWIG)
subdirs(UnitTests)
endif()
46 changes: 29 additions & 17 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,50 @@ The following optional software can greatly enhance the NTPoly experience:

* BLAS: for multiplying dense matrices, if they emerge in the calculation.
* A C++ Compiler for building C++ bindings.
* Doxygen: for building documentation.
* Python (Version 2.7+): for testing.
* Ford: for building documentation.
* Doxygen: for building C++ documentation.
* SWIG (Version 3.0+): for building the Python bindings.
* Python (Version 2.7+): if you would like python bindings.
* MPI4PY: for testing.
* SciPy: for testing.
* NumPy: for testing.
* SWIG (Version 3.0+): for building the Python bindings.

NTPoly uses CMake as a build system. First, take a look in the Targets
directory. You'll find a list of `.cmake` files which have example configurations
on popular systems. You should copy one of these files, and create your own
mymachine.cmake file. Then, cd into the Build directory, and type:
directory. You'll find a list of `.cmake` files which have example
configurations on popular systems. You should copy one of these files, and
create your own mymachine.cmake file. Then, cd into the Build directory, and
type:
> cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/mymachine.cmake ..
There are a few options you can pass to CMake to modify the build. You can set
`-DCMAKE_BUILD_TYPE=Debug` for debugging purposes. You can set the install
directory using the standard `-DCMAKE_INSTALL_PREFIX=/path/to/dir`. You can
also set `-DFORTRAN_ONLY=YES` if you want to only build the Fortran interface.
Note that with just the Fortran interface, it is not possible to perform local
tests.

After that you can build using:
> make
And for the documentation:
> make doc
[Online documentation](https://william-dawson.github.io/NTPoly/documentation/) is also
available. Further details about the library can be found on the
[Wiki](https://github.com/william-dawson/NTPoly/wiki).
If you aren't cross compiling, you can perform local tests using:
If you aren't cross compiling and have built the python bindings, you can
perform local tests using:
> make test
There are a few options you can pass to CMake to modify the build. A few
useful standard options are:
* `-DCMAKE_BUILD_TYPE=` `Debug` or `Release`.
* `-DCMAKE_INSTALL_PREFIX=` followed by the path to your desired install
directory.

There are also some custom options special for NTPoly:
* `-DFORTRAN_ONLY=` set to `Yes` if you only want to build the Fortran bindings.
* `-DNOSWIG=` set to `Yes` if you don't want to build Python bindings.
* `-DUSE_MPIH=` on some systems, there is no `use mpi` feature for Fortran,
just `#include "mpi.h"`. You can set this option to activate the later.
* `-DNOIALLGATHER=` on older MPI implementations, there is no non blocking
collective operations. You can disable this feature using this option, but
beware this might reduce performance.

[Online documentation](https://william-dawson.github.io/NTPoly/documentation/)
is also available. Further details about the library can be found on the
[Wiki](https://github.com/william-dawson/NTPoly/wiki).

Basic Theory
--------------------------------------------------------------------------------
The theory of matrix functions is a long studied branch of matrix algebra.
Expand Down
11 changes: 10 additions & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
################################################################################
## Basic Code
subdirs(Fortran)

## C++ Bindings
if (NOT FORTRAN_ONLY)
subdirs(C)
subdirs(CPlusPlus)
subdirs(Swig)
subdirs(Wrapper)
endif()

## Python bindings built with swig
if (NOT NOSWIG)
subdirs(Swig)
else()
message(WARNING "Swig is disabled. No python bindings with be generated.")
endif()
4 changes: 3 additions & 1 deletion Source/CPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ set(Chead

################################################################################
add_library(NTPolyCPP ${Csrc} ${Chead})
set_target_properties(NTPolyCPP PROPERTIES POSITION_INDEPENDENT_CODE True)
if (NOT NOSWIG)
set_target_properties(NTPolyCPP PROPERTIES POSITION_INDEPENDENT_CODE True)
endif()
target_link_libraries(NTPolyCPP NTPolyWrapper)

set_target_properties(NTPolyCPP PROPERTIES PUBLIC_HEADER "${Chead}")
Expand Down
2 changes: 1 addition & 1 deletion Source/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(Fsrc

################################################################################
add_library(NTPoly ${Fsrc})
if (NOT FORTRAN_ONLY)
if (NOT NOSWIG)
set_target_properties(NTPoly PROPERTIES POSITION_INDEPENDENT_CODE True)
endif()
target_link_libraries(NTPoly ${MPI_Fortran_LIBRARIES}
Expand Down
70 changes: 33 additions & 37 deletions Source/Swig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
################################################################################
if (SWIG_FOUND)
# Probe some information about python
if(NOT DEFINED PYTHON_EXECUTABLE)
find_package(PythonInterp REQUIRED)
endif()
# Probe some information about python
if(NOT DEFINED PYTHON_EXECUTABLE)
find_package(PythonInterp REQUIRED)
endif()

include(ConfigPython.cmake)
if (APPLE)
get_py_lib()
message(STATUS "Using Python Library Path:" ${PYTHON_LIBRARIES})
endif()
get_py_include()
message(STATUS "Using Python Include Path:" ${PYTHON_INCLUDE_PATH})
include(ConfigPython.cmake)
if (APPLE)
get_py_lib()
message(STATUS "Using Python Library Path:" ${PYTHON_LIBRARIES})
endif()
get_py_include()
message(STATUS "Using Python Include Path:" ${PYTHON_INCLUDE_PATH})

include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/Source/C)
include_directories(${CMAKE_SOURCE_DIR}/Source/CPlusPlus)
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/Source/C)
include_directories(${CMAKE_SOURCE_DIR}/Source/CPlusPlus)

include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")

set(Swigsrc
NTPolySwig.i
)
set(Swigsrc
NTPolySwig.i
)

foreach(file ${Swigsrc})
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES CPLUSPLUS ON)
endforeach(file)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/python)
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
swig_add_module(NTPolySwig python ${Swigsrc})
else()
swig_add_library(NTPolySwig LANGUAGE python SOURCES ${Swigsrc})
endif()
swig_link_libraries(NTPolySwig NTPolyCPP NTPolyWrapper NTPoly
${PYTHON_LIBRARIES} ${TOOLCHAIN_LIBS})
set_target_properties(_NTPolySwig PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python
)
foreach(file ${Swigsrc})
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES CPLUSPLUS ON)
endforeach(file)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/python)
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
swig_add_module(NTPolySwig python ${Swigsrc})
else()
message(WARNING "Swig not found! No python bindings will be generated.")
swig_add_library(NTPolySwig LANGUAGE python SOURCES ${Swigsrc})
endif()
swig_link_libraries(NTPolySwig NTPolyCPP NTPolyWrapper NTPoly
${PYTHON_LIBRARIES} ${TOOLCHAIN_LIBS})
set_target_properties(_NTPolySwig PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python
)
5 changes: 4 additions & 1 deletion Source/Wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ set(Wsrc

################################################################################
add_library(NTPolyWrapper ${Wsrc})
set_target_properties(NTPolyWrapper PROPERTIES POSITION_INDEPENDENT_CODE True)
if (NOT NOSWIG)
set_target_properties(NTPolyWrapper PROPERTIES
POSITION_INDEPENDENT_CODE True)
endif()
target_link_libraries(NTPolyWrapper NTPoly)

include(GNUInstallDirs)
Expand Down

0 comments on commit 2bacdc9

Please sign in to comment.