-
Notifications
You must be signed in to change notification settings - Fork 418
feat: improved library build system when building as third party #2298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
c6e3308
1dfe1e7
2edadfc
26de75c
c261784
419d860
960148c
d9a96d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,8 @@ foreach(source ${templates}) | |
| endforeach() | ||
|
|
||
| add_library(idl SHARED ${headers} ${sources}) | ||
| add_library(${PROJECT_NAME}::idl ALIAS idl) | ||
| target_compile_definitions(idl PRIVATE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:DDS_STATIC_DEFINE>) | ||
|
|
||
| if(MSVC) | ||
| # ignore warning 5286 and 5287 about enum type conversion | ||
|
|
@@ -163,11 +165,16 @@ set_target_properties( | |
| idl PROPERTIES | ||
| OUTPUT_NAME "cycloneddsidl" | ||
| VERSION ${PROJECT_VERSION} | ||
| SOVERSION ${PROJECT_VERSION_MAJOR}) | ||
| SOVERSION ${PROJECT_VERSION_MAJOR} | ||
| POSITION_INDEPENDENT_CODE ON) | ||
|
|
||
| generate_export_header(idl EXPORT_FILE_NAME include/idl/export.h) | ||
|
|
||
| target_link_libraries(idl PUBLIC ddsc) | ||
| target_link_libraries(idl | ||
| PUBLIC | ||
| ${PROJECT_NAME}::ddsc | ||
| $<$<NOT:$<STREQUAL:"${CMAKE_PROJECT_NAME}","CycloneDDS">>:${PROJECT_NAME}::cdr> | ||
|
||
| ) | ||
|
|
||
| target_include_directories( | ||
| idl | ||
|
|
@@ -194,7 +201,7 @@ install( | |
|
|
||
| install( | ||
| TARGETS idl | ||
| EXPORT "${CMAKE_PROJECT_NAME}" | ||
| EXPORT "${PROJECT_NAME}" | ||
| RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT lib | ||
| LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib | ||
| ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this force position independent code always? I remember trying to set it to
ONand running into a problem. I think it was the one mentioned here:cyclonedds/CMakeLists.txt
Line 33 in 518c546
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property will set position indipendent code only for the DDSC target (and, in a future commit, also for CDR). I had to enable it due to relocation issues happening when building CycloneDDS as a static library on linux.
Specifically the errors were:
tsd_thread_statefrom ddsi_thread.c. Fixed by adding POSITION_INDEPENDENT_CODE property on DDSC targetddsrt_hh_emptyfrom dds_cdrstream.c. Fixed by adding POSITION_INDEPENDENT_CODE property on CDR targetSeeing the shared nature of the project and the many relocation issues, I suggest to directly set CMAKE_POSITION_INDEPENDENT_CODE=ON whenever the library is built with BUILD_SHARED_LIBS=ON.
Further tests with this setting on Windows Environment are required though.