Convert Makefile to CMake

I am trying to convert a Makefile project to cmake.

My project has an executable file that is created and linked to both the internal shared library and the external shared library (there are dependencies in the executable files).

Here is my old Makefile (generic):

Include = -I$(PROJ_DIRECTORY)/include -I/${EXTERN}/lnInclude
Library = -L$(PROJ_DIRECTORY)/build -lshared  -L$(EXTERN_LIBBIN) -lextern
CPPFLAGS    = -D_GLIBCXX_DEBUG -DProjectRescource=$(PROJ_DIRECTORY)/resources -O0 -g3 -Wall -c -fpermissive -std=c++0x -fPIC -MMD -MP
CCC     = g++
TARGET      = ExecutableName

all: $(TARGET)

clean:
    rm -f $(TARGET).o $(TARGET).d $(TARGET)

$(TARGET) : $(TARGET).o
    $(CCC) -o $(TARGET) $(TARGET).o $(Library) 

$(TARGET).o : 
    $(CCC) $(Include) $(CPPFLAGS) $(TARGET).cpp

Here is my attempt at CMakeLists.txt (generalized):

include_directories(${PROJECT_SOURCE_DIR}/include/)
add_executable(test1 test1.cpp)
set (CMAKE_CXX_FLAGS "-D_GLIBCXX_DEBUG -DProjectRescource=${PROJECT_SOURCE_DIR}/resources -O0 -g3 -Wall -fpermissive -std=c++0x -fPIC -MMD -MP")
include_directories($ENV{EXTERN_INCLUDE}/lnInclude)
target_link_libraries(test1 "$ENV{EXTERN_LIBBIN}/libextern.so" Project)

When I run the executable, the calls to the functions defined in the return include -nan directory. Does anyone know why?

+4
source share
1 answer

The cause of the problem is related to the binding order of shared libraries.

I managed to solve the problem by changing the last line of CMakeLists.txt to:

target_link_libraries(test1 Project "$ENV{EXTERN_LIBBIN}/libextern.so")
+2
source

All Articles