Skip to content

Commit

Permalink
don't export symbols for Clang & GCC by default, use the NAPAPI to se…
Browse files Browse the repository at this point in the history
…lectively export instead. Also fixes pybind exposure issue.
  • Loading branch information
cklosters committed Jul 12, 2022
1 parent d7c2ed9 commit 31dbb63
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion demos/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions dist/cmake/Findnaprtti.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion dist/cmake/native/dist_shared_native.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions dist/cmake/native/nap_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions dist/cmake/native/nap_project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/napimgui/src/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions rtti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utility/src/utility/dllexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 31dbb63

Please sign in to comment.