View Issue Details

IDProjectCategoryView StatusLast Update
0015712ScribusBuild Systempublic2019-07-16 12:34
Reporterale Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version1.5.5.svn 
Summary0015712: CMake: document how to create tools or library that are in their own directory
Descriptionas previously discussed, i'm trying to recreate the higher level API without making it a plugin, but still putting it in its own directory.

the goal is to create a directory with its own CMakeLists.txt file.

i've based the code on the text/ directory and while it compiles and links without any error, at run time i get a "symbol missing" error for the class functions that have their body defined in the .cpp files.

for the API, these are the modifications i've made to the CMakeLists.txt in the scribus/ directory:

diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt
index 76c73e3db..ca2e66242 100644
--- a/scribus/CMakeLists.txt
+++ b/scribus/CMakeLists.txt
@@ -30,6 +30,7 @@ add_subdirectory(desaxe)
 add_subdirectory(fonts)
 add_subdirectory(styles)
 add_subdirectory(text)
+add_subdirectory(api)
 add_subdirectory(ui/qml)
 if(WITH_TESTS)
        add_subdirectory(tests)
@@ -1105,6 +1109,7 @@ link_directories(
        ${CMAKE_CURRENT_BINARY_DIR}/fonts
        ${CMAKE_CURRENT_BINARY_DIR}/styles
        ${CMAKE_CURRENT_BINARY_DIR}/text
+ ${CMAKE_CURRENT_BINARY_DIR}/api
        ${CMAKE_CURRENT_BINARY_DIR}/third_party/wpg
        ${CMAKE_CURRENT_BINARY_DIR}/third_party/pgf
        ${CMAKE_CURRENT_BINARY_DIR}/third_party/rtf-qt
@@ -1127,6 +1132,7 @@ endif ()

 set(SCRIBUS_COLORMGMT_LIB "scribus_colormgmt_lib")
 set(SCRIBUS_TEXT_LIB "scribus_text_lib")
+set(SCRIBUS_API_LIB "scribus_api_lib")
 if(WITH_TESTS)
        set(SCRIBUS_TESTS_LIB "scribus_tests_lib")
 else()
@@ -1209,6 +1215,7 @@ if(HAVE_OSG)
                ${SCRIBUS_MAIN_CPP}
                ${SCRIBUS_UI_SOURCES}
                ${SCRIBUS_TEXT_SOURCES}
+ ${SCRIBUS_API_SOURCES}
                ${SCRIBUS_STYLES_SOURCES}
                ${SCRIBUS_COLORMGMT_SOURCES}
                ${SCRIBUS_FONTS_SOURCES}
@@ -1224,6 +1231,7 @@ else()
                ${SCRIBUS_MAIN_CPP}
                ${SCRIBUS_UI_SOURCES}
                ${SCRIBUS_TEXT_SOURCES}
+ ${SCRIBUS_API_SOURCES}
                ${SCRIBUS_STYLES_SOURCES}
                ${SCRIBUS_COLORMGMT_SOURCES}
                ${SCRIBUS_FONTS_SOURCES}
@@ -1332,6 +1340,7 @@ target_link_libraries(${EXE_NAME}
        ${SCRIBUS_COLORMGMT_LIB}
        ${SCRIBUS_DESAXE_LIB}
        ${SCRIBUS_TEXT_LIB}
+ ${SCRIBUS_API_LIB}
        ${SCRIBUS_STYLES_LIB}
        ${SCRIBUS_FONTS_LIB}
        ${SCRIBUS_WPG_LIB}


it is to be noted that the part in the IF(OSG) ... ELSE() is probably not needed (most of the entries in there are undefined)...

the CMakeLists.txt file in the api/ directory is:

include_directories(
    ${CMAKE_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/scribus
    ${FREETYPE_INCLUDE_DIRS} # we need those if we want to scribusdoc
    ${HARFBUZZ_INCLUDE_DIRS}
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

set(SCRIBUS_API_LIB_MOC_CLASSES
)

set(SCRIBUS_API_LIB_SOURCES
  document.cpp
  item.cpp
)

QT5_WRAP_CPP(SCRIBUS_API_LIB_MOC_SOURCES ${SCRIBUS_API_LIB_MOC_CLASSES})

set(SCRIBUS_API_LIB "scribus_api_lib")

add_library(${SCRIBUS_API_LIB} STATIC ${SCRIBUS_API_LIB_SOURCES} ${SCRIBUS_API_LIB_MOC_SOURCES})

# This is a convenience library that for linkage purposes is part of Scribus's
# main API.
set_target_properties(${SCRIBUS_API_LIB}
    PROPERTIES
    COMPILE_FLAGS -DCOMPILE_SCRIBUS_MAIN_APP
)

it would be wonderful to have a documentation that states what is needed for adding a new directory in scribus code for both cases:

- include the code in the exe itself. (this is what i think the code above should achieve...)
- create a .so / .dll.
TagsNo tags attached.
PatchNo

Relationships

related to 0015739 new Metabug: improve code modularity 

Activities

ale

2019-06-14 07:32

manager   ~0046303

of course, if i add the .cpp files in the scribus/CMakeLists.txt's SCRIBUS_SOURCES then it works... but i'd really like to touch as little as possible in the files that are outside "my" directory.

for the plugins this works perfectly: it's just one more entry in the parent directory's CMakeLists.txt ...

... the goal being that i can keep a "clean" master and that i can easily share my test code with other people (without having to explain all the things they have to change in the scribus code)

ale

2019-06-26 13:27

manager   ~0046342

i got it, i think!

a good example is how the zip library gets added.

in the scribus/CMakeLists.txt one needs to add

- the directory with `add_subdirectory(newdirectory)`
- the directory to `link_directories()` as `${CMAKE_CURRENT_BINARY_DIR}/newdirectory`
- the string of the "library" as defined in the library's CMakeLists.txt: `set(SCRIBUS_NEWDIRECTORY_LIB "scribus_newdirectory_lib")`
- link the ${SCRIBUS_NEWDIRECOTRY_LIB} library code in `target_link_libraries(${EXE_NAME} (...)`

the library's CMakeLists.txt file will look like this:

include_directories(
    ${CMAKE_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/scribus
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

set(SCRIBUS_NEWDIRECTORY_LIB_MOC_CLASSES
    # xxx.h
)

set(SCRIBUS_NEWDIRECTORY_LIB_SOURCES
    # xxx.cpp
)

QT5_WRAP_CPP(SCRIBUS_NEWDIRECTORY_LIB_MOC_SOURCES ${SCRIBUS_NEWDIRECTORY_LIB_MOC_CLASSES})

set(SCRIBUS_NEWDIRECTORY_LIB "scribus_newdirectory_lib")
add_library(${SCRIBUS_NEWDIRECTORY_LIB} STATIC ${SCRIBUS_NEWDIRECTORY_LIB_SOURCES} ${SCRIBUS_NEWDIRECTORY_LIB_MOC_SOURCES})

set_target_properties(${SCRIBUS_NEWDIRECTORY_LIB}
    PROPERTIES
    COMPILE_FLAGS -DCOMPILE_SCRIBUS_MAIN_APP
)

Issue History

Date Modified Username Field Change
2019-06-13 19:48 ale New Issue
2019-06-14 07:32 ale Note Added: 0046303
2019-06-26 13:27 ale Note Added: 0046342
2019-07-16 12:33 ale Relationship added related to 0015739
2019-07-16 12:34 ale Summary document how to create tools or library that are in their own directory => CMake: document how to create tools or library that are in their own directory