I am writting a C++/CLI project, using CMake as a build generator.
In the root of the project I have the main CMakeLists.txt, the include and the src dir.
# CMakeList.txt :
cmake_minimum_required (VERSION 3.8)
set(This Project) # Creates a variable to reference the project's name
project(${This} CXX) # Sets the name of the project and the languages used in
set(CMAKE_CXX_STANDARD 17) # This project will be build using the C++ 17 standard
# Directories for headers and source code
file(
GLOB_RECURSE
Headers
./include/Project/**.hpp
Sources
src/**.cpp
)
add_library(
${This} STATIC ${Headers} ${Sources}
)
# Compiler options
SET_TARGET_PROPERTIES(${This} PROPERTIES COMPILE_FLAGS "/clr")
STRING(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
STRING(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clr")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /c")
# Testing
enable_testing() # Telling CMake that we will have unit tests
add_subdirectory(test) # Project tests
#target_link_libraries(${This} PRIVATE ProjectTests)
Then I have a subdirectory with the test package, using the CppUnitTestFramework
cmake_minimum_required(
VERSION 3.8
)
set(This ProjectTests)
project(${This} CXX)
# Directories for the testing files of the projects
file(
GLOB_RECURSE
Sources
src/**.cpp
)
add_executable(${This} ${Sources})
# The locations of the MS CppUnitTestFramework
include_directories("C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/UnitTest/include")
link_directories("C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/VS/UnitTest/lib/x86/Microsoft.VisualStudio.TestTools.CppUnitTestFramework.lib")
target_link_libraries(${This} PUBLIC Project)
add_test(
NAME ${This}
COMMAND ProjectTests
)
I am not being able to make it work the test subdirectory with any test framework
Error:
Error LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)\MSVCRTD.lib(exe_main.obj) 1
``
Can someone give me a hand? Thanks in advice