CMake file being added in linking step

Viewed 37

I have a project with several sub directories I'm compiling with CMake. Sometimes, when I do mkdir build && cd build && cmake .. && cmake --build . I get g++: error: mysub: linker input file not found. For some reason, on the link step, there is a mysub added to the compilation command. It happens after the includes. Sometimes, cleaning the build directory and rerunning cmake .. will fix it, sometimes it won't.

The options I'm telling CMake to use are:

function(addcxxwarn opt)
    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${opt}>")
endfunction()

addcxxwarn(${name} -Wall)
addcxxwarn(${name} -Wextra)
addcxxwarn(${name} -Wshadow)
addcxxwarn(${name} -Wpointer-arith)
addcxxwarn(${name} -Wcast-qual)
addcxxwarn(${name} -Wswitch-default)
addcxxwarn(${name} -Wcast-align)
addcxxwarn(${name} -Wundef)
addcxxwarn(${name} -Wwrite-strings)
addcxxwarn(${name} -Wconversion)
addcxxwarn(${name} -Wunreachable-code)
addcxxwarn(${name} -pedantic)
addcxxwarn(${name} -funroll-loops)
addcxxwarn(${name} -fno-common)
addcxxwarn(${name} -fno-exceptions)
addcxxwarn(${name} -ffloat-store)
addcxxwarn(${name} -fstrict-aliasing)

link_libraries(gsl gslcblas)
if (UNIX AND NOT APPLE)
    include_directories(/opt/local/include)
    link_directories(/opt/local/lib /opt/local/lib/libgcc)
    link_libraries(gfortran blitz)
elseif (UNIX)
    include_directories(/home/fitzpatrickr/include)
    link_directories(/home/fitzpatrickr/lib)
    link_libraries(gfortran.5)
endif()

add_compile_options("$<$<CONFIG:Debug>:-g;-Og;-Werror>")
add_compile_options("$<$<CONFIG:Release>:-O3>")
add_compile_options("$<$<CONFIG:RelWithDebInfo>:-g;-O3>")

and

configure_file(macro_defs.h.in macro_defs.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

I don't see anywhere else where things are added to link or include options.

0 Answers
Related