Skip to content

Commit 812d89e

Browse files
author
Alexander Widerberg
committed
Fix shared builds to not need global symbol visibility. Also added example of cpack to package mac applications
1 parent fb05ce0 commit 812d89e

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

example/example-lib/CMakeLists.txt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ set(HEADERS
5757
# Library
5858
if(BUILD_SHARED)
5959
add_library (example SHARED ${SOURCES} ${HEADERS})
60+
target_compile_definitions(example PUBLIC IS_BUILDING_SHARED)
6061
message(STATUS "Building shared version...")
6162
else()
6263
add_library (example STATIC ${SOURCES} ${HEADERS})
@@ -69,14 +70,44 @@ endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
6970

7071
# Executable
7172
if(PLATFORM MATCHES "MAC.*")
72-
add_executable (helloworld main.cpp)
73+
set(APP_NAME TestApp)
74+
add_executable (${APP_NAME} MACOSX_BUNDLE main.cpp)
75+
set_target_properties(${APP_NAME} PROPERTIES
76+
BUNDLE True
77+
MACOSX_BUNDLE_GUI_IDENTIFIER leetal.com.helloworld
78+
MACOSX_BUNDLE_BUNDLE_NAME helloworld
79+
MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
80+
MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1"
81+
)
7382
# Link the library with the executable
74-
target_link_libraries(helloworld example)
83+
target_link_libraries(${APP_NAME} example)
7584
endif()
7685

7786
# Debug symbols set in XCode project
7887
set_xcode_property(example GCC_GENERATE_DEBUGGING_SYMBOLS YES "All")
7988

8089
# Installation
81-
install (TARGETS example DESTINATION lib)
90+
if(PLATFORM MATCHES "MAC.*")
91+
install(TARGETS ${APP_NAME}
92+
BUNDLE DESTINATION . COMPONENT Runtime
93+
RUNTIME DESTINATION bin COMPONENT Runtime
94+
LIBRARY DESTINATION lib
95+
ARCHIVE DESTINATION lib/static)
96+
97+
# Note Mac specific extension .app
98+
set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app")
99+
100+
# Directories to look for dependencies
101+
set(DIRS ${CMAKE_BINARY_DIR})
102+
103+
install(CODE "include(BundleUtilities)
104+
fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")")
105+
106+
set(CPACK_GENERATOR "DRAGNDROP")
107+
include(CPack)
108+
else()
109+
install(TARGETS example
110+
LIBRARY DESTINATION lib
111+
ARCHIVE DESTINATION lib/static)
112+
endif()
82113
install (FILES ${HEADERS} DESTINATION include)

example/example-lib/HelloWorld.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#pragma once
22
#include <string>
33

4-
class HelloWorld
4+
#if defined(__clang__)
5+
#define SHARED_EXPORT __attribute__((visibility("default")))
6+
#define SHARED_LOCAL __attribute__((visibility("hidden")))
7+
#endif
8+
9+
#if defined(IS_BUILDING_SHARED)
10+
#define API SHARED_EXPORT
11+
#else
12+
#define API
13+
#endif
14+
15+
class API HelloWorld
516
{
617
public:
718
std::string helloWorld();

0 commit comments

Comments
 (0)