Skip to content

Commit

Permalink
update cmake structure for better compatibility with macOS Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPdeS committed Dec 20, 2024
1 parent 8da341b commit 42626fc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
43 changes: 25 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.20)

set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0" CACHE STRING "Minimum OS X deployment version")

project(PyMieSim LANGUAGES Fortran CXX)

# CMake settings
Expand All @@ -11,24 +9,30 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Type of build" FORCE)


# Directories
set(PYMIESIM_CXX_DIR "PyMieSim/cpp")
set(PYMIESIM_BIN_DIR "${CMAKE_SOURCE_DIR}/PyMieSim/binary")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PYMIESIM_BIN_DIR}")


# Compiler and linker options
add_compile_options(-fPIC -Wall -Wextra -Wno-uninitialized)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wno-unused-dummy-argument -Wno-compare-reals -Wno-do-subscript -Wno-intrinsic-shadow")

# Find packages

# Include directories
include_directories("${PYMIESIM_CXX_DIR}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
include_directories("/opt/homebrew/opt/libomp/include") # for if compiler was installed through brew
endif()


# Find dependencies
find_package(OpenMP REQUIRED)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

# Include directories
include_directories(
"${PYMIESIM_CXX_DIR}"
)

# Platform-specific settings for static linking
if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand All @@ -37,6 +41,9 @@ if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fopenmp)
add_link_options(-static -fopenmp -Wl,--whole-archive -lgomp -Wl,--no-whole-archive)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fopenmp")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lomp")
message("AppleClang compiler detected")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message("GNU compiler detected")
Expand Down Expand Up @@ -65,7 +72,17 @@ function(add_pymiesim_module name source)
target_link_options(${name} PUBLIC ${STATIC_LINK_OPTIONS})
endfunction()

# Add modules
# Function to add PyMieSim modules
function(add_pymiesim_module name source)
pybind11_add_module(${name} MODULE "${PYMIESIM_CXX_DIR}/${source}")
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name})
target_link_libraries(${name} PRIVATE ZBessel OpenMP::OpenMP_CXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(${name} PRIVATE -lomp)
endif()
endfunction()

# Add PyMieSim modules
add_pymiesim_module(DetectorInterface "single/interface/detector.cpp")
add_pymiesim_module(SphereInterface "single/interface/sphere.cpp")
add_pymiesim_module(CylinderInterface "single/interface/cylinder.cpp")
Expand All @@ -76,13 +93,3 @@ add_pymiesim_module(Fibonacci "single/interface/mesh.cpp")
add_pymiesim_module(SetsInterface "experiment/interface/sets.cpp")
add_pymiesim_module(ScattererPropertiesInterface "experiment/interface/scatterer_properties.cpp")
add_pymiesim_module(Experiment "experiment/interface/experiment.cpp")

# Special handling for Experiment module
if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(Experiment PRIVATE OpenMP::OpenMP_CXX)
add_link_options(-static -fopenmp -Wl,--whole-archive -lgomp -Wl,--no-whole-archive)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(Experiment PRIVATE OpenMP::OpenMP_CXX)
else()
target_link_libraries(Experiment PRIVATE "-Xpreprocessor -fopenmp")
endif()
4 changes: 2 additions & 2 deletions PyMieSim/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '3.1.0.6'
__version_tuple__ = version_tuple = (3, 1, 0, 6)
__version__ = version = '3.1.1.1'
__version_tuple__ = version_tuple = (3, 1, 1, 1)
26 changes: 26 additions & 0 deletions development/cpu_stressing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

from PyMieSim.experiment.scatterer import Sphere
from PyMieSim.experiment.source import Gaussian
from PyMieSim.experiment import Setup
import numpy as np
from PyMieSim.units import nanometer, degree, watt, AU, RIU

source = Gaussian(
wavelength=400 * nanometer,
polarization=[0] * degree,
optical_power=1e-6 * watt,
NA=0.2 * AU
)

scatterer = Sphere(
diameter=np.linspace(300, 1000, 100) * nanometer,
property=[1.2, 1.25] * RIU,
medium_property=[1.0] * RIU,
source=source
)

experiment = Setup(scatterer=scatterer, source=source)

dataframe = experiment.get('a1')

dataframe.plot_data(x='scatterer:diameter')

0 comments on commit 42626fc

Please sign in to comment.