cmake with library and executables

64 views
Skip to first unread message

Konrad Simon

unread,
Nov 8, 2019, 12:06:49 PM11/8/19
to deal.II User Group
Hi deal.ii community,

Little cmake question: I set up a user project with include, test, doc and source directory. I am collecting some code in a library and then I link a few application files to the library. I followed the guidelines of the documentation and everything is fine. Now one little but annoying thing. I get

make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.

when typing make -j8.

Do you have an idea what I could do?

Best,
Konrad

Konrad Simon

unread,
Dec 20, 2019, 2:07:58 PM12/20/19
to deal.II User Group
Hello deal.ii community,

I am posting again (sorry) with a bit more info since I did not find the mistake in my cmake setup. I have essentially the following project structure:

project/source
project/include
project/doc
project/test. 

In project/ I have this CMakeLists.txt:

#############################################################
#############################################################
# Macro to print all arguments
macro (print_all_args)
  message (STATUS "------------------------------------")
  
  set(list_var "${ARGN}")
  foreach(_currentItem IN LISTS list_var)
    message (STATUS "Adding library source file:   ${_currentItem}")
  endforeach (_currentItem)
  
  message (STATUS "------------------------------------")
endmacro (print_all_args)
#############################################################
#############################################################



###############################################################################
###############################################################################
message(STATUS "This is CMake ${CMAKE_VERSION}")
message(STATUS "")

cmake_minimum_required(VERSION 2.8.12)

find_package(deal.II 9.1.1 QUIET
  HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
  )
if (NOT ${deal.II_FOUND})
  message(FATAL_ERROR "\n"
    "*** Could not locate a (sufficiently recent) version of deal.II. ***\n\n"
    "You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
    "or set an environment variable \"DEAL_II_DIR\" that contains this path."
    )
endif ()

DEAL_II_INITIALIZE_CACHED_VARIABLES()

set(PROJECT_NAME MsFEComplex)

# The version number
set(MsFEComplex_VER_MAJOR 0)
set(MsFEComplex_VER_MINOR 1)

project(${PROJECT_NAME})
###############################################################################
###############################################################################



###############################################################################
###############################################################################
# Check for the existence of various optional folders:
if (EXISTS ${CMAKE_SOURCE_DIR}/doc/CMakeLists.txt)
  set(MsFEComplex_HAVE_DOC_DIRECTORY TRUE)
endif ()

if (EXISTS ${CMAKE_SOURCE_DIR}/test/CMakeLists.txt)
  set (MsFEComplex_HAVE_TEST_DIRECTORY TRUE)
endif ()
###############################################################################
###############################################################################



###############################################################################
###############################################################################
# Change default CMAKE_INSTAL_PREFIX to ${CMAKE_BINARY_DIR}/lib
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/lib" CACHE PATH "default install path" FORCE )
endif ()

set (MsFEComplex_LIBRARY msfecomplex)
###############################################################################
###############################################################################



###############################################################################
###############################################################################
set(MsFEComplex_INCLUDE_DIR
${CMAKE_SOURCE_DIR}/include)

set(MsFEComplex_SRC_DIR 
${CMAKE_SOURCE_DIR}/source)
add_subdirectory (${MsFEComplex_SRC_DIR})


# Only add subdirectories for doc if exists
if (MsFEComplex_HAVE_DOC_DIRECTORY)
  add_subdirectory (${CMAKE_SOURCE_DIR}/doc)
endif ()

# Only add subdirectories for doc if exists
if (MsFEComplex_HAVE_TEST_DIRECTORY)
  add_subdirectory (${CMAKE_SOURCE_DIR}/test)
  ENABLE_TESTING()
endif ()
###############################################################################
###############################################################################



###############################################################################
###############################################################################
ADD_CUSTOM_TARGET(debug
  COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
  COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
  COMMENT "Switch CMAKE_BUILD_TYPE to Debug"
  )

ADD_CUSTOM_TARGET(release
  COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
  COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
  COMMENT "Switch CMAKE_BUILD_TYPE to Release"
  )
###############################################################################
###############################################################################


and in project/source I have:


###############################################################################
###############################################################################
#
# Include directory for sources
#
include_directories(${MsFEComplex_INCLUDE_DIR})
###############################################################################
###############################################################################


###############################################################################
###############################################################################
#
# Name all sources
#
#file(GLOB_RECURSE MsFEComplex_TARGET_LIB_SRC  "*.cc") # source files
#set(MsFEComplex_TARGET_LIB_SRC ${MsFEComplex_TARGET_LIB_SRC})
set(MsFEComplex_TARGET_LIB_SRC
eqn_boundary_vals.cc
eqn_coeff_A.cc
eqn_coeff_B.cc
eqn_coeff_R.cc
eqn_exact_solution_lin.cc
eqn_rhs.cc
ned_rt_basis.cc
ned_rt_global.cc
ned_rt_post_processor.cc
ned_rt_ref.cc
parameters.cc
q_ned_basis.cc
q_ned_global.cc
q_ned_post_processor.cc
q_ned_ref.cc)

print_all_args (
  ${MsFEComplex_TARGET_LIB_SRC}
 )
###############################################################################
###############################################################################


###############################################################################
###############################################################################
#
# Compile and link the sources as SHARED
#
add_library (MsFEComplex_LIBRARY SHARED ${MsFEComplex_TARGET_LIB_SRC})
DEAL_II_SETUP_TARGET(MsFEComplex_LIBRARY)

#
# Install into the DESTINATION provided by CMAKE_INSTALL_PREFIX
#
#install (TARGETS ${MsFEComplex_LIBRARY} DESTINATION ${CMAKE_INSTALL_PREFIX})

add_executable(MsFEComplex_Ned_RT "main_ned_rt.cxx")
DEAL_II_SETUP_TARGET(MsFEComplex_Ned_RT)
TARGET_LINK_LIBRARIES(MsFEComplex_Ned_RT MsFEComplex_LIBRARY)

add_executable(MsFEComplex_Q_Ned "main_q_ned.cxx")
DEAL_II_SETUP_TARGET(MsFEComplex_Q_Ned)
TARGET_LINK_LIBRARIES(MsFEComplex_Q_Ned MsFEComplex_LIBRARY)
###############################################################################
###############################################################################

So essentially I want to build a library and then link two executables to it. It compiles correctly but very slow since I can not invoke make -j8  

Google unfortunately does not help.

Any help would be much appreciated.

Best,
Konrad

Wolfgang Bangerth

unread,
Dec 24, 2019, 11:59:31 AM12/24/19
to dea...@googlegroups.com

Konrad,
your email has no question :-) Is your problem that you can't call 'make -j8'
and your question how to make that possible? If so, what happens if you try?
What is the error message?

Best
W.
> It compiles correctly but very slow since I can not invoke *make -j8*
>
> Google unfortunately does not help.
>


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Konrad Simon

unread,
Dec 24, 2019, 5:55:53 PM12/24/19
to deal.II User Group
Hi Wolfgang,


On Tuesday, December 24, 2019 at 5:59:31 PM UTC+1, Wolfgang Bangerth wrote:

Konrad,
your email has no question :-) Is your problem that you can't call 'make -j8'
and your question how to make that possible? If so, what happens if you try?
What is the error message?

The message essentially says I can not use the jobserver so I can only use once core to compile. My library does compile but falls back to make -j1 every time I invoke make -j8. My question is why? And how can I use all cores?

Thank you and merry Christmas!

Konrad

Matthias Maier

unread,
Dec 25, 2019, 8:07:41 AM12/25/19
to dea...@googlegroups.com

On Fri, Dec 20, 2019, at 13:07 CST, Konrad Simon <ksimo...@gmail.com> wrote:

> ###############################################################################
> ###############################################################################
> ADD_CUSTOM_TARGET(debug
> COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
> COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
> COMMENT "Switch CMAKE_BUILD_TYPE to Debug"
> )
>
> ADD_CUSTOM_TARGET(release
> COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
> COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
> COMMENT "Switch CMAKE_BUILD_TYPE to Release"
> )
> ###############################################################################
> ###############################################################################

Do you get the jobserver warning while running "make release" or "make
debug" with "-j8"?

If so - that's because you cannot recursively call into make with the
jobserver feature that way.

We have fixed the example steps a while ago but probably never updated
the documentation regarding these two custom targets. It is best to
simply have:

ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
COMMENT "Switch CMAKE_BUILD_TYPE to Debug"
)

ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
)

and then

$ make release
$ make -j8

or

$ make debug
$ make -j8

Best,
Matthias

Konrad Simon

unread,
Dec 25, 2019, 1:20:24 PM12/25/19
to deal.II User Group
Many thanks, Matthias!

Works!

Best,
Konrad
Reply all
Reply to author
Forward
0 new messages