Skip to content

Commit

Permalink
Improvements to the build system (#86)
Browse files Browse the repository at this point in the history
* Minor cleanups to build

* Script cleanup

* Simplified python building

* Capitalization consistency...

* Only mac autopath for python is needed

* Mac without toolchain

* Test for linux with no toolchain

* Static/Shared division

* Reverting feature that still doesn't work.
  • Loading branch information
william-dawson authored Nov 16, 2018
1 parent f18346e commit dfea262
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 69 deletions.
38 changes: 26 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ enable_language(Fortran)

################################################################################
## Packages
find_package(MPI REQUIRED)
if (NOT CMAKE_TOOLCHAIN_FILE)
message(WARNING "Building without a toolchain file. "
"If this does not work, please see the example toolchain files in "
"the Targets directory and set the parameters that match your "
"system.")
find_package(MPI REQUIRED)
find_package(BLAS)
endif()
find_package(SWIG 3.0)

################################################################################
## Testing
if (NOT FORTRAN_ONLY)
enable_testing()
else()
MESSAGE(WARNING "Fortran only! No local testing will be generated.")
message(WARNING "Fortran only! No local testing will be generated.")
endif()

################################################################################
Expand All @@ -23,33 +30,40 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION include)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/
DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/scratch)

################################################################################
## Compiler Flags
set(CMAKE_Fortran_FLAGS_DEBUG ${F_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${CXX_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_Fortran_FLAGS_RELEASE ${F_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${CXX_TOOLCHAINFLAGS_RELEASE})
if (CMAKE_TOOLCHAIN_FILE)
set(CMAKE_Fortran_FLAGS_DEBUG ${F_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${CXX_TOOLCHAINFLAGS_DEBUG})
set(CMAKE_Fortran_FLAGS_RELEASE ${F_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${CXX_TOOLCHAINFLAGS_RELEASE})
else()
find_package(OpenMP)
set(CMAKE_Fortran_FLAGS_RELEASE
"${CMAKE_Fortran_FLAGS_RELEASE} ${OpenMP_Fortran_FLAGS}")
endif()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_Fortran_FLAGS ${F_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_CXX_FLAGS ${CXX_TOOLCHAINFLAGS_RELEASE})
set(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
endif()

################################################################################
## Check MPI Features
option(USE_MPIH OFF)
if (NOT ${MPI_Fortran_HAVE_F90_MODULE})
if (USE_MPIH OR NOT ${MPI_Fortran_HAVE_F90_MODULE})
add_definitions(-DUSE_MPIH)
endif()

option(NOIALLGATHER OFF)
if (NOIALLGATHER)
add_definitions(-DNOIALLGATHER)
MESSAGE(STATUS "IAllgather replacement activated.")
MESSAGE(STATUS "Note that this may reduce parallel performance.")
message(STATUS "IAllgather replacement activated.")
message(STATUS "Note that this may reduce parallel performance.")
endif()

################################################################################
Expand Down
4 changes: 2 additions & 2 deletions Documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if ( FORD )
add_custom_target(fdoc "${FORD}" Ford)
add_dependencies(doc fdoc)
else()
MESSAGE(WARNING
message(WARNING
"FORD not found! No fortran documentation will be generated.")
endif()

Expand All @@ -23,5 +23,5 @@ if (NOT FORTRAN_ONLY AND DOXYGEN_FOUND)
add_custom_target(cdoc ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile)
add_dependencies(doc cdoc)
elseif(NOT DOXYGEN_FOUND)
MESSAGE(WARNING "Doxygen not found! No documentation will be generated.")
message(WARNING "Doxygen not found! No documentation will be generated.")
endif()
2 changes: 1 addition & 1 deletion Source/CPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set(Chead
)

################################################################################
add_library(NTPolyCPP STATIC ${Csrc} ${Chead})
add_library(NTPolyCPP ${Csrc} ${Chead})
target_link_libraries(NTPolyCPP NTPolyWrapper)

set_target_properties(NTPolyCPP PROPERTIES PUBLIC_HEADER "${Chead}")
Expand Down
1 change: 0 additions & 1 deletion Source/CPlusPlus/EigenBounds.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "EigenBounds.h"
using namespace NTPoly;
#include <iostream>

////////////////////////////////////////////////////////////////////////////////
extern "C" {
Expand Down
2 changes: 0 additions & 2 deletions Source/CPlusPlus/MatrixMapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "TripletList.h"
#include "Wrapper.h"

#include <iostream>

////////////////////////////////////////////////////////////////////////////////
extern "C" {
#include "PSMatrix_c.h"
Expand Down
6 changes: 5 additions & 1 deletion Source/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ set(Fsrc
)

################################################################################
add_library(NTPoly STATIC ${Fsrc})
add_library(NTPoly ${Fsrc})
target_link_libraries(NTPoly ${MPI_Fortran_LIBRARIES}
${OpenMP_Fortran_LIBRARIES} ${BLAS_LIBRARIES})
target_include_directories(NTPoly PUBLIC ${MPI_Fortran_INCLUDE_PATH})

include(GNUInstallDirs)
install(TARGETS NTPoly
EXPORT ntpoly-export
Expand Down
34 changes: 18 additions & 16 deletions Source/Swig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
################################################################################
if (SWIG_FOUND)
# Determine python path using python's distutils module
# Probe some information about python
if(NOT DEFINED PYTHON_EXECUTABLE)
find_package(PythonInterp REQUIRED)
endif()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import get_python_inc; print(get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE(STATUS "Using Python Include Path:" ${PYTHON_INCLUDE_PATH})
MESSAGE(STATUS "Using Python Library Path:" ${PYTHON_LIBRARIES})
INCLUDE(${SWIG_USE_FILE})

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(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)

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

set(Swigsrc
NTPolySwig.i
Expand All @@ -27,13 +29,13 @@ if (SWIG_FOUND)
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES CPLUSPLUS ON)
endforeach(file)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/python)
SWIG_ADD_MODULE(NTPolySwig python ${Swigsrc})
SWIG_LINK_LIBRARIES(NTPolySwig NTPolyCPP NTPolyWrapper NTPoly
swig_add_module(NTPolySwig python ${Swigsrc})
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
)
else()
MESSAGE(WARNING "Swig not found! No python bindings will be generated.")
message(WARNING "Swig not found! No python bindings will be generated.")
endif()
20 changes: 20 additions & 0 deletions Source/Swig/ConfigPython.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
################################################################################
# Determine python include path using python's distutils module
macro(get_py_include)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import get_python_inc; print(get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
endmacro()

################################################################################
# Determine Python Library Path
macro(get_py_lib)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"
from distutils.sysconfig import get_python_lib
path=get_python_lib(standard_lib=True)+\"/../../Python\"
print(path)"
OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
endmacro()
2 changes: 1 addition & 1 deletion Source/Wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(Wsrc
)

################################################################################
add_library(NTPolyWrapper STATIC ${Wsrc})
add_library(NTPolyWrapper ${Wsrc})
target_link_libraries(NTPolyWrapper NTPoly)

include(GNUInstallDirs)
Expand Down
13 changes: 0 additions & 13 deletions Targets/Mac-python2.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
################################################################################
# Target file for a Mac computer.
# Unfortunately, installing on the mac is a bit tricky. The problem is that
# when you install SWIG, it might link against the wrong version of python.
# That's why I've included custom set variables for the python dynamic library,
# which is determined by your choice of python executable.
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)
set(PYTHON_EXECUTABLE python2)

# Determine Python Library Path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"
from distutils.sysconfig import get_python_lib
path=get_python_lib(standard_lib=True)+\"/../../Python\"
print path"
OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)

# Library Files
set(TOOLCHAIN_LIBS "-framework Accelerate -lgomp")

Expand Down
13 changes: 0 additions & 13 deletions Targets/Mac-python3.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
################################################################################
# Target file for a Mac computer.
# Unfortunately, installing on the mac is a bit tricky. The problem is that
# when you install SWIG, it might link against the wrong version of python.
# That's why I've included custom set variables for the python dynamic library,
# which is determined by your choice of python executable.
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)
set(PYTHON_EXECUTABLE python3)

# Determine Python Library Path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c
"
from distutils.sysconfig import get_python_lib
path=get_python_lib(standard_lib=True)+\"/../../Python\"
print(path)"
OUTPUT_VARIABLE PYTHON_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)

# Library Files
set(TOOLCHAIN_LIBS "-framework Accelerate -lgomp")

Expand Down
1 change: 1 addition & 0 deletions UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(TestFiles
find_package(PythonInterp REQUIRED)

################################################################################
find_package(MPI REQUIRED)
execute_process(COMMAND ${MPIEXEC} --version
OUTPUT_VARIABLE mpiversion OUTPUT_STRIP_TRAILING_WHITESPACE)
if (${mpiversion} MATCHES "OpenRTE")
Expand Down
14 changes: 7 additions & 7 deletions UnitTests/travis_run_cmake.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
if [[ "$TESTOS" == "OSX" ]]; then
cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/Mac-python2.cmake \
-DCMAKE_BUILD_TYPE=Release .. ;
cmake .. -DCMAKE_TOOLCHAIN_FILE=../Targets/Mac-python2.cmake \
-DCMAKE_BUILD_TYPE=Release ;
else
if [ ! -z ${NOIALLGATHER+x} ]; then
cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake \
-DNOIALLGATHER=YES .. -DCMAKE_BUILD_TYPE=Release ;
cmake .. -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake \
-DNOIALLGATHER=YES -DCMAKE_BUILD_TYPE=Release ;
elif [ -z ${FORTRAN_ONLY+x} ]; then
cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake .. \
cmake .. -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake \
-DCMAKE_BUILD_TYPE=Release ;
else
cmake -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake \
-DFORTRAN_ONLY=YES .. -DCMAKE_BUILD_TYPE=Release ;
cmake .. -DCMAKE_TOOLCHAIN_FILE=../Targets/Linux.cmake \
-DFORTRAN_ONLY=YES -DCMAKE_BUILD_TYPE=Release ;
fi
fi

0 comments on commit dfea262

Please sign in to comment.