Search code examples
c++ccmakenmake

Why NMake generator puts the .obj file for C files in a directory other than those of C ++


I've a mysterious problem with the "NMake Makefiles" generator.

When I used my CMakeLists for generate a Solution Visual and I build after, he puts all my .obj in the same folder "sql_lite.dir/Debug/". The build success.

But when I use the Nmake generator, he put my .obj in 2 diferent folder :

sql_sqlite.dir/C_/Users/mea/Documents/repos/corealpi/external/sqlite

and

sql_sqlite.dir/C_/Users/mea/Documents/repos/corealpi/external/sqlite/sqlite3.c.obj

I thought the fact I have file.cpp and file.c is the problem of my issue, because I have the following output :

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILE_OBJECT

And this at the end of Nmake :

[100%] Building C object CMakeFiles/sql_sqlite.dir/C_/Users/mea/Documents/repos/
corealpi/external/sqlite/sqlite3.c.obj
Linking CXX shared library C:\Users\mea\Documents\repos\corealpi\build\cmake_x86
d\bin\sql_sqlite.dll
LINK : fatal error LNK1104: cannot open file 'CMakeFiles/sql_sqlite.dir/C_/Users
/mea/Documents/repos/corealpi/external/sqlite/sqlite3.c.obj'
LINK failed. with 1104

It seems, he not build in the same directory and not build the .obj for the C file's.

Here is my CMakeLists.txt (who's running well under Visual Studio) :

############################### SQLITE ###############################
project(sql_sqlite CXX)

SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO")
# Path of Release
SET(BIN_RELEASE_PATH "../../build/cmake_x86")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
# Path of Debug
SET(BIN_DEBUG_PATH "../../build/cmake_x86d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
# Flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /Ycstdafx.h /Yustdafx.h /D_USRDLL /DSQL_SQLITE_EXPORTS /D_UNICODE /DUNICODE")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /GL /Oi /Gy /O2 /GR- /Gm- /OPT /Fosql_sqlite.dir/src/sql_sqlite")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX- /ZI /Oy- /Gm /EHsc /MDd /GS /Gd")

    set_source_files_properties(../datasec/src/sql_sqlite/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")  
    set_source_files_properties(../datasec/src/sql_sqlite/main.cpp PROPERTIES COMPILE_FLAGS "/Yustdafx.h")  
    set_source_files_properties(../external/sqlite/sqlite3.c PROPERTIES COMPILE_FLAGS "/Y-")

# Files of library
add_library(

        sql_sqlite

        SHARED

    ../datasec/src/sql_sqlite/stdafx.h
    ../external/sqlite/sqlite3.h

    ../datasec/src/sql_sqlite/sql_sqlite.cpp
    ../datasec/src/sql_sqlite/stdafx.cpp
    ../datasec/src/sql_sqlite/main.cpp  
    ../external/sqlite/sqlite3.c

)

target_link_libraries(sql_sqlite datasec core)

Please I need help because, I've search on many website, try different solution during many days but anyway, it stand failing linking.

I've trying to put something like that : /Fosql_sqlite.dir/src/sql_sqlite but nothing change.

Do I have to make a special rule for sqlite3.c ? Or have I make something wrong on my CMakeLists.txt ?

Why CMake tells me : Missing variable is: CMAKE_C_COMPILE_OBJECT ?

Thanks for help.


Solution

  • Your PROJECT lines specifes C++ only via the CXX. Maybe removing the CXX will fix the problem so that both C and C++ compilers will be setup. The documentation is here, http://www.cmake.org/cmake/help/v3.2/command/project.html