Skip to content

Commit

Permalink
Try building nupic_core_solo intermediate static library without spec…
Browse files Browse the repository at this point in the history
…ifying system libraries. It's a static library and shouldn't need additional linking information.
  • Loading branch information
Vitaly Kruglikov committed Aug 10, 2016
1 parent 0851aa0 commit 3e82745
Showing 1 changed file with 55 additions and 66 deletions.
121 changes: 55 additions & 66 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ set(src_capnp_specs_rel
nupic/proto/VectorFileSensorProto.capnp
)

# TODO it might be cleaner to abstract the building of src_capnp_specs, etc.
# within the implementation of function CREATE_CAPNPC_COMMAND in
# external/CapnpProto.cmake, which would use an output variable to return the
# contents of src_capnp_generated_srcs for linking. These details are very
# specific to capnproto and CapnpProto.cmake is our capnrpoto build abstraction.
# TODO it might be cleaner to abstract the generation of src_capnp_specs,
# src_capnp_hdrs, and src_capnp_generated_srcs within the implementation of
# function CREATE_CAPNPC_COMMAND in external/CapnpProto.cmake, which would use
# an output variable to return the contents of src_capnp_generated_srcs for
# linking. These details are very specific to capnproto and CapnpProto.cmake is
# our capnrpoto build abstraction.
foreach(spec ${src_capnp_specs_rel})
list(APPEND src_capnp_specs ${PROJECT_SOURCE_DIR}/${spec})
list(APPEND src_capnp_hdrs ${PROJECT_BINARY_DIR}/${spec}.h)
Expand All @@ -246,19 +247,14 @@ set(src_py_support_files
nupic/py_support/PyCapnp.cpp
nupic/bindings/PySparseTensor.cpp
)
if(NOT "${PLATFORM}" STREQUAL "windows")
list(APPEND src_py_support_files nupic/py_support/CapnpToPycapnp.cpp)
endif()

message(STATUS "CAPNP_EXECUTABLE = ${CAPNP_EXECUTABLE}")
message(STATUS "CAPNP_CMAKE_DEFINITIONS = ${CAPNP_CMAKE_DEFINITIONS}")
message(STATUS "CAPNP_INCLUDE_DIRS = ${CAPNP_INCLUDE_DIRS}")
message(STATUS "CAPNP_LINK_LIBRARIES = ${CAPNP_LINK_LIBRARIES}")

#
# Add the pycapnp Python package headers to includes
# Add pycapnp support
#
if(NOT "${PLATFORM}" STREQUAL "windows")
list(APPEND src_py_support_files nupic/py_support/CapnpToPycapnp.cpp)

# Add the pycapnp Python package headers to includes
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import capnp; import os; import sys; sys.stdout.write(os.path.dirname(os.path.dirname(capnp.__file__)))"
Expand All @@ -268,16 +264,15 @@ if(NOT "${PLATFORM}" STREQUAL "windows")
include_directories(SYSTEM ${src_pycapnp_include_dir})
endif()

message(STATUS "CAPNP_EXECUTABLE = ${CAPNP_EXECUTABLE}")
message(STATUS "CAPNP_CMAKE_DEFINITIONS = ${CAPNP_CMAKE_DEFINITIONS}")
message(STATUS "CAPNP_INCLUDE_DIRS = ${CAPNP_INCLUDE_DIRS}")
message(STATUS "CAPNP_LINK_LIBRARIES = ${CAPNP_LINK_LIBRARIES}")


#
# Setup nupic_core_solo static library, consisting of our own sources;
#
# this is an intermediate archive that will be merged with external static
# libraries in a subsequent step to produce the nupic_core "combined" static
# library.
# Common system libraries for shared libraries and executables
#
set(src_lib_static_nupiccore_solo nupic_core_solo)

set(src_common_os_libs)

if("${PLATFORM}" STREQUAL "linux")
Expand All @@ -290,6 +285,18 @@ elseif("${PLATFORM}" STREQUAL "windows")
list(APPEND src_common_os_libs oldnames.lib psapi.lib ws2_32.lib)
endif()

message(STATUS "src_common_os_libs = ${src_common_os_libs}")


#
# Setup nupic_core_solo static library, consisting of our own sources;
#
# this is an intermediate archive that will be merged with external static
# libraries in a subsequent step to produce the nupic_core "combined" static
# library.
#
set(src_lib_static_nupiccore_solo nupic_core_solo)

set(src_nupiccore_srcs
nupic/algorithms/Anomaly.cpp
nupic/algorithms/BitHistory.cpp
Expand Down Expand Up @@ -369,20 +376,16 @@ set(src_lib_static_nupiccore_srcs
${src_py_support_files}
${src_nupiccore_srcs})

set(src_lib_static_nupiccore_solo_link_libs ${src_common_os_libs})
#set(src_lib_static_nupiccore_solo_link_libs ${src_common_os_libs})
set(src_lib_static_nupiccore_solo_link_libs)

set(src_lib_static_nupiccore_solo_deps capnp_specs)

set(src_lib_static_nupiccore_compile_flags
"${src_compile_flags} -I${src_numpy_core}/include")
# TODO Does the static library nupiccore_solo need the flags from
# INTERNAL_LINKER_FLAGS_OPTIMIZED? Static libraries don't get linked, do they?
#set(src_lib_static_nupiccore_link_flags
# "${INTERNAL_LINKER_FLAGS_OPTIMIZED} -static")

message(STATUS "src_compile_flags = ${src_compile_flags}")
message(STATUS "src_lib_static_nupiccore_compile_flags = ${src_lib_static_nupiccore_compile_flags}")
#message(STATUS "src_lib_static_nupiccore_link_flags = ${src_lib_static_nupiccore_link_flags}")
message(STATUS "src_lib_static_nupiccore_solo_link_libs = ${src_lib_static_nupiccore_solo_link_libs}")

add_library(${src_lib_static_nupiccore_solo} STATIC
Expand All @@ -393,8 +396,6 @@ target_link_libraries(${src_lib_static_nupiccore_solo}
${src_lib_static_nupiccore_solo_link_libs})
set_target_properties(${src_lib_static_nupiccore_solo} PROPERTIES COMPILE_FLAGS
${src_lib_static_nupiccore_compile_flags})
#set_target_properties(${src_lib_static_nupiccore_solo} PROPERTIES LINK_FLAGS
# ${src_lib_static_nupiccore_link_flags})
if(${NUPIC_IWYU})
# TODO: Create a target that doesn't include the generated capnp schema files
# since we don't want to run iwyu on them and iwyu can only be applied to
Expand Down Expand Up @@ -506,12 +507,13 @@ endif()
# Build tests of the nupic_core "combined" static library
#

# Common libs for test executables;
# Common libs for test executables
set(src_common_test_exe_libs
${src_lib_static_nupiccore_combined}
${PYTHON_LIBRARIES})
${PYTHON_LIBRARIES}
${src_common_os_libs})

# Common dependencies for test executables
# Extra dependencies for test executables
set(src_common_test_exe_deps)

# Add capnproto static libs to our C/C++ test apps when building python
Expand All @@ -528,9 +530,7 @@ endif() # ${NUPIC_BUILD_PYEXT_MODULES}
#
set(src_executable_cppregiontest cpp_region_test)
add_executable(${src_executable_cppregiontest} test/integration/CppRegionTest.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_cppregiontest} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_cppregiontest} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_cppregiontest} ${src_common_test_exe_libs})
set_target_properties(${src_executable_cppregiontest} PROPERTIES COMPILE_FLAGS ${src_compile_flags})
set_target_properties(${src_executable_cppregiontest} PROPERTIES LINK_FLAGS "${INTERNAL_LINKER_FLAGS_OPTIMIZED}")
Expand All @@ -545,9 +545,7 @@ add_custom_target(tests_cpp_region
#
set(src_executable_pyregiontest py_region_test)
add_executable(${src_executable_pyregiontest} test/integration/PyRegionTest.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_pyregiontest} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_pyregiontest} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_pyregiontest} ${src_common_test_exe_libs})
set_target_properties(${src_executable_pyregiontest}
PROPERTIES COMPILE_FLAGS ${src_compile_flags})
Expand All @@ -565,10 +563,8 @@ add_custom_target(tests_py_region
set(src_executable_connectionsperformancetest connections_performance_test)
add_executable(${src_executable_connectionsperformancetest}
test/integration/ConnectionsPerformanceTest.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_connectionsperformancetest}
${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_connectionsperformancetest}
${src_common_test_exe_deps})
target_link_libraries(${src_executable_connectionsperformancetest}
${src_common_test_exe_libs})
set_target_properties(${src_executable_connectionsperformancetest}
Expand All @@ -586,9 +582,7 @@ add_custom_target(tests_connections_performance
#
set(src_executable_helloregion helloregion)
add_executable(${src_executable_helloregion} examples/regions/HelloRegions.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_helloregion} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_helloregion} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_helloregion} ${src_common_test_exe_libs})
set_target_properties(${src_executable_helloregion}
PROPERTIES COMPILE_FLAGS ${src_compile_flags})
Expand All @@ -600,9 +594,7 @@ set_target_properties(${src_executable_helloregion}
#
set(src_executable_prototest prototest)
add_executable(${src_executable_prototest} examples/prototest.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_prototest} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_prototest} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_prototest} ${src_common_test_exe_libs})
set_target_properties(${src_executable_prototest}
PROPERTIES COMPILE_FLAGS ${src_compile_flags})
Expand All @@ -614,9 +606,7 @@ set_target_properties(${src_executable_prototest}
#
set(src_executable_hellosptp hello_sp_tp)
add_executable(${src_executable_hellosptp} examples/algorithms/HelloSP_TP.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_hellosptp} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_hellosptp} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_hellosptp} ${src_common_test_exe_libs})
set_target_properties(${src_executable_hellosptp}
PROPERTIES COMPILE_FLAGS ${src_compile_flags})
Expand Down Expand Up @@ -678,9 +668,7 @@ add_executable(${src_executable_gtests}
test/unit/utils/MovingAverageTest.cpp
test/unit/utils/RandomTest.cpp
test/unit/utils/WatcherTest.cpp)
if (src_common_test_exe_deps)
add_dependencies(${src_executable_gtests} ${src_common_test_exe_deps})
endif()
add_dependencies(${src_executable_gtests} ${src_common_test_exe_deps})
target_link_libraries(${src_executable_gtests}
${src_lib_static_gtest}
${src_common_test_exe_libs})
Expand Down Expand Up @@ -766,20 +754,21 @@ if (${NUPIC_BUILD_PYEXT_MODULES})
# Set up linker flags for python extension shared libraries
set(src_swig_extension_link_flags "${PYEXT_LINKER_FLAGS_OPTIMIZED}")

# NOTE Python extensions shouldn't be linking agains libpython; symbols should
# be available automatically when python loads the extension.
# NOTE Non-Windows Python extensions shouldn't be linking agains libpython;
# symbols should be available automatically when python loads the extension.
#
# NOTE We don't link our non-windows python extensions with capnproto static libs to force
# dynamic linkage to pycapnp's capnp symbols at nupic.bindings load-time and
# avoid the conflict of executing the methods in our own compilation of
# capnproto (different compiler/STL/version, flags, etc.) on objects created by
# pycapnp's. Instead, we force dynamic linkage to pycapnp's capnproto symbols
# by preloading the pycapnp extension in our extension python proxy modules, thus avoiding the conflict from
# executing the methods in our own compilation of capnproto (different compiler,
# flags, etc.) on objects created by pycapnp's.
# NOTE We don't link our non-Windows python extensions with capnproto static
# libs to force runtime linkage to pycapnp's capnproto symbols in order to
# avoid the conflict of executing the methods in our own
# compilation of capnproto (different compiler/STL/version, flags, etc.) on
# objects created by pycapnp's. Instead, we force dynamic linkage to pycapnp's
# capnproto symbols by preloading the pycapnp extension in our extension
# python proxy modules, thus avoiding the conflict from executing the methods
# in our own compilation of capnproto (different compiler, flags, etc.) on
# objects created by pycapnp's.
set(src_swig_link_libraries
${src_common_os_libs}
${src_lib_static_nupiccore_combined})
${src_lib_static_nupiccore_combined}
${src_common_os_libs})

# Common dependencies for our python extensions for use with
# SWIG_MODULE_name_EXTRA_DEPS
Expand Down

0 comments on commit 3e82745

Please sign in to comment.