CMake Project automake library - c++

I've a CMake Project. Now I need to use libcpuid and procps which is automake.
I want to ship so files with executable.

One way is to create a CMakeLists.txt file for libcpuid and procps
Here is an example for a CMakeLists.txt file for lipcpuid:
cmake_minimum_required(VERSION 2.8.12)
project(libcpuid-0.1.0)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Compiler settings
if (WIN32)
# Standard: /DWIN32 /D_WINDOWS /W3 /Zm1000 /EHsc /GR
set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W4 /Zi /EHsc /GR- /MP /openmp")
endif (WIN32)
file(GLOB libcpuid_SRC *.c *.h)
add_definitions(-DVERSION="0.1.0")
# Create a target for the library
add_library(libcpuid-0.1.0
${libcpuid_SRC}
)
Afterwards in your CMake project you can easily reference to the lib via:
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/external/libcpuid_0.1.0)
target_link_libraries( YourProject
libcpuid-0.1.0
)

Related

How to fix : LINK Error when using Try_Run command in CMake

I am working on setting up a project folder architecture for a game and want to compile and link dependencies while keeping a clean project structure using CMake.
This imply that external libraries are built separately from my application binary. The application binary should however be able to access includes & sources files when building.
Here is a link to the git project : https://github.com/guyllaumedemers/SDL2-Tetris.
Here's my project folder architecture :
cmake
doc
extern
- libImGUI
- CMakeLists.txt
- #git.submodule - imgui
- libImGUI.cpp
- libSDL2
- CMakeLists.txt
- #git.submodule - sdl2
- libSDL2.cpp
- CMakeLists.txt
src
- appTetris
- CMakeLists.txt
- Main.cpp
- CMakeLists.txt
test
CMakeLists.txt
Before integrating the libraries I have added in my project, I want to run a test using ONLY my dummy source files with CMake Try_Run command.
// test script
#include <cstdio>
void libImGUITest(){ std::printf("libImGUI, Hello World!");}
I have created a src file under extern/libSDL2 with a simple function definition & did the same for the second library under extern/libImGUI. You can ignore the target_include_directories atm since I do not require the headers of the actual library.
project(
libImGUI
)
# add directory for lib
add_library(
${PROJECT_NAME}
OBJECT
"${PROJECT_SOURCE_DIR}/libImGUI.cpp"
)
add_library(
lib::imgui
ALIAS
${PROJECT_NAME}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
"${PROJECT_SOURCE_DIR}/pkg/backends"
)
# temp solution for try_run in appTetris CMakeLists.txt
add_library(
tryRunlibImGUI
STATIC
$<TARGET_OBJECTS:${PROJECT_NAME}>
)
Under my application folder : src/appTetris, I have my application entry point which is a Main.cpp with 2 forward declarations.
I am expecting the LINKER to resolve the definition of the forward declaration and print both library output message in the console log.
void libImGUITest();
void libSDL2Test();
int main(int argv, char** argc)
{
libImGUITest();
libSDL2Test();
return 0;
}
src/AppTetris CMakeLists.txt
set(
MYLANGUAGES
CXX
)
project(
Demo
VERSION 0.0.0.0
DESCRIPTION "Demo"
LANGUAGES ${MYLANGUAGES}
)
add_executable(
${PROJECT_NAME}
Main.cpp
)
add_dependencies(
${PROJECT_NAME}
lib::imgui
lib::sdl2
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC
lib::imgui
lib::sdl2
)
# set project specifics
set(
MYCXX_VERSION_STANDARD
20
)
set_property(
TARGET
${PROJECT_NAME}
PROPERTY
CMAKE_CXX_STANDARD
${MYCXX_VERSION_STANDARD}
)
if(NOT ${CMAKE_CXX_STANDARD} EQUAL ${MYCXX_VERSION_STANDARD})
message(WARNING "WARNING! CXX_STANDARD SHOULD BE CXX_${MYCXX_VERSION_STANDARD}, CURRENTLY : ${CMAKE_CXX_STANDARD}")
else()
message(WARNING "WARNING! CXX_STANDARD IS CXX_${CMAKE_CXX_STANDARD}") # why this doesnt print?
endif()
set(
CMAKE_CXX_STANDARD_REQUIRED
ON
)
if(${CMAKE_CXX_STANDARD_REQUIRED})
message(WARNING "WARNING! CXX_STANDARD_REQUIRED IS ${CMAKE_CXX_STANDARD_REQUIRED}. MAKE SURE YOU HAVE THE LATEST COMPILER VERSION SUPPORTING THE CURRENT REQUIREMENTS FOR CXX_${CMAKE_CXX_STANDARD}")
endif()
set(
CMAKE_CXX_EXTENSIONS
OFF
)
if(NOT ${CMAKE_CXX_EXTENSIONS})
message(WARNING "WARNING! CXX_EXTENSIONS IS ${CMAKE_CXX_EXTENSIONS}!")
endif()
# check support for LINK Time Optimization between translation units
include(CheckIPOSupported)
check_ipo_supported(
RESULT
IS_IPO_SUPPORTED
OUTPUT
IPO_SUPPORT_LOG_OUTPUT
LANGUAGES
${MYLANGUAGES}
)
if(NOT ${IS_IPO_SUPPORTED})
message(WARNING "IPO ADD ON SUPPORTED : ${IS_IPO_SUPPORTED}. ${IPO_SUPPORT_LOG_OUTPUT}")
else()
set(
CMAKE_INTERPROCEDURAL_OPTIMIZATION
TRUE
)
endif()
# check compiler features supported
set(
PRINT_UNSUPPORTED_COMPILE_FEATURES
FALSE
)
if(${PRINT_UNSUPPORTED_COMPILE_FEATURES})
foreach(VAR IN LISTS CMAKE_CXX_COMPILE_FEATURES)
list(FIND CMAKE_CXX_COMPILE_FEATURES ${VAR} RESULT COMPILE_FEATURE_SUPPORT_RESULT)
if(NOT ${COMPILE_FEATURE_SUPPORT_RESULT})
message(WARNING "WARNING! FEATURE NOT SUPPORTED : ${VAR}")
endif()
endforeach()
endif()
# run try catch on dependencies
set(
APP_TETRIS_TEST_BINARY_DIR
"${PROJECT_BINARY_DIR}/test"
)
set(
TARGET_TRY_RUN
"${PROJECT_SOURCE_DIR}/Main.cpp"
)
# try_run cannot use ALIAS for some reason. target_link_libraries however allow such setup
# try_run doesn't allow OBJECTlib which means I can only create another lib that capture the TARGET_OBJECTS thru transitive property
try_run(
MAIN_CPP_RUN_RESULT
MAIN_CPP_COMPILE_RESULT
"${APP_TETRIS_TEST_BINARY_DIR}"
"${TARGET_TRY_RUN}"
LINK_LIBRARIES
tryRunlibImGUI
tryRunlibSDL2
COMPILE_OUTPUT_VARIABLE
TRY_COMPILE_LOG_OUTPUT
RUN_OUTPUT_VARIABLE
TRY_RUN_LOG_OUTPUT
)
if(NOT ${MAIN_CPP_COMPILE_RESULT})
message(SEND_ERROR "SEND_ERROR! TARGET TRY COMPILATION FAILED : ${TARGET_TRY_RUN}, COMPILE OUTPUT : ${TRY_COMPILE_LOG_OUTPUT}, RUN OUTPUT : ${TRY_RUN_LOG_OUTPUT}")
elseif(NOT ${MAIN_CPP_RUN_RESULT})
message(SEND_ERROR "SEND_ERROR! TARGET TRY RUN FAILED : ${TARGET_TRY_RUN}, COMPILE OUTPUT : ${TRY_COMPILE_LOG_OUTPUT}, RUN OUTPUT : ${TRY_RUN_LOG_OUTPUT}")
endif()
However, when running Try_Run command in CMake, I get the following linking error.
CMake Error at src/appTetris/CMakeLists.txt:138 (message):
SEND_ERROR! TARGET TRY COMPILATION FAILED :
D:/VisualStudio/SDL2/SDL2-GameDevCMake/SDL2-Tetris/src/appTetris/Main.cpp,
COMPILE OUTPUT : Change Dir:
D:/VisualStudio/SDL2/SDL2-GameDevCMake/SDL2-Tetris/out/build/bin/SDL2-TetrisApp/test/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual
Studio/2022/Enterprise/MSBuild/Current/Bin/amd64/MSBuild.exe
cmTC_4786f.vcxproj /p:Configuration=Debug /p:Platform=x64
/p:VisualStudioVersion=17.0 /v:m && MSBuild version 17.3.1+2badb37d1 for
.NET Framework
Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31629 for x64
Main.cpp
Copyright (C) Microsoft Corporation. All rights reserved.
cl /c /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_4786f.dir\Debug\\" /Fd"cmTC_4786f.dir\Debug\vc143.pdb" /external:W1 /Gd /TP /errorReport:queue "D:\VisualStudio\SDL2\SDL2-GameDevCMake\SDL2-Tetris\src\appTetris\Main.cpp"
LINK : fatal error LNK1104: cannot open file 'tryRunlibImGUI.lib'
[D:\VisualStudio\SDL2\SDL2-GameDevCMake\SDL2-Tetris\out\build\bin\SDL2-TetrisApp\test\CMakeFiles\CMakeTmp\cmTC_4786f.vcxproj]
Can anyone point me in the right direction to compile and run the Try_Run command?

Can't build OR-Tools (fetched with FetchContent) with MSVC in Qt Creator

I'm trying to build a project that integrates OR-Tools, with MSCV 2019 in Qt Creator, but there are strange build errors (hundred of them, in Abseil source code at the moment, but probably only because it's built first):
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2039: 'ratio': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\algorithm(40): note: see declaration of 'std'
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2061: syntax error: identifier 'ratio'
C:\MyProject\build_deps\absl-src\absl\time\time.h:408: erreur : C2760: syntax error: unexpected token '{', expected ')'
I'm fetching OR-Tools with FetchContent, with the following CMakeLists.txt (I've removed most of the default Qt boilerplate):
cmake_minimum_required(VERSION 3.15)
project(MyProject VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
set(PROJECT_SOURCES main.cpp)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
include(FetchContent)
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_Declare(
or-tools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG v9.3
)
FetchContent_MakeAvailable(or-tools)
target_link_libraries(${PROJECT_NAME} PRIVATE or-tools)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
target_compile_options(${PROJECT_NAME} PRIVATE /experimental:external /external:anglebrackets /external:W0)
qt_finalize_executable(${PROJECT_NAME})
For information, Qt Creator successively calls:
C:\Qt\Tools\CMake_64\bin\cmake.exe -S "C:/MyProject" -B "C:/MyProject/build" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:/Qt/Tools/QtCreator/share/qtcreator/package-manager/auto-setup.cmake" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.3.0/msvc2019_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.3.0/msvc2019_64" "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe"
C:\Qt\Tools\CMake_64\bin\cmake.exe --build "C:/MyProject/build" --target all
The first failed compile command is:
C:\MSVC\x64\cl.exe /nologo /TP
-I"C:\MyProject\build\_deps\absl-build\absl\time"
-I"C:\MyProject\build\_deps\absl-src\absl\time"
-I"C:\MyProject\build\_deps\absl-build\absl\time\time_zone_autogen\include"
-I"C:\MyProject\build\_deps\absl-src"
/DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /W3 /DNOMINMAX
/DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /D_ENABLE_EXTENDED_ALIGNED_STORAGE
/bigobj /wd4005 /wd4068 /wd4180 /wd4244 /wd4267 /wd4503 /wd4800 -std:c++20 /showIncludes
/Fo_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\internal\cctz\src\time_zone_lookup.cc.obj
/Fd_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\time_zone.pdb
/FS -c "C:\MyProject\build\_deps\absl-src\absl\time\internal\cctz\src\time_zone_lookup.cc
Am I missing something?
Can you try with c++17 instead of c++20?
This happens when a project (such as https://github.com/abseil/abseil-cpp, used by or-tools) has a file called time.h.
The project builds fine when built standalone, but when used with FetchContent in a toplevel project that defines set(CMAKE_INCLUDE_CURRENT_DIR ON), <ctime> ends up including the time.h file from the project instead of the time.h file from the system.
I fixed this with
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
FetchContent_MakeAvailable(absl)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

Can't compile static library with cmake cause compilation `cannot open include file: ...` for any standard header

Note: I've only tested this problem on windows but that's what I want to solve right now.
I'm trying to create a static library and I'm using CMake to generate the build files. However, building leads to no standard libraries being found. The simplest form I reproduce this issue is with these 3 files:
Test.hpp
#pragma once
class A
{
public:
int DoSomething();
};
Test.cpp
#include "Test.hpp"
#include <assert.h>
int A::DoSomething()
{
assert(true);
return 5;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project(MyLib VERSION 1.0.0 DESCRIPTION "My Lib")
set(SOURCE "src/Test.cpp")
if(WIN32)
set(CMAKE_CXX_FLAGS "/std:c++17 /EHsc")
else()
...
endif()
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
add_library(MyLib STATIC ${SOURCE})
Running cmake is fine but then running cmake --build . I get the following output:
C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\HostX64\x64\cl.exe /nologo /TP -I..\..\..\include /std:c++17 /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\MyLib.dir\src\Test.cpp.obj /FdCMakeFiles\MyLib.dir\MyLib.pdb /FS -c ..\..\..\src\Test.cpp ..\..\..\src\Test.cpp(3): fatal error C1083: Cannot open include file: 'assert.h': No such file or directory
I'm not sure why it can't find assert.h. I'm only using this as an example but this happens with all STL headers. I've also tried using /MD /MT /MTd but it doesn't change anything. Feels like I need to do something special because it's a STATIC library but I couldn't identify what looking around.

Unresolved external symbol error when using CMake in Visual Studio 2017 to build a wxWidgets project

I'm working on a CMake project in Visual Studio 2017 that targets wxWidgets 3.1.0. Whenever I try to build it, I get numerous error messages similar to the following:
unresolved external symbol "protected: virtual class wxRefCounter * __cdecl wxObject::CreateRefData(void)const " (?CreateRefData#wxObject##MEBAPEAVwxRefCounter##XZ)
Here is the content of my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.8)
project (FNDice-cmake)
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_CONFIGURATION mswu)
set(wxWidgets_ROOT_DIR C:/wxWidgets-3.1.0)
find_package(wxWidgets REQUIRED all)
include(${wxWidgets_USE_FILE})
add_executable(FNDice-cmake WIN32 FNDiceApp.h FNDiceApp.cpp MainWindow.h MainWindow.cpp FNDie.h FNDie.cpp AboutDialog.h AboutDialog.cpp FNDice.rc fndice-small.ico wxIconBundleResLoader.h wxIconBundleResLoader.cpp sqlite3.c sqlite3.h LICENSE-2.0.h about24.h help24.h history24.h new24.h open24.h save24.h)
target_link_libraries(FNDice-cmake ${wxWidgets_LIBRARIES})
I did find a similar question (linker error using wxwidgets with cmake), but as you can see, I'm already using WIN32 in my add_executable() line.
I have the same problem:
The wxWidgets website does not seem to list CMake as a method for building wxWidgets projects, but CMake has a documented findpackage method for wxWidgets, and, following the instructions for that package:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project (wxHello)
#set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
if (NOT wxWidgets_FOUND)
message(SEND_ERROR "wxWidgets_FOUND => ${wxWidgets_FOUND}")
endif ()
include(${wxWidgets_USE_FILE})
message ( "wxWidgets_INCLUDE_DIRS => ${wxWidgets_INCLUDE_DIRS}")
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "${PROJECT_NAME}" )
# add_executable(test ${SOURCES})
add_executable(${PROJECT_NAME} app.cpp app.h frame.cpp frame.h stdafx.h)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
The generated Makefile and visual studio solution file fail with a linking error.
I can manually build the program from the command line, and this works fine, but the whole reason for using wxWidgets is portability, and command line building is not portable.
CL.exe /c /ZI /I%VCINCLUDE% /I%WXWIN%\lib\vc_x64_lib\mswud /JMC /W3 /WX- /diagnostics:classic /sdl /Od /D _DEBUG /D _WINDOWS /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Gd /TP /FC /errorReport:prompt ..\*.cpp
link /LIBPATH:%WXWIN%\lib\vc_x64_lib *.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Comctl32.lib Rpcrt4.lib
program built in the command line works fine, or built with with a visual studio *.sln file works fine - just the Makefile and the sln file built by CMake fails.

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.
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