cmakecross-platformshared-objects

CMake building multiple libraries in the same project


I have a specific CMake project I would like to build as both a static lib and a shared object (Linux only). The relevant part of the CMake file:

...

# Static lib
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})

# Build shared object in Linux only
if(UNIX)
    set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
    add_library("${PROJECT_NAME}_SHARED" SHARED ${SOURCES} ${HEADERS})
endif(UNIX)

link_directories(${ILI_EXTERNAL_LIB_DIRS})

target_link_libraries(${PROJECT_NAME} ${ILI_EXTERNAL_LIBS} IliLib PlantModel)

I can figure out why the shared object is not being built, when I add a message within the Unix block, it gets printed during the make build. The rest of this cmake file only sets variables and declares the project name.

Any tips for how to go about debugging this issue? On both Windows and Linux, it only builds the static lib at present.


Edit: Link to CMake and Make log outputs.


Solution

  • The solution was suggested by @Tsyvarev, trivial error on my part.

    The static lib was being built because it was a dependency of another build target. I had not explicitly run "Make" on the SimulatorLib project.

    CMake messages appear in the CMake log irrespective of whether that particular project is being built.