floooh / fips

High-level build system for distributed, multi-platform C/C++ projects.
MIT License
468 stars 82 forks source link

How to use 'exec_program' in FIPS??? #256

Closed Ron2014 closed 4 years ago

Ron2014 commented 4 years ago

When I want to build MSVC project of LuaJIT, I found the guide in msvcbuild.bat is

%LJCOMPILE% host\minilua.c
@if errorlevel 1 goto :BAD
%LJLINK% /out:minilua.exe minilua.obj
@if errorlevel 1 goto :BAD
if exist minilua.exe.manifest^
  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe

@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64
@set LJARCH=x64
@minilua
@if errorlevel 8 goto :X64
@set DASC=vm_x86.dasc
@set DASMFLAGS=-D WIN -D JIT -D FFI
@set LJARCH=x86
@set LJCOMPILE=%LJCOMPILE% /arch:SSE2
:X64
@if "%1" neq "nogc64" goto :GC64
@shift
@set DASC=vm_x86.dasc
@set LJCOMPILE=%LJCOMPILE% /DLUAJIT_DISABLE_GC64
:GC64
minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
@if errorlevel 1 goto :BAD

which means fips_begin_app(minilua cmdline) first and then execute it

minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%

In cmake, exec_program can do this, but I get this problem in FIPS

CMake Warning (dev) at LuaJIT/src/CMakeLists.txt:19:
  Syntax Warning in cmake code at column 19

  Argument not separated from preceding token by whitespace.
This warning is for project developers.  Use -Wno-dev to suppress it.

Process failed because: The system cannot find the file specified

build & execute, maybe FIPS doesn't support this?

floooh commented 4 years ago

Hmm, not sure what the cmake warning is about, this shouldn't be fips-specific though.

I'm not sure if exec_command is the right way to do this though, AFAIK this runs an executable while cmake processes the CMakeLists.txt files, not during the build (see here: https://cmake.org/cmake/help/v3.17/command/exec_program.html).

Since the the executable is only created during a build there would be a chicken-egg-problem

I would probably use cmake's add_custom_command or add_custom_target in this situation:

https://cmake.org/cmake/help/latest/command/add_custom_command.html

https://cmake.org/cmake/help/latest/command/add_custom_target.html

These allow to run executables during the build process, the only thing you'd need to make sure is that the dependencies are set up properly, so that those custom commands are only running after the executable is built. These are all cmake features though, and should work the same with or without fips.