I have the jpeglib library, built with cmake and visual studio 2005. And I also have a separate program that uses this library. How can I compile that program so that I can debug both program and library code?
My first attempt was by just including the main program's project into the libjpeg solution, changing include paths and specifying the path to libjpeg .lib. This worked, but when I rerun cmake, I have to redo that. I described it here: https://board.flatassembler.net/topic.php?p=203834#203834
How can I compile those two programs using cmake itself? I tried adding this in the libjpeg CMakeList.txt :
add_executable(_main--ddraw main.cpp)
set_property(TARGET _main--ddraw PROPERTY RUNTIME_OUTPUT_DIRECTORY "c:/_src/_main--ddraw3")
target_link_libraries(_main--ddraw jpeg-static)
But it only resulted in this:
1>CMake Error at CMakeLists.txt:369 (add_executable):
1> Cannot find source file:
1> main.cpp
1> Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
1> .hxx .in .txx
1>CMake Error: CMake can not determine linker language for target: _main--ddraw
Related
This question already has answers here:
What's the CMake syntax to set and use variables?
(3 answers)
Closed 2 years ago.
here is my code of cmake :
PROJECT (HELLO)
SET(SRC ./main.c)
MESSAGE(STATUS "This is BINARY dir "${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir"${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello SRC)
if I run, what appears in front of me is that:
-- Configuring done
CMake Error at CMakeLists.txt:5 (ADD_EXECUTABLE):
Cannot find source file:
SRC
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: hello
CMake Error: Cannot determine link language for target "hello".
-- Generating done
if I change my code to
PROJECT (HELLO)
SET(SRC ./main.c)
MESSAGE(STATUS "This is BINARY dir "${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir"${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ./main.c)
it just works well.
So, what happens to SET? why didn't it work well?
You need to use:
ADD_EXECUTABLE(hello ${SRC})
Otherwise, cmake just thinks you have a source file named "SRC" leading to that error you see.
I'm looking into switching my C++ building workflow from use of VisualStudio sln/vcxproj files and Makefiles to using CMake. Compilation is fine, but I'm running into issues when trying to link .res files for our Windows dialogs.
Our project is structured as you would expect a VS project to be structured: it has a solution with a core project, and it relies symbols from other projects. One of the 'libraries' I need for building on Windows is our base dialog .res file, which has been pre-compiled and is available in a directory, but when I try to link that file I get an error stating that it can't link "BaseResource.res.lib".
So of course I've done some Googling on this, and have spent more than a few hours looking for something. The closest I've found is this StackOverflow question on the subject, and I've tried its suggestion which apparently worked for the original ask-er, but it doesn't seem to be working on my end. Currently within my CMakeLists I have:
project(my_project CXX)
...
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
ENABLE_LANGUAGE(RC)
file(TO_CMAKE_PATH "${RES_SOURCE_ROOT}/Source/Resources/Dialogs/Resource.rc"
BASE_RESOURCE_RC)
add_executable( BaseResource ${BASE_RESOURCE_RC})
target_link_libraries(BaseResource "BaseResource.res")
set(BASE_RESOURCE_LINK_FLAGS
"${RES_SOURCE_ROOT}/Lib/${PLATFORM_DIR}/BaseResource.res")
set_target_properties(BaseResource PROPERTIES LINK_FLAGS
${BASE_RESOURCE_LINK_FLAGS})
...
else()
# Do *Nix things.
endif()
Where BaseResource is the previously-undeclared project which is different from this one, and PLATFORM_DIR is the platform-based directory where we keep our binaries, e.g. "windows/v140/32bit". However, when I attempt this, loading the project tells me:
Cannot find source file:
D:/Path/To/Resource/Root/Source/Resources/Dialogs/Resource.rc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
No SOURCES given to target: BaseResource
To be clear, this project should not care about the sources of other projects - it is specifically meant to compile just this project and to use the libraries from other projects to do so. The use of the above workaround was solely in the hope that it might allow me to use the resource.
I'm honestly at a loss; it's using the MSVC compiler so there really should be no issues in doing this linking, which goes off without a hitch using the VisualStudio solution. Any help on this subject would be hugely appreciated.
Thanks,
~Jon
EDIT: To clarify further, the original error is when I attempt to use:
link_libraries("${RES_SOURCE_ROOT}/Lib/${PLATFORM_DIR}/BaseResource.res")
The original error I get is:
LINK : fatal error LNK1104: cannot open file 'BaseResource.res.lib'
The error with the .rc file is coming from a workaround, in the event that it was the right direction but lacking some other things.
This question already has answers here:
Automatically add all files in a folder to a target using CMake?
(5 answers)
Closed 6 years ago.
I wan't to compile an external library:
It works with the complete path of the source like:
add_library(timetool "../src/wnt/foo.cxx"
"../../../../include/foo.h"
It DOESN'T works
add_library(timetool "../src/wnt/*.cxx"
"../../../../include/*.h"
And I get the error message:
CMake Error at CMakeLists.txt:25 (add_library):
Cannot find source file:
../src/*.cxx
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
What can I do to solve the Problem?
And that is the solution! No whildcards in function add_library
file(GLOB timetool_SRC "../src/wnt/*.cxx"
"../../../../include/*.h"
add_library(timetool ${timetool_SRC}
I have a CMake project with the following directory structure:
CMakeLists.txt
A/CMakeLists.txt
B/CMakeLists.txt
A and B both describe shared libraries, and B depends upon A.
Calling cmake on the entire project gives no problems. Neither does building A, but building B tells me it misses symbols from A. This makes sense, and so I solved that by adding target_link_libraries(B A) to B/CMakeLists.txt.
However, when I call cmake now, I get errors about B/CMakeLists.txt not being able to find source files from A. Apparently, to solve this, I should add target_include_directories(A PUBLIC .) to A/CMakeLists.txt, but that does not work. What am I missing here?
For completion's sake, here's the dumbed-down CMake files:
cmake_minimum_required (VERSION 3.5.1)
project(main C CXX)
add_subdirectory(A)
add_subdirectory(B)
A/CMakeLists.txt
cmake_minimum_required (VERSION 3.5.1)
add_library(A SHARED "")
target_include_directories(A PUBLIC .)
target_sources(A PUBLIC ...)
B/CMakeLists.txt
cmake_minimum_required (VERSION 3.5.1)
add_library(B SHARED "")
target_link_libraries(B A)
target_sources(B PUBLIC ...)
The error I get is the following
CMake Error at B/CMakeLists.txt:3 (add_library):
Cannot find source file:
Access.hpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
I'm following this tutorial, explaining about target_link_libraries and target_include_directories.
Don't use target_sources(). Add source files to the add_library() command.
Or use target_sources() with PRIVATE.
I'm trying to build a fortran project that uses Fruit for unit tests. Essentially, I have a fortran module source file which contains some subroutines named test_something, and then I want to run a Rakefile which calls Fruit to generate a fortran program source file which will run all the tests. Fruit uses rake for this purpose, so not using rake isn't really an option for me.
I've included these commands to tell cmake to expect these files to be generated:
set_source_files_properties(fruit_driver_gen.f90 PROPERTIES GENERATED true)
set_source_files_properties(fruit_basket_gen.f90 PROPERTIES GENERATED true)
Then I have a custom command to run rake:
add_custom_command(
OUTPUT fruit_driver_gen.f90 fruit_basket_gen.f90
COMMAND rake gen
DEPENDS Rakefile)
The Rakefile is just a file that needs to be copied over to the folder where the custom command is executed, but whith DEPENDS it's registered as a target, so I try adding it as a custom target like this:
add_custom_target(Rakefile SOURCES "${PROJECT_SOURCE_DIR}/Rakefile}")
When I run cmake, I get the following error:
CMake Error at tests/CMakeLists.txt:20 (add_custom_target):
Cannot find source file:
~/Fruit_example/tests/Rakefile}
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Am I doing something completely wrong? Is there a more elegant way to achive what I want? I'm essentially trying to make cmake copy and run a script to generate some output, and I guess I can't be the only one trying to do that, even if using Fortran and Fruit is perhaps not that common.