Skip to content
Snippets Groups Projects
Commit 2de1893e authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Provide simplified ad-hoc C++ wrapper for C-compiled libcerf

parent 549127a7
No related branches found
No related tags found
No related merge requests found
...@@ -10,13 +10,6 @@ set(lib BornAgain${name}) ...@@ -10,13 +10,6 @@ set(lib BornAgain${name})
file(GLOB source_files */*.cpp) file(GLOB source_files */*.cpp)
file(GLOB include_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */*.h) file(GLOB include_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */*.h)
if((NOT Cerf_IS_CPP) AND (NOT WIN32)) # TEMPORARY
list(APPEND source_files ${CMAKE_SOURCE_DIR}/ThirdParty/Core/cerf_wrapper/cerf_ptr.c)
endif()
if(${Cerf_IS_CPP})
string(APPEND CMAKE_CXX_FLAGS " -DCERF_AS_CPP=ON")
endif()
# --- make the library --- # --- make the library ---
MakeLib(${name} ${lib} ${CMAKE_CURRENT_BINARY_DIR}/Wrap) MakeLib(${name} ${lib} ${CMAKE_CURRENT_BINARY_DIR}/Wrap)
...@@ -34,7 +27,7 @@ target_include_directories(${lib} ...@@ -34,7 +27,7 @@ target_include_directories(${lib}
PUBLIC ${CMAKE_SOURCE_DIR} PUBLIC ${CMAKE_SOURCE_DIR}
${tspectrum_INCLUDE_DIR} ${tspectrum_INCLUDE_DIR}
${Cerf_INCLUDE_DIR} ${Cerf_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/ThirdParty/Core/cerf_wrapper # TEMPORARY ${CMAKE_SOURCE_DIR}/ThirdParty/Core/ # TEMPORARY
) )
target_link_libraries(${lib} target_link_libraries(${lib}
${tspectrum_LIBRARY} ${Cerf_LIBRARIES}) ${tspectrum_LIBRARY} ${Cerf_LIBRARIES})
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
#include "Sample/RT/ILayerRTCoefficients.h" #include "Sample/RT/ILayerRTCoefficients.h"
#include "Sample/Slice/LayerInterface.h" #include "Sample/Slice/LayerInterface.h"
#include "Sample/Slice/LayerRoughness.h" #include "Sample/Slice/LayerRoughness.h"
#include <cerf.h>
#include "cerfcpp.h"
// Diffuse scattering from rough interfaces is modelled after // Diffuse scattering from rough interfaces is modelled after
// Phys. Rev. B, vol. 51 (4), p. 2311 (1995) // Phys. Rev. B, vol. 51 (4), p. 2311 (1995)
......
// -*- mode: c++ -*-
#include <cerf_ptr.h>
std::complex<double> cerfcx(std::complex<double> z) {
std::complex<double> ret;
p_cerfcx((void*)&z, (void*)&ret);
return ret;
}
#include "cerf_ptr.h"
#include "cerf.h"
#include <string.h>
void p_cerfcx(void* z, void* ret)
{
double _Complex val = cerfcx(*(double _Complex*)(z));
memcpy(ret, &val, 2*sizeof(double));
}
#ifdef __cplusplus
extern "C" {
#endif
void p_cerfcx(void* z, void* ret);
#ifdef __cplusplus
} // extern "C"
#endif
/*
This is an ad-hoc solution to make the C-compiled libcerf callable from C++ code.
TODO:
- Either, distribute this along with liberf.
- Or, make sure the Debian, Homebrew etc packages distribute a libcerfcpp along with libcerf.
*/
#include <cerf.h>
#include <complex>
std::complex<double> cerfcx(const std::complex<double>& z)
{
const _cerf_cmplx ret = cerfcx(*((_cerf_cmplx*)(&z)));
return {reinterpret_cast<const double(&)[2]>(ret)[0],
reinterpret_cast<const double(&)[2]>(ret)[1]};
}
...@@ -19,6 +19,9 @@ else() ...@@ -19,6 +19,9 @@ else()
endif() endif()
find_package(Cerf REQUIRED) find_package(Cerf REQUIRED)
if(Cerf_IS_CPP)
add_compile_definitions(CERF_AS_CPP=ON)
endif()
# --- Boost --- # --- Boost ---
set(Boost_NO_BOOST_CMAKE ON) # prevent shortcut set(Boost_NO_BOOST_CMAKE ON) # prevent shortcut
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment