diff --git a/CMakeLists.txt b/CMakeLists.txt index acd95f5136..0bc690060a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ if(WIN32) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse") endif() elseif(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch -fvisibility=hidden") if(DEFINED INCLUDE_DEBUG_SYMBOLS AND NOT INCLUDE_DEBUG_SYMBOLS) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Verified for AppleClang, expected to also potentially work (at a later date) for Clang on Linux @@ -55,6 +55,7 @@ if(APPLE) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) endif() +# enable python set(NAP_ENABLE_PYTHON 1) add_definitions(-DNAP_ENABLE_PYTHON) cmake_policy(SET CMP0020 NEW) @@ -66,7 +67,6 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release") # Allow extra Find{project}.cmake files to be found by projects list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") - include(cmake/configure.cmake) include(cmake/cross_context_macros.cmake) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index b7344d1f6c..f15100bac1 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -212,14 +212,18 @@ macro(set_output_directories) endif() endmacro() -# Let find_python find our prepackaged Python in thirdparty. Used before a call to find_package(pybind11) +# Let find_python find our prepackaged Python in thirdparty. +# Used before a call to find_package(pybind11) macro(find_python_in_thirdparty) # Set our pre built Python location if(APPLE) + set(PYTHON_LIB_DIR ${THIRDPARTY_DIR}/python/macos/x86_64/lib) set(PYTHON_EXECUTABLE ${THIRDPARTY_DIR}/python/macos/x86_64/bin/python3) elseif(MSVC) + set(PYTHON_LIB_DIR ${THIRDPARTY_DIR}/python/msvc/x86_64/libs) set(PYTHON_EXECUTABLE ${THIRDPARTY_DIR}/python/msvc/x86_64/python.exe) else() + set(PYTHON_LIB_DIR ${THIRDPARTY_DIR}/python/linux/${ARCH}/lib) set(PYTHON_EXECUTABLE ${THIRDPARTY_DIR}/python/linux/${ARCH}/bin/python3) endif() endmacro() diff --git a/demos/python/CMakeLists.txt b/demos/python/CMakeLists.txt index 37f17ed095..a08ef11761 100644 --- a/demos/python/CMakeLists.txt +++ b/demos/python/CMakeLists.txt @@ -22,4 +22,4 @@ target_link_libraries(${PROJECT_NAME} ${NAP_MODULES}) add_dependencies(${PROJECT_NAME} fbxconverter) # Package into release, export FBX, other shared source project fixes -nap_source_project_packaging_and_shared_postprocessing(TRUE FALSE "demos" TRUE) +nap_source_project_packaging_and_shared_postprocessing(TRUE FALSE "demos" FALSE) diff --git a/dist/cmake/Findnaprtti.cmake b/dist/cmake/Findnaprtti.cmake index b5f70401a2..577c9385ee 100644 --- a/dist/cmake/Findnaprtti.cmake +++ b/dist/cmake/Findnaprtti.cmake @@ -46,6 +46,7 @@ endif() add_library(naprtti INTERFACE) target_link_libraries(naprtti INTERFACE debug ${NAPRTTI_LIBS_DEBUG} RTTR::Core) target_link_libraries(naprtti INTERFACE optimized ${NAPRTTI_LIBS_RELEASE} RTTR::Core) +target_link_directories(naprtti PUBLIC ${PYTHON_LIB_DIR}) set_target_properties(naprtti PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${NAP_ROOT}/include;${pybind11_INCLUDE_DIRS};${RAPIDJSON_INCLUDE_DIRS}") # Show headers in IDE diff --git a/dist/cmake/native/dist_shared_native.cmake b/dist/cmake/native/dist_shared_native.cmake index 88f386548b..9bd2a3d9d5 100644 --- a/dist/cmake/native/dist_shared_native.cmake +++ b/dist/cmake/native/dist_shared_native.cmake @@ -186,11 +186,13 @@ macro(copy_files_to_bin) endmacro() # Set our environment so that find_package finds our pre-packaged Python in thirdparty -macro(find_python_in_thirdparty) +macro(find_python_in_thirdparty) set(PYTHON_PREFIX ${THIRDPARTY_DIR}/python) if(UNIX) + set(PYTHON_LIB_DIR ${PYTHON_PREFIX}/lib) set(PYTHON_EXECUTABLE ${PYTHON_PREFIX}/bin/python3) else() + set(PYTHON_LIB_DIR ${PYTHON_PREFIX}/libs) set(PYTHON_EXECUTABLE ${PYTHON_PREFIX}/python.exe) endif() endmacro() diff --git a/dist/cmake/native/nap_module.cmake b/dist/cmake/native/nap_module.cmake index c68fa474f8..e5dbfdec1b 100644 --- a/dist/cmake/native/nap_module.cmake +++ b/dist/cmake/native/nap_module.cmake @@ -32,14 +32,13 @@ if(NOT MODULE_INTO_PROJ) set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -Wa,-mbig-obj") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse") endif() elseif(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch -fvisibility=hidden") endif() if(APPLE) - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) endif() cmake_policy(SET CMP0020 NEW) diff --git a/dist/cmake/native/nap_project.cmake b/dist/cmake/native/nap_project.cmake index e1423c8acb..b1cfb3f847 100644 --- a/dist/cmake/native/nap_project.cmake +++ b/dist/cmake/native/nap_project.cmake @@ -39,14 +39,13 @@ if (WIN32) set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -Wa,-mbig-obj") -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse") endif() elseif(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-format-security -Wno-switch -fvisibility=hidden" ) endif() if(APPLE) - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) endif() cmake_policy(SET CMP0020 NEW) diff --git a/modules/napimgui/src/imgui/imconfig.h b/modules/napimgui/src/imgui/imconfig.h index d2a1120ee5..6cc27ddb93 100644 --- a/modules/napimgui/src/imgui/imconfig.h +++ b/modules/napimgui/src/imgui/imconfig.h @@ -22,7 +22,7 @@ #define IMGUI_API __declspec(dllimport) // Import the symbols #endif // NAP_SHARED_LIBRARY #else - #define IMGUI_API // Empty statement, does nothing + #define IMGUI_API __attribute__ ((visibility ("default"))) // Export the symbols #endif // _WIN32 //---- Don't define obsolete functions names. Consider enabling from time to time or when updating to reduce like hood of using already obsolete function/names diff --git a/rtti/CMakeLists.txt b/rtti/CMakeLists.txt index 98ba70feee..b4f20e0e6d 100644 --- a/rtti/CMakeLists.txt +++ b/rtti/CMakeLists.txt @@ -10,16 +10,10 @@ set(rapidjson_FIND_QUIETLY TRUE) find_package(rapidjson REQUIRED) add_definitions(-DRAPIDJSON_HAS_STDSTRING=1) -# Let find_python find our prepackaged Python in thirdparty -if (NAP_ENABLE_PYTHON) - find_python_in_thirdparty() - set(pybind11_DIR ${THIRDPARTY_DIR}/pybind11/install/share/cmake/pybind11) - find_package(pybind11 REQUIRED) -endif() - add_platform_specific_files("${WIN32_SOURCES}" "${MACOS_SOURCES}" "${LINUX_SOURCES}") add_library(${PROJECT_NAME} SHARED ${SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER Core) + # Remove lib prefix on Unix libraries set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") @@ -33,8 +27,18 @@ target_include_directories(${PROJECT_NAME} PUBLIC src) target_include_directories(${PROJECT_NAME} PUBLIC ${RAPIDJSON_INCLUDE_DIRS}) if (NAP_ENABLE_PYTHON) + # Find the python interpreter in thirdparty + find_python_in_thirdparty() + + # Find pybind. + # Pybind uses the interpreter to locate the python libraries and includes, next to pybind includes + set(pybind11_DIR ${THIRDPARTY_DIR}/pybind11/install/share/cmake/pybind11) + find_package(pybind11 REQUIRED) + + # Add pybind includes and libraries target_include_directories(${PROJECT_NAME} PUBLIC ${pybind11_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} pybind11::embed) + target_link_directories(${PROJECT_NAME} PUBLIC ${PYTHON_LIB_DIR}) endif() target_link_libraries(${PROJECT_NAME} naputility) diff --git a/utility/src/utility/dllexport.h b/utility/src/utility/dllexport.h index edea2f2a8e..0494c7b9f5 100644 --- a/utility/src/utility/dllexport.h +++ b/utility/src/utility/dllexport.h @@ -17,5 +17,5 @@ #define NAPAPI __declspec(dllimport) // Import the symbols #endif // NAP_SHARED_LIBRARY #else - #define NAPAPI // Empty statement, does nothing + #define NAPAPI __attribute__ ((visibility ("default"))) #endif // _WIN32