<commit_before>cmake_minimum_required(VERSION 2.8.12)
project(SofaPython)

##
## SofaPython version
##
set( SOFAPYTHON_MAJOR_VERSION 0 )
set( SOFAPYTHON_MINOR_VERSION 0 )
set( SOFAPYTHON_BUILD_VERSION 1 )

set( SOFAPYTHON_VERSION ${SOFAPYTHON_MAJOR_VERSION}.${SOFAPYTHON_MINOR_VERSION}.${SOFAPYTHON_BUILD_VERSION} CACHE INTERNAL "Set to internal so it can be changed by sub directories.")


set(SOFAPYTHON_BUILD_LIB_DIR     ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(SOFAPYTHON_BUILD_BIN_DIR     ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(SOFAPYTHON_BUILD_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(SOFAPYTHON_BUILD_CMAKE_DIR   ${CMAKE_BINARY_DIR}/SofaPython)

# Offer the user the choice of overriding the installation directories
set(SOFAPYTHON_INSTALL_LIB_DIR     lib                      CACHE PATH "Installation directory for libraries relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_BIN_DIR     bin                      CACHE PATH "Installation directory for executables relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_INCLUDE_DIR include                  CACHE PATH "Installation directory for header files relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_CMAKE_DIR   ${SOFAPYTHON_INSTALL_LIB_DIR}/cmake/SofaPython )


find_package(PythonLibs 2.7 REQUIRED)

find_package(SofaGui REQUIRED)
find_package(SofaGeneral REQUIRED)
find_package(SofaMisc REQUIRED)
set(SOFAPYTHON_DEPENDENCY_INCLUDE_DIR ${SofaGui_INCLUDE_DIRS} ${SofaGeneral_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} )

set(SOFA_HAVE_PYTHON 1)

set(HEADER_FILES

    initSofaPython.h
    ScriptController.h
    PythonScriptController.h
    PythonMacros.h
    PythonEnvironment.h
    Binding.h
    Binding_Base.h
    Binding_SofaModule.h
    Binding_Node.h
    Binding_Context.h
    Binding_BaseContext.h
    Binding_Data.h
    Binding_BaseObject.h
    Binding_BaseState.h
    PythonVisitor.h
    Binding_DisplayFlagsData.h
    ScriptEvent.h
    PythonScriptEvent.h
    Binding_BaseLoader.h
    Binding_MeshLoader.h
    Binding_Vector.h
    Binding_Topology.h
    Binding_BaseMeshTopology.h
    Binding_MeshTopology.h
    Binding_GridTopology.h
    Binding_RegularGridTopology.h
    Binding_BaseMapping.h 
    Binding_MultiMapping.h 
    Binding_SubsetMultiMapping.h 
    Binding_Mapping.h 
    Binding_RigidMapping.h 
    Binding_MechanicalObject.h
    Binding_BaseMechanicalState.h
    Binding_PythonScriptController.h
    Binding_LinearSpring.h
    Binding_VisualModel.h
    SceneLoaderPY.h
    ScriptEnvironment.h
	)

set(SOURCE_FILES

    initSofaPython.cpp
    ScriptController.cpp
    PythonScriptController.cpp
    PythonEnvironment.cpp
    Binding.cpp
    Binding_SofaModule.cpp
    Binding_Base.cpp
    Binding_Context.cpp
    Binding_BaseContext.cpp
    Binding_Node.cpp
    Binding_Data.cpp
    Binding_BaseObject.cpp
    Binding_BaseState.cpp
    PythonMacros.cpp
    PythonVisitor.cpp
    Binding_DisplayFlagsData.cpp
    ScriptEvent.cpp
    PythonScriptEvent.cpp
    Binding_BaseLoader.cpp
    Binding_MeshLoader.cpp
    Binding_Vector.cpp
    Binding_Topology.cpp
    Binding_BaseMeshTopology.cpp
    Binding_MeshTopology.cpp
    Binding_GridTopology.cpp
    Binding_RegularGridTopology.cpp
    Binding_BaseMapping.cpp 
    Binding_MultiMapping.cpp 
    Binding_Mapping.cpp 
    Binding_RigidMapping.cpp 
    Binding_SubsetMultiMapping.cpp 
    Binding_MechanicalObject.cpp
    Binding_BaseMechanicalState.cpp
    Binding_PythonScriptController.cpp
    Binding_LinearSpring.cpp
    Binding_VisualModel.cpp
    SceneLoaderPY.cpp
    ScriptEnvironment.cpp
	)

set(PYTHON_FILES
    SofaPython.py
)

# include python files
include(./python/python.cmake)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/SofaPython.h.in
                ${CMAKE_CURRENT_BINARY_DIR}/sofa/SofaPython.h)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/sofa/SofaPython.h
         DESTINATION "${SOFAPYTHON_INSTALL_INCLUDE_DIR}/sofa")

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} )
target_link_libraries( ${PROJECT_NAME} PUBLIC SofaSimulationCommon SofaUserInteraction SofaGuiCommon SofaComponentMisc SofaComponentGeneral ${PYTHON_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>") 
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>") 
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${SOFAPYTHON_DEPENDENCY_INCLUDE_DIR}>")
set( SOFAPYTHON_COMPILER_FLAGS "-DSOFA_BUILD_SOFAPYTHON")
# Python's implementation deliberately breaks strict-aliasing rules, so we
# compile with -fno-strict-aliasing to prevent the compiler from relying on
# those rules to optimize the code.
if(${CMAKE_COMPILER_IS_GNUCC})
    set(SOFAPYTHON_COMPILER_FLAGS "${SOFAPYTHON_COMPILER_FLAGS} -fno-strict-aliasing")
endif()<commit_msg>SofaPython: cmake: link with libdl on Linux<commit_after>cmake_minimum_required(VERSION 2.8.12)
project(SofaPython)

##
## SofaPython version
##
set( SOFAPYTHON_MAJOR_VERSION 0 )
set( SOFAPYTHON_MINOR_VERSION 0 )
set( SOFAPYTHON_BUILD_VERSION 1 )

set( SOFAPYTHON_VERSION ${SOFAPYTHON_MAJOR_VERSION}.${SOFAPYTHON_MINOR_VERSION}.${SOFAPYTHON_BUILD_VERSION} CACHE INTERNAL "Set to internal so it can be changed by sub directories.")


set(SOFAPYTHON_BUILD_LIB_DIR     ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(SOFAPYTHON_BUILD_BIN_DIR     ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(SOFAPYTHON_BUILD_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(SOFAPYTHON_BUILD_CMAKE_DIR   ${CMAKE_BINARY_DIR}/SofaPython)

# Offer the user the choice of overriding the installation directories
set(SOFAPYTHON_INSTALL_LIB_DIR     lib                      CACHE PATH "Installation directory for libraries relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_BIN_DIR     bin                      CACHE PATH "Installation directory for executables relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_INCLUDE_DIR include                  CACHE PATH "Installation directory for header files relative to CMAKE_INSTALL_PREFIX variable")
set(SOFAPYTHON_INSTALL_CMAKE_DIR   ${SOFAPYTHON_INSTALL_LIB_DIR}/cmake/SofaPython )


find_package(PythonLibs 2.7 REQUIRED)

find_package(SofaGui REQUIRED)
find_package(SofaGeneral REQUIRED)
find_package(SofaMisc REQUIRED)
set(SOFAPYTHON_DEPENDENCY_INCLUDE_DIR ${SofaGui_INCLUDE_DIRS} ${SofaGeneral_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} )

set(SOFA_HAVE_PYTHON 1)

set(HEADER_FILES

    initSofaPython.h
    ScriptController.h
    PythonScriptController.h
    PythonMacros.h
    PythonEnvironment.h
    Binding.h
    Binding_Base.h
    Binding_SofaModule.h
    Binding_Node.h
    Binding_Context.h
    Binding_BaseContext.h
    Binding_Data.h
    Binding_BaseObject.h
    Binding_BaseState.h
    PythonVisitor.h
    Binding_DisplayFlagsData.h
    ScriptEvent.h
    PythonScriptEvent.h
    Binding_BaseLoader.h
    Binding_MeshLoader.h
    Binding_Vector.h
    Binding_Topology.h
    Binding_BaseMeshTopology.h
    Binding_MeshTopology.h
    Binding_GridTopology.h
    Binding_RegularGridTopology.h
    Binding_BaseMapping.h 
    Binding_MultiMapping.h 
    Binding_SubsetMultiMapping.h 
    Binding_Mapping.h 
    Binding_RigidMapping.h 
    Binding_MechanicalObject.h
    Binding_BaseMechanicalState.h
    Binding_PythonScriptController.h
    Binding_LinearSpring.h
    Binding_VisualModel.h
    SceneLoaderPY.h
    ScriptEnvironment.h
	)

set(SOURCE_FILES

    initSofaPython.cpp
    ScriptController.cpp
    PythonScriptController.cpp
    PythonEnvironment.cpp
    Binding.cpp
    Binding_SofaModule.cpp
    Binding_Base.cpp
    Binding_Context.cpp
    Binding_BaseContext.cpp
    Binding_Node.cpp
    Binding_Data.cpp
    Binding_BaseObject.cpp
    Binding_BaseState.cpp
    PythonMacros.cpp
    PythonVisitor.cpp
    Binding_DisplayFlagsData.cpp
    ScriptEvent.cpp
    PythonScriptEvent.cpp
    Binding_BaseLoader.cpp
    Binding_MeshLoader.cpp
    Binding_Vector.cpp
    Binding_Topology.cpp
    Binding_BaseMeshTopology.cpp
    Binding_MeshTopology.cpp
    Binding_GridTopology.cpp
    Binding_RegularGridTopology.cpp
    Binding_BaseMapping.cpp 
    Binding_MultiMapping.cpp 
    Binding_Mapping.cpp 
    Binding_RigidMapping.cpp 
    Binding_SubsetMultiMapping.cpp 
    Binding_MechanicalObject.cpp
    Binding_BaseMechanicalState.cpp
    Binding_PythonScriptController.cpp
    Binding_LinearSpring.cpp
    Binding_VisualModel.cpp
    SceneLoaderPY.cpp
    ScriptEnvironment.cpp
	)

set(PYTHON_FILES
    SofaPython.py
)

# include python files
include(./python/python.cmake)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/SofaPython.h.in
                ${CMAKE_CURRENT_BINARY_DIR}/sofa/SofaPython.h)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/sofa/SofaPython.h
         DESTINATION "${SOFAPYTHON_INSTALL_INCLUDE_DIR}/sofa")

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} )
target_link_libraries( ${PROJECT_NAME} PUBLIC SofaSimulationCommon SofaUserInteraction SofaGuiCommon SofaComponentMisc SofaComponentGeneral ${PYTHON_LIBRARIES})
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
    # dlopen() is used on Linux for a workaround (see PythonEnvironnement.cpp)
    target_link_libraries(${PROJECT_NAME} PRIVATE dl)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>") 
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>") 
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${SOFAPYTHON_DEPENDENCY_INCLUDE_DIR}>")
set( SOFAPYTHON_COMPILER_FLAGS "-DSOFA_BUILD_SOFAPYTHON")

# The implementation of Python deliberately breaks strict-aliasing rules, so we
# compile with -fno-strict-aliasing to prevent the compiler from relying on
# those rules to optimize the code.
if(${CMAKE_COMPILER_IS_GNUCC})
    set(SOFAPYTHON_COMPILER_FLAGS "${SOFAPYTHON_COMPILER_FLAGS} -fno-strict-aliasing")
endif()
{'fraction_non_alphanumeric': 0.06563004846526656, 'fraction_numerical': 0.0020193861066235864, 'mean_word_length': 4.871369294605809, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3392150', 'n_tokens_mistral': 3668, 'n_tokens_neox': 3311, 'n_words': 518}