Browse Source

Merge remote-tracking branch 'origin/master'

Ovidio Peña Rodríguez 4 years ago
parent
commit
ccd8378069
2 changed files with 56 additions and 15 deletions
  1. 36 12
      CMakeLists.txt
  2. 20 3
      src/CMakeLists.txt

+ 36 - 12
CMakeLists.txt

@@ -3,9 +3,10 @@ project(scattnlay VERSION 2.3)
 
 cmake_host_system_information(RESULT HOSTNAME QUERY HOSTNAME)
 
-message("Build type is: " ${CMAKE_BUILD_TYPE})
+message("Build type is: ${CMAKE_BUILD_TYPE}")
 message("Host OS System: ${CMAKE_HOST_SYSTEM}")
 message("Hostname:  ${HOSTNAME}")
+message("CMake version:  ${CMAKE_VERSION}")
 
 # Select flags.
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
@@ -13,7 +14,7 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
 set(CMAKE_CXX_FLAGS_RELEASE "-O3")
 set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 
-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
@@ -21,7 +22,7 @@ add_compile_options(-Wall)
 add_compile_options(-funroll-loops -fstrict-aliasing)
 
 # Set options
-option(ENABLE_MP "Use multiple precision" ON)
+option(ENABLE_MP "Use multiple precision" OFF)
 if (${ENABLE_MP})
     add_compile_options(-DMULTI_PRECISION=100)
 endif ()
@@ -41,8 +42,7 @@ if (USE_STATIC_LIBRARIES)
 endif ()
 set(Boost_USE_MULTITHREADED OFF)
 set(Boost_USE_STATIC_RUNTIME OFF)
-find_package(Boost
-        REQUIRED COMPONENTS chrono filesystem iostreams regex serialization system timer)
+find_package(Boost REQUIRED)
 if (Boost_INCLUDE_DIRS)
     if (${Boost_VERSION} VERSION_LESS 1.60.0)
         message(FATAL_ERROR
@@ -54,18 +54,19 @@ if (Boost_INCLUDE_DIRS)
     include_directories(${Boost_INCLUDE_DIRS})
 endif ()
 
-#Find Python and NumPy
+#Find Python, NumPy and PyBind11
 find_package(Python COMPONENTS Interpreter Development)
 
 include_directories(${Python_INCLUDE_DIRS})
 
-message("Python_EXECUTABLE:${Python_EXECUTABLE}")
-message("Python_FOUND:${Python_FOUND}")
-message("Python_VERSION:${Python_VERSION}")
-message("Python_Development_FOUND:${Python_Development_FOUND}")
-message("Python_LIBRARIES:${Python_LIBRARIES}")
+message("Python_EXECUTABLE: ${Python_EXECUTABLE}")
+message("Python_FOUND: ${Python_FOUND}")
+message("Python_VERSION: ${Python_VERSION}")
+message("Python_Development_FOUND: ${Python_Development_FOUND}")
+message("Python_LIBRARIES: ${Python_LIBRARIES}")
+message("Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
 
-# This comes to hand if we also need to use the NumPy C API
+# Ensure that numpy is installed and read its include dir
 exec_program(${Python_EXECUTABLE}
         ARGS "-c \"import numpy; print(numpy.get_include())\""
         OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
@@ -75,5 +76,28 @@ if (NUMPY_NOT_FOUND)
     message(FATAL_ERROR "NumPy headers not found")
 endif ()
 
+# Ensure that pybind11 is installed and read its include dir
+exec_program(${Python_EXECUTABLE}
+        ARGS "-c \"import pybind11; print(pybind11.get_include())\""
+        OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR
+        RETURN_VALUE PYBIND11_NOT_FOUND
+        )
+if (PYBIND11_NOT_FOUND)
+    message(FATAL_ERROR "PyBind11 headers not found")
+endif ()
+
 #include_directories(src)
 add_subdirectory(src)
+
+#
+# Copy all python scripts to the build directory.
+#
+set(Python_SCRIPTS scattnlay/__init__.py scattnlay/main.py)
+
+foreach (_script ${Python_SCRIPTS})
+    configure_file(
+            ${PROJECT_SOURCE_DIR}/${_script}
+            ${PROJECT_BINARY_DIR}/${_script}
+            COPYONLY
+    )
+endforeach ()

+ 20 - 3
src/CMakeLists.txt

@@ -1,3 +1,4 @@
+# Sources for python extension
 set(_scattnlay_python_sources
         ${CMAKE_CURRENT_LIST_DIR}/nmie.hpp
         ${CMAKE_CURRENT_LIST_DIR}/nmie.cc
@@ -7,8 +8,11 @@ set(_scattnlay_python_sources
         ${CMAKE_CURRENT_LIST_DIR}/nmie-impl.cc
         ${CMAKE_CURRENT_LIST_DIR}/pb11_wrapper.cc)
 
+# Define python extension
 add_library(python3-scattnlay SHARED ${_scattnlay_python_sources})
-target_link_libraries(python3-scattnlay ${PYTHON_LIBRARIES})
+target_link_libraries(python3-scattnlay PRIVATE Boost::headers ${Python_LIBRARIES})
+target_include_directories(python3-scattnlay PRIVATE ${NUMPY_INCLUDE_DIR} ${PYBIND11_INCLUDE_DIR})
+set_target_properties(python3-scattnlay PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
 
 set_target_properties(
         python3-scattnlay
@@ -18,16 +22,29 @@ set_target_properties(
         LINKER_LANGUAGE C
 )
 
-add_executable(farfield
+# Sources for far field calculation
+set(_scattnlay_farfield_sources
         ${CMAKE_CURRENT_LIST_DIR}/farfield.cc
         ${CMAKE_CURRENT_LIST_DIR}/nmie.hpp
         ${CMAKE_CURRENT_LIST_DIR}/nmie.cc)
 
-add_executable(nearfield
+# Define exe for far field calculation
+add_executable(farfield ${_scattnlay_farfield_sources})
+target_link_libraries(farfield PRIVATE Boost::headers)
+set_target_properties(farfield PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
+# Sources for near field calculation
+set(_scattnlay_nearfield_sources
         ${CMAKE_CURRENT_LIST_DIR}/nearfield.cc
         ${CMAKE_CURRENT_LIST_DIR}/nmie.hpp
         ${CMAKE_CURRENT_LIST_DIR}/nmie.cc)
 
+# Define exe for near field calculation
+add_executable(nearfield ${_scattnlay_nearfield_sources})
+target_link_libraries(nearfield PRIVATE Boost::headers)
+set_target_properties(nearfield PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
+# Rename files to match precision
 if (${ENABLE_MP})
     set_property(TARGET python3-scattnlay APPEND_STRING PROPERTY OUTPUT_NAME "_mp")
     set_property(TARGET farfield APPEND_STRING PROPERTY OUTPUT_NAME "farfield-mp")