Reusing custom makefile for static library with cmake

I assume this will be a general question about including libraries with existing makefiles in cmake; but here is my context -

I am trying to include scintillaCMake in another project, and I have the following problem:

On Linux, scintilla has a makefile in the (say) directory ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/gtk; if you run makein this directory (as usual), you will get a file ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/bin/scintilla.awhich (I think) is a static library.

Now, if I try to use cmake ADD_LIBRARY, I would have to manually specify the scintilla sources in cmake - and I would prefer not to interfere with this, given that I already have a make file. So, I would prefer to call regular scintilla make- and then instruct CMAKE to somehow refer to the resulting one scintilla.a. (I believe that then it will not provide cross-platform compatibility - but note that the cross-platform version is not a problem for me at present, I would just like to build scintilla as part of this project that already uses cmake, only on Linux)

 

So, I worked a bit with this:

ADD_CUSTOM_COMMAND(
  OUTPUT scintilla.a
  COMMAND ${CMAKE_MAKE_PROGRAM}
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/gtk
  COMMENT "Original scintilla makefile target" )

... but then add_custom_command adds a "target without output"; so I am trying to use several approaches for this, all of which fail (errors are indicated as a comment):

ADD_CUSTOM_TARGET(scintilla STATIC DEPENDS scintilla.a) # Target "scintilla" of type UTILITY may not be linked into another target.

ADD_LIBRARY(scintilla STATIC DEPENDS scintilla.a) # Cannot find source file "DEPENDS".

ADD_LIBRARY(scintilla STATIC) # You have called ADD_LIBRARY for library scintilla without any source files.
ADD_DEPENDENCIES(scintilla scintilla.a)

 

, , noob cmake - cmake make "" , cmake ?

,
!

 

EDIT: : CMake: ? - - , cmake...

+5
2

:

# set the output destination
set(SCINTILLA_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/gtk/scintilla.a)
# create a custom target called build_scintilla that is part of ALL
# and will run each time you type make 
add_custom_target(build_scintilla ALL 
                   COMMAND ${CMAKE_MAKE_PROGRAM}
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/gtk
                   COMMENT "Original scintilla makefile target")

# now create an imported static target
add_library(scintilla STATIC IMPORTED)
# Import target "scintilla" for configuration ""
set_property(TARGET scintilla APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(scintilla PROPERTIES
  IMPORTED_LOCATION_NOCONFIG "${SCINTILLA_LIBRARY}")

# now you can use scintilla as if it were a regular cmake built target in your project
add_dependencies(scintilla build_scintilla)

add_executable(foo foo.c)
target_link_libraries(foo scintilla)

# note, this will only work on linux/unix platforms, also it does building
# in the source tree which is also sort of bad style and keeps out of source 
# builds from working.  
+9

, , ; , CMakeLists.txt, , :

ADD_CUSTOM_TARGET(
  scintilla.a ALL
  COMMAND ${CMAKE_MAKE_PROGRAM}
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scintilla/gtk
  COMMENT "Original scintilla makefile target" )

... , , , cmake , ${PROJECT_NAME} - :

ADD_DEPENDENCIES(${PROJECT_NAME} scintilla.a)

... , , .

, scintilla.a - /// ( - , scintilla--a - ); - `scintilla.a ( ${SCINTILLA_LIBRARY}).

list(APPEND PROJ_LIBRARIES ${SCINTILLA_LIBRARY} )

... , cmake (, , )

 

${SCINTILLA_LIBRARY} scintilla.a ADD_CUSTOM_TARGET, : " . ADD_CUSTOM_COMMAND ". , / ADD_CUSTOM_COMMAND - , " , . named , ."... , , , - , ( , :))

, ,
!

+2

All Articles