Merge branch 'origin/feature/mex_static_module_revive'
parent
e48fa756c0
commit
a16096276a
|
@ -93,7 +93,7 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex
|
||||||
|
|
||||||
# Paths for generated files
|
# Paths for generated files
|
||||||
set(generated_files_path "${PROJECT_BINARY_DIR}/wrap/${moduleName}")
|
set(generated_files_path "${PROJECT_BINARY_DIR}/wrap/${moduleName}")
|
||||||
set(generated_cpp_file "${PROJECT_BINARY_DIR}/wrap/${moduleName}/${moduleName}_wrapper.cpp")
|
set(generated_cpp_file "${generated_files_path}/${moduleName}_wrapper.cpp")
|
||||||
set(compiled_mex_modules_root "${PROJECT_BINARY_DIR}/wrap/${moduleName}_mex")
|
set(compiled_mex_modules_root "${PROJECT_BINARY_DIR}/wrap/${moduleName}_mex")
|
||||||
|
|
||||||
message(STATUS "Building wrap module ${moduleName}")
|
message(STATUS "Building wrap module ${moduleName}")
|
||||||
|
@ -109,24 +109,87 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex
|
||||||
set(matlab_h_path "${installed_includes_path}/wrap")
|
set(matlab_h_path "${installed_includes_path}/wrap")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Add -shared or -static suffix to targets
|
# If building a static mex module, add all cmake-linked libraries to the
|
||||||
|
# explicit link libraries list so that the next block of code can unpack
|
||||||
|
# any static libraries
|
||||||
|
set(automaticDependencies "")
|
||||||
|
foreach(lib ${moduleName} ${linkLibraries})
|
||||||
|
message("MODULE NAME: ${moduleName}")
|
||||||
|
if(TARGET "${lib}")
|
||||||
|
get_target_property(dependentLibraries ${lib} INTERFACE_LINK_LIBRARIES)
|
||||||
|
message("DEPENDENT LIBRARIES: ${dependentLibraries}")
|
||||||
|
if(dependentLibraries)
|
||||||
|
list(APPEND automaticDependencies ${dependentLibraries})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
## CHRIS: START HACK. On my system the get_target_property above returned Not-found for gtsam module
|
||||||
|
## This needs to be fixed!!
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
list(APPEND automaticDependencies ${Boost_SERIALIZATION_LIBRARY_RELEASE} ${Boost_FILESYSTEM_LIBRARY_RELEASE}
|
||||||
|
${Boost_SYSTEM_LIBRARY_RELEASE} ${Boost_THREAD_LIBRARY_RELEASE} ${Boost_DATE_TIME_LIBRARY_RELEASE}
|
||||||
|
${Boost_REGEX_LIBRARY_RELEASE})
|
||||||
|
if(Boost_TIMER_LIBRARY_RELEASE AND NOT GTSAM_DISABLE_NEW_TIMERS) # Only present in Boost >= 1.48.0
|
||||||
|
list(APPEND automaticDependencies ${Boost_TIMER_LIBRARY_RELEASE} ${Boost_CHRONO_LIBRARY_RELEASE})
|
||||||
|
if(GTSAM_MEX_BUILD_STATIC_MODULE)
|
||||||
|
#list(APPEND automaticDependencies -Wl,--no-as-needed -lrt)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message("AUTOMATIC DEPENDENCIES: ${automaticDependencies}")
|
||||||
|
## CHRIS: END HACK
|
||||||
|
|
||||||
|
# Separate dependencies
|
||||||
set(correctedOtherLibraries "")
|
set(correctedOtherLibraries "")
|
||||||
set(otherLibraryTargets "")
|
set(otherLibraryTargets "")
|
||||||
set(otherLibraryNontargets "")
|
set(otherLibraryNontargets "")
|
||||||
foreach(lib ${moduleName} ${linkLibraries})
|
set(otherSourcesAndObjects "")
|
||||||
if(TARGET ${lib})
|
foreach(lib ${moduleName} ${linkLibraries} ${automaticDependencies})
|
||||||
|
if(TARGET "${lib}")
|
||||||
|
if(GTSAM_MEX_BUILD_STATIC_MODULE)
|
||||||
|
get_target_property(target_sources ${lib} SOURCES)
|
||||||
|
list(APPEND otherSourcesAndObjects ${target_sources})
|
||||||
|
else()
|
||||||
list(APPEND correctedOtherLibraries ${lib})
|
list(APPEND correctedOtherLibraries ${lib})
|
||||||
list(APPEND otherLibraryTargets ${lib})
|
list(APPEND otherLibraryTargets ${lib})
|
||||||
elseif(TARGET ${lib}-shared) # Prefer the shared library if we have both shared and static)
|
endif()
|
||||||
list(APPEND correctedOtherLibraries ${lib}-shared)
|
else()
|
||||||
list(APPEND otherLibraryTargets ${lib}-shared)
|
get_filename_component(file_extension "${lib}" EXT)
|
||||||
elseif(TARGET ${lib}-static)
|
get_filename_component(lib_name "${lib}" NAME_WE)
|
||||||
list(APPEND correctedOtherLibraries ${lib}-static)
|
if(file_extension STREQUAL ".a" AND GTSAM_MEX_BUILD_STATIC_MODULE)
|
||||||
list(APPEND otherLibraryTargets ${lib}-static)
|
# For building a static MEX module, unpack the static library
|
||||||
|
# and compile its object files into our module
|
||||||
|
file(MAKE_DIRECTORY "${generated_files_path}/${lib_name}_objects")
|
||||||
|
execute_process(COMMAND ar -x "${lib}"
|
||||||
|
WORKING_DIRECTORY "${generated_files_path}/${lib_name}_objects"
|
||||||
|
RESULT_VARIABLE ar_result)
|
||||||
|
if(NOT ar_result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Failed extracting ${lib}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Get list of object files
|
||||||
|
execute_process(COMMAND ar -t "${lib}"
|
||||||
|
OUTPUT_VARIABLE object_files
|
||||||
|
RESULT_VARIABLE ar_result)
|
||||||
|
if(NOT ar_result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Failed listing ${lib}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add directory to object files
|
||||||
|
string(REPLACE "\n" ";" object_files_list "${object_files}")
|
||||||
|
foreach(object_file ${object_files_list})
|
||||||
|
get_filename_component(file_extension "${object_file}" EXT)
|
||||||
|
if(file_extension STREQUAL ".o")
|
||||||
|
list(APPEND otherSourcesAndObjects "${generated_files_path}/${lib_name}_objects/${object_file}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
else()
|
else()
|
||||||
list(APPEND correctedOtherLibraries ${lib})
|
list(APPEND correctedOtherLibraries ${lib})
|
||||||
list(APPEND otherLibraryNontargets ${lib})
|
list(APPEND otherLibraryNontargets ${lib})
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Check libraries for conflicting versions built-in to MATLAB
|
# Check libraries for conflicting versions built-in to MATLAB
|
||||||
|
@ -144,7 +207,7 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex
|
||||||
file(MAKE_DIRECTORY "${generated_files_path}")
|
file(MAKE_DIRECTORY "${generated_files_path}")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${generated_cpp_file}
|
OUTPUT ${generated_cpp_file}
|
||||||
DEPENDS ${interfaceHeader} wrap ${module_library_target} ${otherLibraryTargets}
|
DEPENDS ${interfaceHeader} wrap ${module_library_target} ${otherLibraryTargets} ${otherSourcesAndObjects}
|
||||||
COMMAND
|
COMMAND
|
||||||
wrap
|
wrap
|
||||||
${modulePath}
|
${modulePath}
|
||||||
|
@ -157,7 +220,7 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex
|
||||||
# Set up building of mex module
|
# Set up building of mex module
|
||||||
string(REPLACE ";" " " extraMexFlagsSpaced "${extraMexFlags}")
|
string(REPLACE ";" " " extraMexFlagsSpaced "${extraMexFlags}")
|
||||||
string(REPLACE ";" " " mexFlagsSpaced "${GTSAM_BUILD_MEX_BINARY_FLAGS}")
|
string(REPLACE ";" " " mexFlagsSpaced "${GTSAM_BUILD_MEX_BINARY_FLAGS}")
|
||||||
add_library(${moduleName}_wrapper MODULE ${generated_cpp_file} ${interfaceHeader})
|
add_library(${moduleName}_wrapper MODULE ${generated_cpp_file} ${interfaceHeader} ${otherSourcesAndObjects})
|
||||||
target_link_libraries(${moduleName}_wrapper ${correctedOtherLibraries})
|
target_link_libraries(${moduleName}_wrapper ${correctedOtherLibraries})
|
||||||
set_target_properties(${moduleName}_wrapper PROPERTIES
|
set_target_properties(${moduleName}_wrapper PROPERTIES
|
||||||
OUTPUT_NAME "${moduleName}_wrapper"
|
OUTPUT_NAME "${moduleName}_wrapper"
|
||||||
|
|
|
@ -33,28 +33,32 @@ fi
|
||||||
|
|
||||||
# Run cmake
|
# Run cmake
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release \
|
cmake -DCMAKE_BUILD_TYPE=Release \
|
||||||
-DGTSAM_INSTALL_MATLAB_TOOLBOX:bool=true \
|
-DGTSAM_INSTALL_MATLAB_TOOLBOX:BOOL=ON \
|
||||||
-DCMAKE_INSTALL_PREFIX="$PWD/stage" \
|
-DCMAKE_INSTALL_PREFIX="$PWD/stage" \
|
||||||
-DBoost_NO_SYSTEM_PATHS:bool=true \
|
-DBoost_NO_SYSTEM_PATHS:BOOL=ON \
|
||||||
-DBoost_USE_STATIC_LIBS:bool=true \
|
-DBoost_USE_STATIC_LIBS:BOOL=ON \
|
||||||
-DBOOST_ROOT="$1" \
|
-DBOOST_ROOT="$1" \
|
||||||
-DGTSAM_BUILD_SHARED_LIBRARY:bool=false \
|
-DGTSAM_BUILD_TESTS:BOOL=OFF \
|
||||||
-DGTSAM_BUILD_STATIC_LIBRARY:bool=true \
|
-DGTSAM_BUILD_TIMING:BOOL=OFF \
|
||||||
-DGTSAM_BUILD_TESTS:bool=false \
|
-DGTSAM_BUILD_EXAMPLES_ALWAYS:BOOL=OFF \
|
||||||
-DGTSAM_BUILD_EXAMPLES:bool=false \
|
-DGTSAM_WITH_TBB:BOOL=OFF \
|
||||||
-DGTSAM_BUILD_UNSTABLE:bool=false \
|
-DGTSAM_BUILD_METIS:BOOL=OFF \
|
||||||
-DGTSAM_DISABLE_EXAMPLES_ON_INSTALL:bool=true \
|
-DGTSAM_INSTALL_GEOGRAPHICLIB:BOOL=OFF \
|
||||||
-DGTSAM_DISABLE_TESTS_ON_INSTALL:bool=true \
|
-DGTSAM_BUILD_UNSTABLE:BOOL=OFF \
|
||||||
-DGTSAM_BUILD_CONVENIENCE_LIBRARIES:bool=false \
|
-DGTSAM_MEX_BUILD_STATIC_MODULE:BOOL=ON ..
|
||||||
-DGTSAM_MEX_BUILD_STATIC_MODULE:bool=true ..
|
|
||||||
|
|
||||||
if [ ! $? ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "CMake failed"
|
echo "CMake failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compile
|
# Compile
|
||||||
make -j4 install
|
make -j8 install
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Compile failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create package
|
# Create package
|
||||||
tar czf gtsam-toolbox-2.3.0-$platform.tgz -C stage/borg toolbox
|
tar czf gtsam-toolbox-3.0.0-$platform.tgz -C stage/gtsam_toolbox toolbox
|
||||||
|
|
Loading…
Reference in New Issue