How to link Folly in CLion on Mac OS - macos

I installed folly by attempting both ways of installation.
brew install folly
./build/bootstrap-osx-homebrew.sh
I have verified that it's installed correctly at the location /usr/local/Cellar/folly/2017.10.23.00.
Now I'm trying to use it in a HelloWorld project in CLion. Here is my CMakeLists.txt file.
cmake_minimum_required(VERSION 3.7)
project(HelloWorld)
message(STATUS "start running cmake....")
set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00)
find_package(Boost 1.66)
find_package(folly 2017.10.23.00)
set(CMAKE_CXX_STANDARD 14)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
if(folly_FOUND)
message(STATUS "folly_INCLUDE_DIRS: ${folly_INCLUDE_DIRS}")
message(STATUS "folly_LIBRARIES: ${folly_LIBRARIES}")
message(STATUS "folly_VERSION: ${folly_VERSION}")
include_directories(${folly_INCLUDE_DIRS})
endif()
set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})
if(Boost_FOUND)
target_link_libraries(HelloWorld ${Boost_LIBRARIES})
endif()
if(folly_FOUND)
target_link_libraries(HelloWorld ${folly_LIBRARIES})
endif()
The error I get is:
By not providing "Findfolly.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "folly", but
CMake did not find one.
Could not find a package configuration file provided by "folly" (requested
version 2017.10.23.00) with any of the following names:
follyConfig.cmake
folly-config.cmake
Add the installation prefix of "folly" to CMAKE_PREFIX_PATH or set
"folly_DIR" to a directory containing one of the above files. If "folly"
provides a separate development package or SDK, be sure it has been
installed.
I'm setting folly_DIR right at the top but it's still unable to find. What am I doing wrong?

The phrase
or set "*_DIR" to a directory containing one of the above files.
in the CMake error message should be treated as setting the cached variable to appropriate value.
Normally, the variable is set via command-line option -D when execute cmake. If you want to set the variable in CMakeLists.txt, add CACHE option to the set command:
set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00 CACHE PATH "")
Make sure that given path contain one of the config files noted in the error message.

Create you own FindFolly.cmake file as following (reference here):
# Usage of this module as follows:
#
# find_package(Folly)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# FOLLY_ROOT_DIR Set this variable to the root installation of
# folly if the module has problems finding
# the proper installation path.
#
# Variables defined by this module:
#
# FOLLY_FOUND System has folly libs/headers
# FOLLY_LIBRARIES The folly library/libraries
# FOLLY_INCLUDE_DIR The location of folly headers
find_path(FOLLY_ROOT_DIR
NAMES include/folly/folly-config.h
)
find_library(FOLLY_LIBRARIES
NAMES folly
HINTS ${FOLLY_ROOT_DIR}/lib
)
find_library(FOLLY_BENCHMARK_LIBRARIES
NAMES follybenchmark
HINTS ${FOLLY_ROOT_DIR}/lib
)
find_path(FOLLY_INCLUDE_DIR
NAMES folly/folly-config.h
HINTS ${FOLLY_ROOT_DIR}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Folly DEFAULT_MSG
FOLLY_LIBRARIES
FOLLY_INCLUDE_DIR
)
mark_as_advanced(
FOLLY_ROOT_DIR
FOLLY_LIBRARIES
FOLLY_BENCHMARK_LIBRARIES
FOLLY_INCLUDE_DIR
)
Then, you need to put this file into your CMake module path (more detailes here), that means:
Create a folder named "cmake/Modules/" under your project root
Put the FindFolly.cmake file in the created folder
Add the following line to your cmake file:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

Related

CMake Error: variable set to NOTFOUND even after defining it manually

I am new to cmake and attempting to build an existing repository that relies on GLEW. I have installed GLEW using Homebrew and am now trying to run cmake . The configuration step completes, but the generation step raises the following error:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY
I have checked/tried the following:
CMakeLists.txt contains a line find_package(GLEW REQUIRED) which does not fail. I even added the line FIND_LIBRARY(GLEW_LIBRARY NAMES libGLEW.dylib PATHS /opt/local/lib /usr/local/lib /usr/lib REQUIRED) to explicitly tell cmake where to look for the library and it finds the correct path.
There is a file FindGlew.cmake that was placed in /usr/local/Cellar/cmake/3.25.2/share/cmake/Modules (I assume during the homebrew install of GLEW). It contains a line unset(GLEW_LIBRARY). I'm a bit hesitant to mess with the file (it shouldn't be necessary, right?) but I tried commenting that line out and running cmake again, but it didn't have any effect.
CMakeCache.txt contains the variables GLEW_LIBRARY_DEBUG and GLEW_LIBRARY_RELEASE which were set to GLEW_LIBRARY_DEBUG-NOTFOUND etc. I edited them manually to the path of the libGLEW.dylib file and added an additional path which I called GLEW_LIBRARY, but to no avail.
CMakeCache.txt also contains a variable GLEW_DIR which is defined. There is a GLEW_LIBRARY_DIR which is also NOTFOUND.
I passed the variable as an explicit command using cmake . -DGLEW_LIBRARY=/usr/local/lib/libGLEW.dylib. I tried this both with and without first deleting the cache.
Statically define the library using the approach in this answer.
brew reinstall glew.
I do have OpenGL installed as wel, but built from source (not via Homebrew). Could It have something to do with them not being linked correctly? OpenGL is found properly by CMakeLists.txt, so cmake must have access to its path somehow.
Edit: this is (a MWE of) the CMakeLists.txt file:
cmake_minimum_required (VERSION 3.15)
project ("ProjectName" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(OpenGL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} )
# set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(GLEW REQUIRED)
# set(CMAKE_FIND_DEBUG_MODE FALSE)
include_directories(${GLEW_INCLUDE_DIRS})
file(GLOB sources CONFIGURE_DEPENDS src/*.cpp src/*.hpp *src/.h)
add_executable(${PROJECT_NAME} ${sources})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES})
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_BINARY_DIR}/Resources)
Edit: for completeness, here is the full output / error message:
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework
-- Found GLEW: /usr/local/lib/cmake/glew/glew-config.cmake
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY
linked by target "ProjectName" in directory /Users/user1/dev/project
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
EDIT2: According to FindGLEW you should use one of the imported targets - GLEW::GLEW i.e.
target_link_libraries(your_target GLEW::GLEW ... )
I would also kindly ask you to post the new errors that you are getting related to the MRE you posted. I will update my answer accordingly.
EDIT: Because you mentioned that some people can compile it and some people can't. Look at this line right here:
find_package(GLEW CONFIG QUIET)
if(GLEW_FOUND)
#...
This line tries to find the actual GLEWConfig.cmake file to configure this. Meaning that if you've installed the package OR they have in a way that you have this GLEWConfig.cmake file then you will get different results.
My recommendation is: Figure out exactly how they installed their GLEW (or if they compiled it) and recreate the exact same environment.
Here is the link to FindGLEW.cmake. On Lines 41-58 you can see the variables that you can use in your project. There is NO GLEW_LIBRARY.
If you look down in the file you'll see why:
if(GLEW_FOUND)
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_CONFIG)
get_target_property(GLEW_INCLUDE_DIRS GLEW::GLEW INTERFACE_INCLUDE_DIRECTORIES)
set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS})
get_target_property(_GLEW_DEFS GLEW::GLEW INTERFACE_COMPILE_DEFINITIONS)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_LOCATION_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_LOCATION_RELEASE)
else()
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_IMPLIB_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_IMPLIB_RELEASE)
endif()
get_target_property(_GLEW_LINK_INTERFACE GLEW::GLEW IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE) # same for debug and release
list(APPEND GLEW_LIBRARIES ${_GLEW_LINK_INTERFACE})
list(APPEND GLEW_LIBRARY ${_GLEW_LINK_INTERFACE})
select_library_configurations(GLEW)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
set(GLEW_STATIC_LIBRARIES ${GLEW_LIBRARIES})
else()
set(GLEW_SHARED_LIBRARIES ${GLEW_LIBRARIES})
endif()
unset(_GLEW_DEFS)
unset(_GLEW_LINK_INTERFACE)
unset(GLEW_LIBRARY) #<-- here the temporary variable is unset
unset(GLEW_LIBRARY_DEBUG)
unset(GLEW_LIBRARY_RELEASE)
return()
endif()
GLEW_LIBRARY is a temporary variable used to set other variables.
What instead you want to use is: GLEW_LIBRARIES

CMAKE_INSTALL_PREFIX not added to CMAKE_SYSTEM_PREFIX_PATH after setting CMAKE_SYSTEM_NAME to Generic

I am cross-compiling a project with CMake. find_library fails to find a library that is located in ${CMAKE_INSTALL_PREFIX}/lib, because CMAKE_INSTALL_PREFIX is not being appended to CMAKE_SYSTEM_PREFIX_PATH as it should according to the documentation.
The cause for this is that I set CMAKE_SYSTEM_NAME to Generic in my toolchain file. I stripped down the toolchain file to this single command. Why does it affect the behaviour of CMAKE_INSTALL_PREFIX?
If I set CMAKE_SYSTEM_NAME to Linux or Windows, CMAKE_SYSTEM_PREFIX_PATH has some preset and also CMAKE_INSTALL_PREFIX is appended as expected.
I think the documentation is wrong here. Adding CMAKE_INSTALL_PREFIX to CMAKE_SYSTEM_PREFIX_PATH is not done automatically. This is done inside CMake modules that are specific to the Windows and Linux platforms (e.g. c:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake on my computer).
To mimic the same behaviour for non-Windows and non-Linux platforms, you can do the following. In the toolchain file, define a unique system name and also add the current directory to CMAKE_MODULE_PATH so that Cmake will look for modules here:
set(CMAKE_SYSTEM_NAME "MySystem")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
Then create a platform file called <CMAKE_SYSTEM_NAME>.cmake in a sub-folder called Platform (e.g. Platform\MySystem.cmake). Inside this file you can append CMAKE_INSTALL_PREFIX to CMAKE_SYSTEM_PREFIX_PATH:
# Copied from c:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake
if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
# Project install destination.
"${CMAKE_INSTALL_PREFIX}"
)
if(CMAKE_STAGING_PREFIX)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
# User-supplied staging prefix.
"${CMAKE_STAGING_PREFIX}"
)
endif()
endif()

CMAKE: how to include and link alternative libraries?

My project need four libraries including MPI, BOOST, VTK and SQLITE3. Since BOOST and SQLITE3 are too old, I installed new version of the two libraries and the old version are not uninstalled:
BOOST # alternative BOOST
|___include
|___lib
|
SQLITE # alternative SQLITE
|___bin
|___include
|___lib
|___share
|
Mypoject
|___src
| |___CMakeLists
| |___.cpp and .h file
|
|___CMakeLists
And I used FindSQLite3.cmake to find the alternative SQLite3:
# Look for the header file.
FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h /export/home/hh/hh/sqlite/include)
# Look for the library.
FIND_LIBRARY(SQLITE3_LIBRARY sqlite3 /export/home/hh/hh/sqlite/lib)
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
# Copy the results to the output variables.
IF(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
ELSE(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES)
SET(SQLITE3_INCLUDE_DIRS)
ENDIF(SQLITE3_FOUND)
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
I am trying to link alternative libraries by following lines:
# CMake version
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
SET(VERSION 0.1)
SET(SOVERSION 1)
# searching ENV{PATH} to find mpicc and
# store the path of mpicc to MPI_INTEL_C
FIND_PATH(MPI_INTEL_C mpicc $ENV{PATH})
# searching ENV{PATH} to find mpicxx and
# store the path of mpicc to MPI_INTEL_CXX
FIND_PATH(MPI_INTEL_CXX mpicxx $ENV{PATH})
IF(MPI_INTEL_C AND MPI_INTEL_CXX)
MESSAGE(STATUS "Intel MPI compiler is used.")
# set C++ complier as mpicxx, and set C complier as mpicc
SET(CMAKE_CXX_COMPILER mpicxx)
SET(CMAKE_C_COMPILER mpicc)
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)
find_package(VTK REQUIRED NO_MODULE)
IF(VTK_FOUND)
MESSAGE(STATUS "VTK IS USED")
include(${VTK_USE_FILE})
ELSE()
MESSAGE("VTK IS NOT FOUND")
ENDIF(VTK_FOUND)
list(APPEND CMAKE_MODULE_PATH "/export/home/hh/hh/iRoot-make/cmake")
FIND_PACKAGE(SQLite3 REQUIRED)
MESSAGE(STATUS "${SQLITE3_INCLUDE_DIRS}")
MESSAGE(STATUS "${SQLITE3_LIBRARY}")
# try to link boost--error
INCLUDE_DIRECTORIES(/export/home/hh/hh/boost/include)
LINK_DIRECTORIES(/export/home/hh/hh/boost/lib)
find_package(MPI REQUIRED)
IF(MPI_FOUND)
MESSAGE(STATUS "MPI IS USED")
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
ELSE()
MESSAGE("MPI IS NOT FOUND")
ENDIF(MPI_FOUND)
aux_source_directory(. DIR_SRCS)
ADD_EXECUTABLE(test ${DIR_SRCS})
#TARGET_LINK_LIBRARIES(iRoot)
# set location of binary generated by the program,
# here PROJECT_BINARY_DIR = DIR OF build
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# set location of lib generated by the program
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
install(TARGETS test DESTINATION bin)
CMake could not find the alternative SQLite3, and could find the old version:
-- /usr/include
-- /usr/lib64/libsqlite3.so
but the new version is located at:
/export/home/hh/hh/sqlite/include
/export/home/hh/hh/sqlite/lib/libsqlite3.so
I am very new to CMAKE, please help me, thank you in advance!
I will explain this using boost as an example. This is how I have it done in my setup.
Let's assume the newer boost version is installed in:
/export/home/hh/hh/Boost/boost-1_60/boost/include/
/export/home/hh/hh/Boost/lib
Now in CMakeLists.txt add these paths to CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH:
LIST (APPEND CMAKE_INCLUDE_PATH "/export/home/hh/hh/Boost/boost-1_60")
LIST (APPEND CMAKE_LIBRARY_PATH "/export/home/hh/hh/Boost/lib)
Then call FindPackage mentioning the minimum required version and optionally the required library components which are built into .so:
FIND_PACKAGE (Boost 1.60 COMPONENTS "program_options" "log" "system" "filesystem" "thread" "python" REQUIRED)
This should work similarly for other libraries too.
Update:
Add to CMakeLists.txt paths to your custom cmake modules, for example the path where FindSQLite3.cmake is located:
LIST (APPEND CMAKE_MODULE_PATH "${MAINFOLDER}/tools/share/cmake")
Then call: FIND_PACKAGE(SQLite3 REQUIRED)
Also remove: /export/home/hh/hh/sqlite/include and /export/home/hh/hh/sqlite/lib from FindSQLite3.cmake but have them added in a similar to boost way.
Instead of hardcoding these settings in the CMakeLists.txt you should change appropriate value in the cache (builddir/CMakeCache.txt). You can do this
manually
with cmake -D VARNAME=value .
with cmake GUI app

How to use CMake RPath for boost.Python

I'm writing a Python extension module in C++ using Boost.Python. However, I
would like to use a newer version of the Boost library than the system
installation offers. This newer version of boost is contained in
BOOST_ROOT=$HOME/opt/boost/1.55.0.
Following this guide on how
to use RPath in CMake I came up with the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project("test")
set(PROJECT_DESC "Test Boost.Python")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_definitions(-std=c++11 -Wall -Wextra -pedantic)
find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
message(STATUS "Using Boost installation in:")
message(STATUS " INCLUDE: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIB: ${Boost_LIBRARIES}")
include_directories(
${PROJECT_SOURCE_DIR}
${PYTHON_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
macro(add_python_module _name _srccpp)
PYTHON_ADD_MODULE(${_name} ${_srccpp})
target_link_libraries(${_name} ${Boost_LIBRARIES})
endmacro()
add_python_module(ownership ownership.cpp)
Then I run the following commands to build the module
mkdir build; cd build
cmake -DCMAKE_INSTALL_PATH="$BOOST_ROOT/lib" ..
make
The status message after running cmake points to the right boost
installation. (The CMake boost module picks up the environment variable
$BOOST_ROOT) I.e. the CMake variable Boost_LIBARIES points to
$BOOST_ROOT/lib/libboost_python.so.
But, if I check which libraries would actually be used, the system libraries
are listed:
$ ldd ownership.so
# ...
libboost_python.so.1.53.0 => /usr/lib64/libboost_python.so.1.53.0 (0x00007f09abfc1000)
# ...
This is version 1.53, even though the status message above explicitely pointed
to 1.55.
What am I doing wrong? How can I get ldd to pick the library in
$BOOST_ROOT/lib/libboost_python.so.1.55.0?
First of all as I already mentioned in commens you don't need to use CMake RPATH-manipulations
options. Example: http://pastebin.com/UDyYbQ1d, output: standard and custom
Do you know of a way of convincing CMake otherwise even if LIBRARY_PATH is set
This issue is not related to CMake, it's compiler responsibility. Read this discussion.
Solution
You can clear LIBRARY_PATH if you set BOOST_ROOT variable explicitly. And you can check
environment variable in CMakeLists.txt to avoid this problem in future:
string(COMPARE NOTEQUAL "$ENV{LIBRARY_PATH}" "" library_path_warning)
if(library_path_warning)
message(
WARNING
"LIBRARY_PATH environment variable is not empty ($ENV{LIBRARY_PATH}) "
"This may cause dynamic linking errors!"
)
endif()

Add libraries Qt and LuaJIT / Lua51 with CMake

I am trying to use CMake with Qt and LuaJIT that will run on Visual Studio 2012. I managed somehow to run Qt, but i don't know how to add LuaJIT library to project. I am using source of LuaJIT cloned from http://luajit.org/git/luajit-2.0.git, which is build by running .bat file.
I dont care that LuaJIT will be build by CMake, i just need to link library and add headers to project.
I removed lib folder from my project... Is not worth troubles to have dependancies coupled with project whitout cmake file :D
My project hierarchy is:
+lib
-luajit-2.0
+src
-my sources
+ui
-ui files
-CMakeLists.txt
And CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 2.8.12)
set(PROJECT "Grapedit")
project(${PROJECT})
# Qt Stuff
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
set(SOURCE_FILES
src/main.cpp
src/mainwindow.h
src/mainwindow.cpp
)
set(UI_FILES
ui/mainwindow.ui
)
source_group("UI Files" FILES ${UI_FILES})
qt5_wrap_ui(UI_HEADERS ${UI_FILES})
source_group("Generated UI Headers" FILES ${UI_HEADERS})
add_executable(${PROJECT} ${SOURCE_FILES} ${UI_HEADERS} ${UI_FILES})
qt5_use_modules(${PROJECT} Widgets)
My solution
So it is finally working and I made couple of newbie mistakes... :)
I will write them down for others:
didn't know what is find module... This will search environment and set up locations of libraries or flag that it didn't find them. Since LuaJIT is compatible with Lua51 you can use find_package(Lua51).
Your libraries must be some way visible to CMake. On Windows simplest way is to add them to PATH variable. Or you can add path of your libraries to CMake variable CMAKE_PREFIX_PATH. Open find module, for example FindLua51.cmake and you will see how must be your library organized. On windows I've must installed LuaJIT manualy - created LuaJIT folder and I've put *.h files to include subfolder, *.dll to bin subfolder and *.lib to lib subfolder. Then add bin folder to PATH and set LUA_DIR to LuaJIT folder.
use include_directories on include folder
then you must link libraries target_link_libraries, but after add_executable!
My CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.12)
# Declare project variables...
set (PROJECT "Grapedit")
set (
SOURCE_FILES
src/main.cpp
src/mainwindow.h
src/mainwindow.cpp
)
set(UI_FILES
ui/mainwindow.ui
)
# Set project name
project(${PROJECT})
# Include Lua directories
include_directories(${LUA_INCLUDE_DIR})
# Qt Stuff
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
# Find packages...
# Will find also LuaJIT, but must be named same as Lua51 and installed into directories
find_package(Lua51)
# Find Qt modules, every module separately
find_package(Qt5Widgets REQUIRED)
# Create nice groups in IDEs
source_group("UI Files" FILES ${UI_FILES})
source_group("Generated UI Headers" FILES ${UI_HEADERS})
# Use Qt UI files
qt5_wrap_ui(UI_HEADERS ${UI_FILES})
# Create executable
add_executable (
${PROJECT}
${SOURCE_FILES}
${UI_HEADERS}
${UI_FILES}
)
# Link libraries...
# Must be after executable is created!
# Link Qt modules
qt5_use_modules (
${PROJECT}
Widgets
)
# Link Lua
target_link_libraries(${PROJECT} ${LUA_LIBRARIES})
# Will not show new windows prompt when running program
if (MSVC)
set_target_properties(${PROJECT} PROPERTIES
WIN32_EXECUTABLE YES
LINK_FLAGS "/ENTRY:mainCRTStartup"
)
endif ()
You are missing the actual linkage which you can amend with the following statement:
target_link_libraries(${PROJECT} luajit-5.1)
For sure, it would be even better if this lua jit could have a cmake find module, or config/version file depending on its exact build system.
You could grab the find module from here:
https://github.com/brimworks/lua-zlib/blob/master/cmake/Modules/FindLuaJIT.cmake
Then you could link against it as follows:
target_link_libraries(${PROJECT} ${LUA_LIBRARIES})
You can see that it would become more dynamic this way rather than hard-coding the exact name. The details for figuring out that would be left with the find module.
Note that you would probably need to use the corresponding variables for the header inclusion then as follows:
include_directories(${LUA_INCLUDE_DIR})
This will take care of automatically finding the include directory, respectively, without you hard-coding it.
You would also need to add the following line into your CMakeLists.txt:
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
and you need to place the downloaded find module into a "cmake" subfolder.
Please refer to the following page for further details about this topic in general:
CMake:How To Find Libraries

Resources