FEM Post: Give access to cmake BUILD variables from python

This commit adds a attribute __cmake__ to App which is a list holding all compile time cmake variables starting with BUILD.

Only export BUILD variables
This commit is contained in:
Stefan Tröger 2016-02-27 11:23:24 +01:00 committed by wmayer
parent 9c61e2f386
commit 3bf749f0fd
4 changed files with 272 additions and 0 deletions

View File

@ -129,6 +129,7 @@ using namespace boost::program_options;
// scriptings (scripts are build in but can be overridden by command line option)
#include "InitScript.h"
#include "TestScript.h"
#include "CMakeScript.h"
#ifdef _MSC_VER // New handler for Microsoft Visual C++ compiler
# include <new.h>
@ -1292,6 +1293,7 @@ void Application::initApplication(void)
{
// interpreter and Init script ==========================================================
// register scripts
new ScriptProducer( "CMakeVariables", CMakeVariables );
new ScriptProducer( "FreeCADInit", FreeCADInit );
new ScriptProducer( "FreeCADTest", FreeCADTest );
@ -1310,6 +1312,7 @@ void Application::initApplication(void)
// starting the init script
Console().Log("Run App init script\n");
Interpreter().runString(Base::ScriptFactory().ProduceScript("CMakeVariables"));
Interpreter().runString(Base::ScriptFactory().ProduceScript("FreeCADInit"));
}

View File

@ -14,6 +14,25 @@ ENDIF(DOCDIR)
add_definitions(-DBOOST_${Boost_VERSION})
#write relevant cmake variables to a file for later access with python. Exportet are all variables
#starting with BUILD. As the variable only exists if the user set it to ON a dict is useless, we
#use a python list for export.
set(_vars "const char CMakeVariables[] =\"cmake = [")
set(_delim "")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
if (${_variableName})
STRING(REGEX MATCH "^[_]?[^_]*" _prefix "${_variableName}_")
if(${_prefix} STREQUAL "BUILD")
STRING(REPLACE "\\" "\\\\" _name ${_variableName})
set(_vars "${_vars}${_delim}\\n\"\n\"\\\"${_name}\\\"")
set(_delim ",")
endif()
endif ()
endforeach()
set(_vars "${_vars}]\\n\" \n;")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeScript.h "${_vars}" )
include_directories(
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src

247
src/App/CMakeLists.txt.orig Normal file
View File

@ -0,0 +1,247 @@
if(WIN32)
add_definitions(-DFCApp)
add_definitions(-DBOOST_DYN_LINK)
endif(WIN32)
# This causes some problems with the resource files to be found, especially with the StartPage
IF(RESOURCEDIR)
add_definitions(-DRESOURCEDIR="${RESOURCEDIR}")
ENDIF(RESOURCEDIR)
IF(DOCDIR)
add_definitions(-DDOCDIR="${DOCDIR}")
ENDIF(DOCDIR)
<<<<<<< 99c1373c94c4a8d3efa0cc0f558a8e523389a501
add_definitions(-DBOOST_${Boost_VERSION})
=======
#write relevant cmake variables to a file for later access with python. Exportet are all variables
#starting with BUILD. As the variable only exists if the user set it to ON a dict is useless, we
#use a python list for export.
set(_vars "const char CMakeVariables[] =\"cmake = [")
set(_delim "")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
if (${_variableName})
STRING(REGEX MATCH "^[_]?[^_]*" _prefix "${_variableName}_")
if(${_prefix} STREQUAL "BUILD")
STRING(REPLACE "\\" "\\\\" _name ${_variableName})
set(_vars "${_vars}${_delim}\\n\"\n\"\\\"${_name}\\\"")
set(_delim ",")
endif()
endif ()
endforeach()
set(_vars "${_vars}]\\n\" \n;")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeScript.h "${_vars}" )
>>>>>>> Give access to cmake BUILD variables from python
include_directories(
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}
${QT_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
)
set(FreeCADApp_LIBS
FreeCADBase
${Boost_LIBRARIES}
${QT_QTCORE_LIBRARY}
${QT_QTXML_LIBRARY}
)
generate_from_xml(DocumentPy)
generate_from_xml(DocumentObjectPy)
generate_from_xml(DocumentObjectGroupPy)
generate_from_xml(GeoFeaturePy)
generate_from_xml(GeoFeatureGroupPy)
generate_from_xml(OriginGroupPy)
generate_from_xml(PartPy)
generate_from_xml(ComplexGeoDataPy)
generate_from_xml(PropertyContainerPy)
generate_from_xml(MaterialPy)
generate_from_py(FreeCADInit InitScript.h)
generate_from_py(FreeCADTest TestScript.h)
SET(FreeCADApp_XML_SRCS
DocumentObjectGroupPy.xml
DocumentObjectPy.xml
GeoFeaturePy.xml
GeoFeatureGroupPy.xml
OriginGroupPy.xml
PartPy.xml
DocumentPy.xml
PropertyContainerPy.xml
ComplexGeoDataPy.xml
MaterialPy.xml
)
SOURCE_GROUP("XML" FILES ${FreeCADApp_XML_SRCS})
# The document stuff
SET(Document_CPP_SRCS
Annotation.cpp
Document.cpp
DocumentObject.cpp
DocumentObjectFileIncluded.cpp
DocumentObjectGroup.cpp
DocumentObjectGroupPyImp.cpp
GeoFeaturePyImp.cpp
DocumentObjectPyImp.cpp
DocumentObserver.cpp
DocumentObserverPython.cpp
DocumentPyImp.cpp
Expression.cpp
FeaturePython.cpp
FeatureTest.cpp
GeoFeature.cpp
GeoFeatureGroupPyImp.cpp
GeoFeatureGroup.cpp
OriginGroupPyImp.cpp
OriginGroup.cpp
PartPyImp.cpp
Part.cpp
Origin.cpp
Path.cpp
InventorObject.cpp
MeasureDistance.cpp
Placement.cpp
OriginFeature.cpp
Range.cpp
Transactions.cpp
VRMLObject.cpp
MaterialObject.cpp
MergeDocuments.cpp
)
SET(Document_HPP_SRCS
Annotation.h
Document.h
DocumentObject.h
DocumentObjectFileIncluded.h
DocumentObjectGroup.h
DocumentObserver.h
DocumentObserverPython.h
Expression.h
ExpressionVisitors.h
FeatureCustom.h
FeaturePython.h
FeaturePythonPyImp.h
FeaturePythonPyImp.inl
FeatureTest.h
GeoFeature.h
GeoFeatureGroup.h
OriginGroup.h
Part.h
Origin.h
Path.h
InventorObject.h
MeasureDistance.h
Placement.h
OriginFeature.h
Range.h
Transactions.h
VRMLObject.h
MaterialObject.h
MergeDocuments.h
)
SET(Document_SRCS
${Document_CPP_SRCS}
${Document_HPP_SRCS}
)
SOURCE_GROUP("Document" FILES ${Document_SRCS})
# The property stuff
SET(Properties_CPP_SRCS
DynamicProperty.cpp
ObjectIdentifier.cpp
Property.cpp
PropertyContainer.cpp
PropertyContainerPyImp.cpp
PropertyFile.cpp
PropertyGeo.cpp
PropertyLinks.cpp
PropertyPythonObject.cpp
PropertyStandard.cpp
PropertyUnits.cpp
PropertyExpressionEngine.cpp
)
SET(Properties_HPP_SRCS
DynamicProperty.h
ObjectIdentifier.h
Property.h
PropertyContainer.h
PropertyFile.h
PropertyGeo.h
PropertyLinks.h
PropertyPythonObject.h
PropertyStandard.h
PropertyUnits.h
PropertyExpressionEngine.h
)
SET(Properties_SRCS
${Properties_CPP_SRCS}
${Properties_HPP_SRCS}
)
SOURCE_GROUP("Properties" FILES ${Properties_SRCS})
SET(FreeCADApp_CPP_SRCS
${Document_CPP_SRCS}
${Properties_CPP_SRCS}
Application.cpp
ApplicationPy.cpp
Branding.cpp
ColorModel.cpp
ComplexGeoData.cpp
ComplexGeoDataPyImp.cpp
Enumeration.cpp
Material.cpp
MaterialPyImp.cpp
)
SET(FreeCADApp_HPP_SRCS
${Document_HPP_SRCS}
${Properties_HPP_SRCS}
Application.h
Branding.h
ColorModel.h
ComplexGeoData.h
Enumeration.h
Material.h
)
SET(FreeCADApp_SRCS
${FreeCADApp_CPP_SRCS}
${FreeCADApp_HPP_SRCS}
${FreeCADApp_XML_SRCS}
FreeCADInit.py
FreeCADTest.py
PreCompiled.cpp
PreCompiled.h
)
if(MSVC)
add_definitions(-D_PreComp_)
ADD_MSVC_PRECOMPILED_HEADER(FreeCADApp PreCompiled.h PreCompiled.cpp FreeCADApp_CPP_SRCS)
endif(MSVC)
add_library(FreeCADApp SHARED ${FreeCADApp_SRCS})
target_link_libraries(FreeCADApp ${FreeCADApp_LIBS})
SET_BIN_DIR(FreeCADApp FreeCADApp)
if(WIN32)
INSTALL(TARGETS FreeCADApp
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
else(WIN32)
INSTALL(TARGETS FreeCADApp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif(WIN32)

View File

@ -150,6 +150,9 @@ Err = FreeCAD.Console.PrintError
Wrn = FreeCAD.Console.PrintWarning
test_ascii = lambda s: all(ord(c) < 128 for c in s)
#store the cmake variales
App.__cmake__ = cmake;
Log ('Init: starting App::FreeCADInit.py\n')
# init every application by importing Init.py